Reputation: 5193
I have 4 points, three of the points make two lines like a V or a < or a >, you get the idea, now I got a point that's in that cone (the V) and I can get the dist from the top to the bottom left, and bottom right, but not where the bottom pos is.
Maybe this will help.
And I have code to go along with this problem:
public float GetDist(Vector3f one, Vector3f two, Vector3f three, Vector3f p){
Vector3f one_to_point = new Vector3f(0,0,0);
Vector3f.sub(p,one,one_to_point); //Storing vector A->P
Vector3f one_to_two = new Vector3f(0,0,0);
Vector3f.sub(two, one, one_to_two); //Storing vector A->B
Vector3f one_to_three = new Vector3f(0,0,0);
Vector3f.sub(three, one, one_to_three); //Storing vector A->C
float q1 = Vector3f.dot(one_to_point, one_to_two) / one_to_two.lengthSquared(); // The normalized "distance" from a to b
float q2 = Vector3f.dot(one_to_point, one_to_three) / one_to_three.lengthSquared(); // The normalized "distance" from a to c
Now I already know that the pos vector is in the cone, so what do I need to do to get the pos as shown by the green circle's pos in the image?
Upvotes: 2
Views: 807
Reputation: 21351
You have 4 points in the plane : A,B,C and D (where D is what you label as pos in your diagram). A unique straight line can be drawn between any 2 distinct points so find the straight line that links A and D and get its equation in the form
y = m_1 * x + c_1
Do the same for line the points B and C to get
y = m_2 * x + c_2
Now you know the 2 lines, you can solve this pair of simultaneous equations to get the point (x,y) that lies at the green circle on your diagram - I shall call this E. Given E, calculate the length of vector BE and divide by the length of vector BC. This value is the value of X
that you are looking for in your question.
If you do not know how to find the equation for a line that goes through 2 points look at this link for details http://www.ugrad.math.ubc.ca/coursedoc/math100/notes/zoo/eqline.html
I do not doubt that there is a simpler more elegant way to do this but if you get no other answer here, this approach will serve your purpose.
Upvotes: 2
Reputation: 303
It's been a while since I've done vector algebra, but let me see if I got this right. You're looking for the green point, which is where a line from A to Pos intersects a line from B to C.
I believe if you knew the ratio of the angle that B-A-Pos forms to the angle that B-A-C forms, that ratio would be the same as the ratio of the distance from B to Green to the distance from B to C. From B, the direction of Green is the same as the direction of C, so the vector that represents Green's location is
VectorGreen = VectorB + (x1 / x2)(VectorC - VectorB) //The vector to B plus a fraction of the vector from B to C
x1 = arccos ( Normalize(VectorP - VectorA ) * Normalize(VectorB - VectorA) )//Angle between A to B and A to Pos
x2 = arccos ( Normalize(VectorB - VectorA ) * Normalize(VectorC - VectorA) ) //Angle between A to B and A to C
Upvotes: 1