BBS: Inland Empire Archive Date: 01-03-93 (18:45) Number: 245 From: WES GARLAND Refer#: NONE To: JOHN GALLAS Recvd: NO Subj: calculations.. Conf: (2) Quik_Bas
======CONTINUTED FROM PREVIOUS MESSAGE====== Let d be the angle in degrees, r the angle in radians. r = PI*d/180 And of course, that means at the top of your program you should put CONST PI = 3.1415926536 Since you say you're using 0 degrees as straight up, theta would be 90 minus your angle, right? Now, to make that calculation you wanted... InitX = 1550 InitY = 1438 Angle = 348 Dist = 3 Rads = PI*Angle/180 Y = sin(Rads) * Dist X = cos(Rads) * Dist NewX = InitX + X NewY = InitY + Y make sense to you? JG> Also, lets say I'm at 500, JG> 500 and my friends spaceship is at 600,650. How do I JG> calculate what angle (in degrees, 0 to 359) I should JG> face in order to go visit him? Well, first you need to know the distance between the two of them. By the pythagorean theorem, D^2 = (X2-X1)^2 - (Y2- Y1)^2 Now, lets assume you're at the origin (makes calculations easier). The angle between the X axis and the origin is easy to calculate: Tan @ = Y/X where @ is the angle in rads (remember how QB does trig calcs), Y is the the Y-coordinate of your destination, and X is the X-coordinate of your destination. So... InitX = 500 InitY = 500 DestX = 600 DestY = 650 Y = DestY - InitY X = DestX - InitX Rads = Arctan (Y/X) Angle = 270+(180*Rads/PI):If Angle >= 360 then Angle=Angle-360 Any questions? 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