finding the midPoint, VectorManipulation
by rennie moffat · in iTorque 2D · 11/24/2010 (8:15 pm) · 8 replies
I have a basic math question using vector manipulation that I can't solve right now.... am researching but if I wanted to fine the midPoint between to vectors, say...
I want the midpoint between (vectorAx, vectorAy) and (vectorBx, vectorBy) then which t2dVector manipulation would best get me that?
I want the midpoint between (vectorAx, vectorAy) and (vectorBx, vectorBy) then which t2dVector manipulation would best get me that?
About the author
My thanks to Garage Games and the Garage Games Community combined with owned determination I got one game up, Temple Racer and I am looking to build more interesting, fun games for the mass market of the iOS app store.
#2
But I came across one problem.
If the distance is not absolute, it can sometimes pick the wrong vector. For instance if...
Vector1 (10, 9)
Vector2 (3, 7)
t2dVectorSub is (Vector2 - Vector1),
in which case the result is (-7, -2)
This relut is not ideal.
How would you deal with negative and positive results from the t2dSubtraction and insuring the vector ultimately used for the midPoint is neither the opposite X or Y value required?
11/24/2010 (11:40 pm)
Thanks Richard, But I came across one problem.
If the distance is not absolute, it can sometimes pick the wrong vector. For instance if...
Vector1 (10, 9)
Vector2 (3, 7)
t2dVectorSub is (Vector2 - Vector1),
in which case the result is (-7, -2)
This relut is not ideal.
How would you deal with negative and positive results from the t2dSubtraction and insuring the vector ultimately used for the midPoint is neither the opposite X or Y value required?
#3
11/25/2010 (1:32 am)
The vector (-7, -2) represents the DIRECTION of the vector that goes between the two (and the length of that vector is the distance between the two, by the way). Half that vector, (-3.5, -1), represents half the distance in the same direction of course. Adding the vector (-3.5, -1) to the first vector (10, 9) will yield the vector (6.5, 8), which is indeed the midpoint between (10, 9) and (3, 7).
#4
Thanks!
11/25/2010 (2:20 am)
hmm. ok. I am going to go over this. If I have any more questions I will ask for sure.Thanks!
#5
11/25/2010 (8:04 am)
Draw the lines on a graph to help you visualize it. Draw a line from A to B, and then draw the vector C that results from subtracting B - A. Notice that C is the exact same length and direction as the line from A to B. Also, remember when drawing a vector on a graph, you should put an arrow on the end of the line, as a vector describes a direction. That way, you can see that A-B and B-A yield different vectors of the same size, pointing in opposite directions.
#6
So
Nicolas Buquet
www.buquet-net.com/cv/
11/25/2010 (12:07 pm)
If (vectorAx, vectorAy) and (vectorBx, vectorBy) are Points and not Vectors, the midPoint between A and B is easily calculated by :M = ( A + B ) / 2.0;
So
vectorMx = (vectorAx + vextorBx)/2.0; vectorMy = (vectorAy + vextorBy)/2.0;
Nicolas Buquet
www.buquet-net.com/cv/
#8
11/25/2010 (7:18 pm)
Oh yeah, that works, too. I guess I overcomplicated it :)
Torque Owner Richard Skala
Pixel Vandals Inc.
Since you want a vector D, representing half the distance, divide the elements of C by 2:
D.x = C.x / 2.0
D.y = C.y / 2.0
Add your resulting vector to the first (A) to get the vector E that represents the midpoint between A and B:
E = D + A