BBS: Inland Empire Archive Date: 12-19-92 (18:11) Number: 357 From: WES GARLAND Refer#: NONE To: SEAN PAGE Recvd: NO Subj: Mathematics Code Conf: (2) Quik_Bas
Hi Sean! SP> What I need are some routines of the following descriptions: SP> SP> AngleToOpponent: Using current X/Y[/Z] coordinates, calculate the SP> angle from the centerline of the player's ship to SP> the opponent ship. If Z, calculate both angles. SP> SP> RangeToOpponent: Using the descriptions given above, calulate the SP> range between ships. SP> In Ontario, is standard Grade 13 algebra/geometry. You should be able to find a text on this (check first-year or grade 12 texts I guess), its not very hard;just simple vector math. DISCLAIMER: I'm not very good at math... The best way to do is to set it up on a grid. This applies to 2D and 3D.. Once you've got it on a grid, you've got some nice things to work with. The co-ordinates of the grid are the distance from the orgin, and there are a lot of standard relations you can use. I'll discuss range first... The range to the opponent is given by Range=sqr((x2- x1)^2+(y2-y1)^2) for 2D,Range=sqr((x2-x1)^2+(y2-y1)^2+(z2- z1)^2) in three dimensions, Where x and y are the coordinates of the objects on the graph. This is just the Phythagorem Theorem revisited, if you're wondering where it came from. Oh yeah,remember, in 3D, the Z axis is "up", the Y axis is is "right", and the X axis is "out". Angle to Opponent is a little complicated. Let me thing here... (hmm...) First, you have to do is translate the grid so that the player is at the origin. All the math is much easier if you do this... So you can keep track of everything in "real- space", but the when you have to do a calculation,just move space so that the player is at the origin. You can do this by subtracting the coordinates of the Opponent from the coordinates of the player, ie (x,y,z) = (x2-x1, y2-y1, z2-z1). Now that you know this (x,y,z), (for 2D, just ignore the z part of this). Now, lets call the angle between the vector (line joining opponent to origin) and the x-axis alpha, the angle between the vector and the y axis beta, and the angle between the z axis and the vector gamma. Remember, in 2D alpha + beta = 90, but there is *NO* relation like this in 3D! Now. Lets see here.. Hmm.. Hm... (been away from this for a while :-) cos alpha = x/Range \ cos beta = y/Range | I think! cos gamma = z/Range / note: In texts, Range to the opponent is the magnitude of the vector. Remember, in this case, you don't need to do the subtraction for the range calculation, because the coordinates of the player are (0,0,0) because you've translated space so that the player is at the origin. Anyhow, theres one thing I haven't told you here and to tell you the truth I can't figure out the answer.. How do you find theta from cos theta = whatever.. Well, its easy with a calculator but I don't know how to do it in QB. Anybody help here? I may be able to figure it out when I find my QB manual :-) If you still need help, let me know. Wes --- Maximus 2.01wb * Origin: Terminal Velocity Kingston * CANADA * (613)542- 4613/6594 * (1:249/128)
Books at Amazon:
Back to BASIC: The History, Corruption, and Future of the Language
Hackers: Heroes of the Computer Revolution (including Tiny BASIC)
Go to: The Story of the Math Majors, Bridge Players, Engineers, Chess Wizards, Scientists and Iconoclasts who were the Hero Programmers of the Software Revolution
The Advent of the Algorithm: The Idea that Rules the World
Moths in the Machine: The Power and Perils of Programming
Mastering Visual Basic .NET