finding the angle between two objects

For questions about using Classic.

» Mon Sep 08, 2008 10:47 pm

i didnt learn sin cos tan yet in school so i need the help of some of you who did. id like to find the angle between 2 objects, the results being the angle relative to one object going to the other, so lets say an explosion goes off at point a, and whatever is being affected is at point b, id like to know at what angle would point A be facing to be looking right at point b. so i can calculate which way to throw point.b

basically i want the function for that (example: A^2+B^2=C^2 for the distance formula)

i know thats what sin,cos, and wtv is for but i havnt got there yet im only 13. so plz help
B
47
S
5
G
6
Posts: 1,940
Reputation: 7,273

» Mon Sep 08, 2008 11:15 pm

angle(ax,ay,bx,by)
B
2
S
2
G
5
Posts: 236
Reputation: 2,122

» Mon Sep 08, 2008 11:19 pm

I'll just put it here
viewtopic.php?f=3&t=1434
B
4
S
2
G
4
Posts: 719
Reputation: 2,938

» Mon Sep 08, 2008 11:19 pm

lol thats easy , didnt know bout that

id still like to know the actual code behind that though, just for learning purposes
B
47
S
5
G
6
Posts: 1,940
Reputation: 7,273

» Mon Sep 08, 2008 11:21 pm

[quote="Doppel":3v2p3f1b]I'll just put it here
viewtopic.php?f=3&t=1434[/quote:3v2p3f1b]

i mean in actual construct bearings, not protracter style measurements, and isnt what he wants different entirely, i think he meant 3 point to describe he dint want bearings. altho i dont knwo why cheez needed those anyways,
B
47
S
5
G
6
Posts: 1,940
Reputation: 7,273

» Mon Sep 08, 2008 11:35 pm

its quite complicated, that angle function is a lifesaver.

If you haven't learnt trig yet its probably no use proving a formula to you.

the actual formula is arctan((y2-y1)/(x2-x1)) but it's made more complicated by getting a sign error in different quadrants, so this formula makes it really nice.

the basic idea is:

(any excuse to do some maths)
B
2
S
2
G
5
Posts: 236
Reputation: 2,122

» Tue Sep 09, 2008 1:27 am

well, i get it, just u know i dont know the across under ect ect, all i really wanted to know is the formula "arctan((y2-y1)/(x2-x1))" as even tho i dont get what it does completely i can still use it for other things where i might need it, wikipedia makes all math look like freaken nuclear science

and god, i really hate different quadrants, while i was programming a swinging pendulum for mmf2 using pythos to draw a cricle path based on radius i had to calculate for weird changes which happen when quadrants are changed its hard to explain tho
B
47
S
5
G
6
Posts: 1,940
Reputation: 7,273

» Tue Sep 09, 2008 5:07 pm

Yeah, atan will only give results over a range of angles (I forget, either just 0-90 or 0-180) which is kind of inconvenient if you want to measure an angle which is actually 270 degrees. Still, the C++ runtime library has a function called 'atan2' which works out the quadrants for you, which is what Construct uses. If you ever need atan2 for something else, I think angle(x, y, 0, 0) is equivalent to atan2(y, x). But the x,y and 0,0 might be the other way round. Can't remember.
Scirra Founder
B
355
S
208
G
71
Posts: 22,831
Reputation: 176,688

» Wed May 18, 2016 6:03 am

Ashley wrote:Yeah, atan will only give results over a range of angles (I forget, either just 0-90 or 0-180) which is kind of inconvenient if you want to measure an angle which is actually 270 degrees. Still, the C++ runtime library has a function called 'atan2' which works out the quadrants for you, which is what Construct uses. If you ever need atan2 for something else, I think angle(x, y, 0, 0) is equivalent to atan2(y, x). But the x,y and 0,0 might be the other way round. Can't remember.

Other way around: angle(0, 0, x, y)

Old post I know, but was searching for atan2 and found this. Thanks!
B
27
S
16
G
11
Posts: 429
Reputation: 8,880

» Wed May 18, 2016 7:02 am

Old post I know, but was searching for atan2 and found this. Thanks!

.... and also for the - now retired - Construct Classic. Bit of a pointless 8 year old thread bump, I'd say.
If your vision so exceeds your ability, then look to something closer.
Moderator
B
117
S
28
G
66
Posts: 4,776
Reputation: 47,059

Next

Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 0 guests