Jump to content

View more

Image of the Day

The night is still, but the invasion brings chaos. #screenshotsaturday #hanako #indiegame #gameart #ue4 #samurai https://t.co/cgILXuokoS
IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.


Sign up now

Find point between 2 points?

4: Adsense

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.


  • You cannot reply to this topic
4 replies to this topic

#1 tuphdc   Members   

103
Like
0Likes
Like

Posted 17 April 2011 - 05:54 PM

I am having a problem finding a point at a specific distance between 2 points. Suppose I have point A(1,1) and point B(4,4). I know the distance between these 2 points is 4.24. However, I do not know how to find point C, which is 1/4 the distance from point A to point B. How do I find point C?

#2 lotusf1   Members   

137
Like
0Likes
Like

Posted 17 April 2011 - 06:00 PM

What you are looking for is the midpoint - http://en.wikipedia.org/wiki/Midpoint

#3 SimonForsman   Members   

7633
Like
4Likes
Like

Posted 17 April 2011 - 06:09 PM

I am having a problem finding a point at a specific distance between 2 points. Suppose I have point A(1,1) and point B(4,4). I know the distance between these 2 points is 4.24. However, I do not know how to find point C, which is 1/4 the distance from point A to point B. How do I find point C?


to find a line 1/4th of the distance between 2 points you just need:

Vector2D p1(1,1);
Vector2D p2(4,4);

Vector2D direction = p2-p1

Vector2D p3 = p1+ direction* 0.25; (assuming your vector library supports scalar multiplication, if not its simply p3.x = p1.x + direction.x*0.25 and same for y)

If you don't have a vector library you can simply do

p1x=1;
p1y=1;
p2x=4;
p2y=4;

dirx=p2x-p1x;
diry=p2y-p1y;

p3x = p1x+dirx*0.25;
p3y = p1y+diry*0.25;
I don't suffer from insanity, I'm enjoying every minute of it.
The voices in my head may not be real, but they have some good ideas!

#4 fastcall22   Moderators   

10682
Like
1Likes
Like

Posted 17 April 2011 - 06:11 PM

Using vector algebra:
C = (B - A) * .25 + A
C = (<4,4> - <1,1>) * .25 + <1,1>
C = <3,3> * .25 + <1,1>
C = <.75,.75> + <1,1>
C = <1.75, 1.75>

Or:
Cx = (Bx - Ax) * .25 + Ax
Cy = (By - Ay) * .25 + Ay
zlib: eJzVVLsSAiEQ6/1qCwoK i7PxA/2S2zMOZljYB1TO ZG7OhUtiduH9egZQCJH9 KcJyo4Wq9t0/RXkKmjx+ cgU4FIMWHhKCU+o/Nx2R LEPgQWLtnfcErbiEl0u4 0UrMghhZewgYcptoEF42 YMj+Z1kg+bVvqxhyo17h nUf+h4b2W4bR4XO01TJ7 qFNzA7jjbxyL71Avh6Tv odnFk4hnxxAf4w6496Kd OgH7/RxC

#5 tuphdc   Members   

103
Like
0Likes
Like

Posted 17 April 2011 - 06:43 PM

thank you very much!!




Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.