09-08-2003, 12:14 AM
is there a function in c/c++ to get the angle between 2 points? if so, what is it? if not, how can i write one? i assume it will use trig but my maths is a bit rusty.
Help?? :???:
Help?? :???:
angle between 2 points (c++)
|
09-08-2003, 12:14 AM
is there a function in c/c++ to get the angle between 2 points? if so, what is it? if not, how can i write one? i assume it will use trig but my maths is a bit rusty.
Help?? :???:
09-08-2003, 12:26 AM
two points is a line... you'd need a third to get an actual angle.
Or are you talking about something like this? Code: . where the line is the base and the two dots are the intersecting line? You can just take the distance formula of the two dots, and a random dot on the base. Say, the dot near the bottom is A, the dot on the base is B, and the one in the air is C. Code: AC = SQRT((Ax - Cx)^2 + (Ay - Cy)^2) I think...
am an asshole. Get used to it.
09-08-2003, 12:27 AM
I can't understand your question, but the atan y atan2 should be the function you are looking for.
Look at the manual for further examples about this.
09-08-2003, 01:44 AM
as i said, my maths is rusty. i think it would go something like this
Code: x1=10;y1=10; EDIT: Im looking for the equivelent to RelLibs RelAngle. its for calculating x and y velocitys and trajectories in my game.
09-08-2003, 01:47 AM
I'm pretty sure my way would work. I don't know what you're trying to do though.
am an asshole. Get used to it.
09-08-2003, 11:43 AM
citpes wrote:
Quote:i know tan theta = opposite/ajacentYour in the right ballpark Code: theta = arctan (ydif/xdif) (the adjacent is xdif) Ninkazu, try your method with some points. If I understand what you are trying to do, I don't think it will work. For example if A =(0,0), then if you try it with B = (Bx,By) and with B = (By,Bx) you will get the same answer both times.
hrist Jesus came into the world to save sinners, of whom I am first.(I Timothy 1:15)
For God so loved the world, that He gave His only begotten Son, that whoever believes in Him should not perish, but have eternal life.(John 3:16)
09-08-2003, 11:57 AM
Allegro: Atan2 or was it fatan?
If all else fails... translate this to c. ;*) Code: FUNCTION Rel.Angle% (X1, Y1, X2, Y2) If you want the ASM version, just ask .;*) BTW, if you're doing homing missiles, ATAN2 and FATAN is not a good choice. Use a modified dot product.
09-08-2003, 07:32 PM
That's just atan2 written out using atan... it's built into the standard C/C++ library...
09-08-2003, 10:19 PM
thanx, rel. ill try it later. the asm source would be useless to me, i hardly understand the qbasic source :lol:
whats all this ruckess bout some atan2 thing. its all gone straight over my head!
09-09-2003, 12:36 AM
This is what you want. Print it out and sleep with it under your pillow, treat it like your best friend, trust me you'll thank me after you read it:
This sine and cosine tut for game coders: http://www.pixelate.co.za/issues/5/5/art...sincos.htm A description of the article Quote:This article will explain sine, cosine, vectors, atan2, and some useful special effects such as how to make homing missiles and how bitmap rotation works'Nuf said.
b]Hard Rock[/b]
[The Stars Dev Company] [Metal Qb flopped] [The Terror] Stop Double Posts! Whats better? HTML or Variables? |
« Next Oldest | Next Newest »
|