Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / Angle between 2 points?

Author
Message
KISTech
18
Years of Service
User Offline
Joined: 8th Feb 2008
Location: Aloha, Oregon
Posted: 3rd May 2011 22:23
I've done some googling, done some searching on the forum here, found several references, but haven't found anything that quite works for what I'm trying to do.

I have 2 objects, as they move around I want to find the angle of the difference in altitude between them.

I'm using the resulting angle to determine whether or not the hill in front of the player is to steep to allow them to walk up it.

I've tried this,



and a few other variants, but haven't come up with anything that gives a consistently correct answer.

Diggsey
20
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 3rd May 2011 22:32 Edited at: 3rd May 2011 22:35


Imagine a triangle with one side in the horizontal (X/Z) plane going from one object to directly above or below the other. The next side goes to the object, so either up or down to it (the difference in height). The hypotenuse then joins the two objects.

You want to find the angle between the hypotenuse and the first side given the lengths of the first and second side.

The length of the first side is sqrt(ax#*ax#+az#*az#) (pythagoras for X and Z distance)
The second side is ay# (difference in height)

The angle is then the arc-tangent of those two divided, or for simplicity atanfull().

[b]
NickH
18
Years of Service
User Offline
Joined: 19th May 2008
Location: Nova Prospekt, North Yorks, UK
Posted: 3rd May 2011 22:41 Edited at: 3rd May 2011 22:46
Hmmm I've got a similar question. Hopefully this thread can kill 2 birds with 1 stone...sort of.

I have 2 sets of co-ordinates in 3D space. I need to calculate the angle from A to B. So if i was to put the angles through the following calculation it would find the original coords:



Basically I can convert one way, but I need to be able to do both ways. I've found something on an old thread I posted a long time ago, which almost works. So far I have.



Sorry KISTech. I think our questions are very closely related. I'll open another thread if you want me too though.
KISTech
18
Years of Service
User Offline
Joined: 8th Feb 2008
Location: Aloha, Oregon
Posted: 3rd May 2011 22:42
That has to be the best explanation I've seen on that yet.

Thanks!!

KISTech
18
Years of Service
User Offline
Joined: 8th Feb 2008
Location: Aloha, Oregon
Posted: 3rd May 2011 22:50
NickH, it's ok. They are very closely related.

I think the same methods can be used to find the X and Y angles you are looking for.

Diggsey, tested it and it worked like a charm.

NickH
18
Years of Service
User Offline
Joined: 19th May 2008
Location: Nova Prospekt, North Yorks, UK
Posted: 3rd May 2011 23:13
It's not exactly the same, but close That formula I'm using at the moment almost works. At the moment for testing purposes I'm clicking on a sphere and instead of just placing an another object on the returned coordinates (which does work anyway), I want to convert to angles, then back again and place the object on the returned coords. This will prove to me it works before I continue to the next stage.
KISTech
18
Years of Service
User Offline
Joined: 8th Feb 2008
Location: Aloha, Oregon
Posted: 4th May 2011 00:18
Take a dummy object and place it at object 1's location, and rotate it to 0,0,0.

Then use point object to point the dummy object to object 2.

Point object only changes the X and Y axis, so taking those angles from the dummy object is kind of a cheat, but it should be accurate.

NickH
18
Years of Service
User Offline
Joined: 19th May 2008
Location: Nova Prospekt, North Yorks, UK
Posted: 4th May 2011 00:32
Thanks. I had thought of that.

I've got it to work thankfully. Now when I click on Earth I can get real long and lat and save selections like that. Very useful!

I noticed 2 of my coords were calculated the wrong way round! so my object was using the wrong coords... DOH!
KISTech
18
Years of Service
User Offline
Joined: 8th Feb 2008
Location: Aloha, Oregon
Posted: 4th May 2011 01:59
Isn't math fun???

Login to post a reply

Server time is: 2026-07-11 13:58:12
Your offset time is: 2026-07-11 13:58:12