How can I simulate a 3D space pursuit between two spaceships with laser weapons?

  • Thread starter Thread starter jst
  • Start date Start date
  • Tags Tags
    3d Space
Click For Summary
SUMMARY

The discussion centers on simulating a 3D space pursuit between two spaceships equipped with laser weapons, focusing on the mathematical and programming challenges involved. Participants emphasized the importance of using a Cartesian coordinate system to determine the positions and movements of the ships, with specific equations for distance and angle calculations. Key insights included the need for transformations to align the ships' coordinates and the implementation of basic AI for the pursuing ship. The final implementation involved calculating the distance and azimuth angle to determine if a shot could be taken.

PREREQUISITES
  • Understanding of 3D Cartesian coordinate systems
  • Familiarity with trigonometric functions and their applications in programming
  • Basic knowledge of vector mathematics for direction and movement
  • Experience with programming languages suitable for simulations, such as Python or Java
NEXT STEPS
  • Research "3D transformations in computer graphics" to understand coordinate alignment
  • Learn about "vector mathematics" for calculating distances and angles in 3D space
  • Explore "AI techniques for simple game mechanics" to enhance spaceship behavior
  • Study "simulation programming" principles to improve the overall design of the project
USEFUL FOR

Game developers, computer graphics programmers, and students working on simulation projects involving physics and AI mechanics.

jst
Messages
28
Reaction score
0
"3D Space Pursuit Problem"

Homework Statement



This is actually a programming assignment, more than a physics problem. However the issue I'm having is more with the math/physics than with the programming. Anyway here it goes:

Write a simulation program and test it for a three dimensional space pursuit of two spaceships each equipped with a laser beam weapon that can destroy its target if it is within a cylindrical angles of ALPHA degrees and a distance of BETA. Do not assume a pure pursuit, but make any necessary assumptions for smart spaceship commanders. Some sort of graphic output is required in addition to a summary report discussing your results.


Homework Equations




Included with the problem was these "hints":

http://glomawr.com/hint.jpg


The Attempt at a Solution



After looking at the book that my professor referenced in his "hint", 2D is no problem, but I'm a little confused on 3D. I found the book on Google Book Search and copied the 3 pages if anyone wants to take a look: http://glomawr.com/problem.jpg

So looking online, I found:

http://glomawr.com/eq1.jpg

Do I just combine the above info with the "hint" where I replace the SIN THETA with the value of SIN from the "hint"?

Also, I assume that the distance equation would be similar, but with an additional z coordinates.

