Jump to content
  • Advertisement
Sign in to follow this  
starfleetrp

get an angle from two points

This topic is 4596 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I need to get the angle of a right triangle, so I can extrapulate the points between them. I know how to extrapulate the points once I have the angle, however I do not know how to get it. I have 2 sets of points(x,y). How could I get the angle from these?

Share this post


Link to post
Share on other sites
Advertisement
I may be misunderstanding you, but you cannot get an angle from two points; you can just get a line. Also you say you need the angle of a right triangle, but that's always 90 degrees!

Maybe you can clarify what you mean?

Share this post


Link to post
Share on other sites
With only two sets of points you have no triangle. Two points only define a line, for which there is no angle. If you know all three points of the triangle then this becomes a relatively simple problem with a little bit of vector math.

Let's say you have three points of a triangle, A, B, and C. You can find a vector between two sets of these points. So lets say you get the vector from point A to point B and then another vector from Point B to Point C. The vector from A to C should then just be the first vector plus the second one. Now that you have three vectors defining your triangle you can do dot product operations on any two of them and that will tell you the angle between them (more correctly, it will tell you about the difference in the direction that they point, but the angle can be extracted with A.B = ||A||*||B|| cos(a)

Share this post


Link to post
Share on other sites
Ok, lets try another approach, I guess (I could get the 3rd point, but this might be easier). I need to be able to figure out the points along a line at X intervals. I know where the starting and ending point of a line is. So how could I get the points in the line thats lets say 10u long and a new point will be drawn every .7. How would I be able to get the x,y cords for each point that id have to draw. The remaining space that wouldnt be used would just be ignored.

Share this post


Link to post
Share on other sites
Point 1: (0, 0)
Point 2: (10, 10)

What is the halfway point?
(5, 5)

What is .75?
(7.5, 7.5)

Think you can figure it out from here?

Take the difference between the 2 points and multiply it by the fraction you want to move and add it to the 1st point.

Share this post


Link to post
Share on other sites
I do not see how this would work because in a hyp triange, which is pretty much a line(the hypontnuse) which is what I want to move along .7. However, I do not know what that would translate to be the difference in the x,y cords. Or am I totally mis-understanding you. I know exactly how many points id have to add but using pythagoreans theorm. However I do not know the difference of the x,y values.

Share this post


Link to post
Share on other sites
Quote:
Original post by starfleetrp
I do not see how this would work because in a hyp triange, which is pretty much a line(the hypontnuse) which is what I want to move along...


If you only want to move along the hypotenuse, you can, I would suppose, effectively ignore the two other legs of the triangle. So if you want to move in increments of .7, just find the points that are .7 units away from the first point. I'm not going to be redundant and reiterate the math, just trying to help you understand the concept. Hope it helps.

-AJ

EDIT: I think tstrimp's latest explanation sums it up pretty nicely.

Share this post


Link to post
Share on other sites
Well I didnt think this would work, and it didnt. My result is a line of dots that procedes off of the screne, even though the line has a hyponeuse of 11u and there should be a dot at .7u incriments. And I know that there should then by dist/inc or 11/.7 = 15.71 lines (how would I round down) so 15 dots. So how would I calculate the distance? Since I am doing something wrong

so
offset = (x1-x2)*dist*inc
(11)*.7*1 = 7.7
...
(11)*.7*15 = 115.5

however I should have only gotten
.7 1.4 2.1 etc. as the final offset

I do not know of anyway to fix this. Well atleast I can not think of any with the forumal I have been given. I have tried this on paper a few times and just could not think of anyting.

Share this post


Link to post
Share on other sites
In the formula I provided, r is the distance as a fraction of the magnitude of the vector. The distance you are moving is 70% of 11u or 7.7u per jump. Since you only want to move .7u, you need to figure out what percentage .7u is of 11u. .7 / 11 = 0.0636363. So in your case the formula should use 0.0636363 or 0.7/11.0 as r.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!