Just more of an opinion thing...by: "Do not assume a pure pursuit, but make any necessary assumptions for smart spaceship commanders" I think he means not do it exactly like the book and give the second plane some weak AI where it moves a bit. What would you assume? (professor isn't really responding to emails :confused::smile:)


Thanks a lot. Any opinions, ideas, and info are appreciated.

-Jason
 
Last edited by a moderator:
Physics news on Phys.org


Hi jst, Well this actually could become a rather very complex mathematical problem, depending on how far you want to take, so here's my take on it.

First ill assume that you have you have the positions of the cat and mouse ships (ill call ship1 and ship2 respectively) in some global Cartesian coordinate system (i.e x,y,z coordinates). You will also require the direction vector that ship1 is pointing in and also how much roll it has, that is the angle about the direction vector that ship1 is rotated. I would actually say the best way to implement "roll" is to have a direction vector located at the same position as that of the position of ship1 at right angles (orthogonal) to the direction vector, such that it points down one of the wings of ship1(ill call this the wind vector). Now the reason why you'll need roll will become apparent in a second.

What you will now need to do is transform the ships coordinates so that ship2 has position relative to ship1, and that ship1's direction vector is pointing down the positive x-axis, and that the wing vector is pointing down the y-axis (depending on which side you put the wind vector will depend which direction along the y-axis it points) such that the ship1 is horizontally aligned. After you have done this transformation you will have something similar to the diagram below, I will assume that you can work out how to do that transformation yourself, there is a lot online describing transformations, but obviously if you can't figure out what to do there give it you best shot then come back and well go from where you get stuck.

http://weald10k.fileave.com/PF003_1.png

Now given that Ship one is at the origin of our coordinate system and it is align horizontally wee can now see if ship2 is withing range to be shot :D.

So this is where those second equations you have come into play. So we can first decide if the ship is within the maximum shooting distance from us, so we can do that by this equation

d = \sqrt{x^2 + y^2 + z^2}

where x,y,z represent the coordinates of ship2 in our transformed coordinate space.
If d is less than the maximum range on the laser then we can proceed to the next stage.
We now need to decided if ship 2 is within the angle of shooting for ship1. In the diagram you can see angle a, now this angle is the angle in which ship1 can shoot and is symetrical about the x axis, so it stretches around the z axis to +(a/2) and -(a/2) each way, and hopefully you can make out where they reach by the vertical gray bars on the diagram.

So now we need to calculate the horizontal angle between ship2 and ship1 (call the azimuth angle) which we do with one of you second set of equations:

\theta = tan^{-1}\left(\frac{y}{x}\right)

from that we can get the azimuth angle of ship2 from ship1, if it satisfies the interval

-\frac{a}{2} < \theta < \frac{a}{2}

then ship1 will be able to shoot ship2.
I hope that helps, it seems like quite a hard programing problem (but I don't know what level of eduction that's at so sorry for any assumption made there :D) good luck with you program
 


Hey, thanks a lot for the info. However, the assignment was due (and turned in yesterday) :eek: Anyway, I think I did okay, but I was fortunate enough to get a couple of responses from my Professor (wasn't expecting that :wink: )

When I asked him a very close to the way I posted the question here, he stated: "I would stick with Cartesian and measure distances as I hinted."

So I wrote back, "As far as the coordinates goes, https://www.physicsforums.com/newreply.php?do=postreply&t=290376#1 the distance itself is not a problem; it's the same equation, but with z added. So would the only difference in the SIN and COS equations from the "hint" be that the distance in the denominator?"

His response: "Yes. You are correct."

So, that's what I did...much more simple than what I was making.

So if there wasn't a "hit", I did:

Catx = Catx + speed*(Mousex-Catx)/getDistance();
Caty = Caty + speed*(Mousey-Caty)/getDistance();
if (Math.Abs(Catz - Mousez) >= blowupDistance / 3)
{
Catz = Catz + MoveUp(1, System.Convert.ToInt32(speed));
}

I moved the mouse based on how close the the cat was, but we had a lot a freedom to do whatever for this.

Was I correct? Based on my Professor's emails, I would say I've very close.

Thanks again,

Jason
 
Last edited by a moderator:


Hi Jason, ah sorry about that, a day late :D. Sure that I think looks fine, I don't quite understand where the "/3" comes from on line 3, but you know that only a small part of you program.
I think the way you did is far more sensible, after all it meant to be a programing problem not a math problem. And I think to be honest there won't be a "correct answer", its a simulation and how the simulation pans out will depend on the programmer :D, I am sure you'll do great with the program.
 


Galadirith said:
Hi Jason, ah sorry about that, a day late :D. Sure that I think looks fine, I don't quite understand where the "/3" comes from on line 3, ...

No worries...my division by 3 is bullsh*t :eek: basically...I moved the Cat's z-position if the difference in z coordinates of the cat and mouse was greater than equal to a third of the distance in which the bomb can hit. Just something to move the z to a better position...hopefully.

Nothing groundbreaking going on here, but it was fun to run...because some of the movements are based on pseudo-random movements, so sometimes the cat wins, some time the mouse gets away.

Overall fun, except for getting started ;)
 

Similar threads

  • · Replies 3 ·
Replies
3
Views
3K
Replies
6
Views
4K
  • · Replies 27 ·
Replies
27
Views
4K
Replies
15
Views
41K