# Thread: Calculate a 3D direction vector using three points.

1. ## Calculate a 3D direction vector using three points.

Good day everyone.
I hope someone can help me with this problem, I've been stuck for a couple of days.

Heres my problem,
I'm trying to calculate the the orientation of an object in 3D space (yaw, tilt, pan), and express it as a three dimensional direction vector. <X,Y,Z>. I only have three known points on the object. And know that those points are orthogonal to each other. (See pictures below for visual aid.) I have Point R, Point B, and Point Y. (Respectively to the colors in the image. Red Blue and Yellow). Additionally, point V is the vertex, such that all points are perpendicular to each other.

By knowing points
B(x,y,z)
Y(x,y,z)
R(x,y,z)

The vertex can be calculated. (Using Thales Theorem with 3D spheres, and their common intersections.) Thus allowing me to calculate a vector from point B to the vertex, point V. Unfortunately, this calculation only get me 2/3rd of what I am trying to get.

Imagine that the vector BV represents the direction that the object is facing. (But not how much the object have rotated around that vector.) A crude example of this would be a human eye, or camera. The optical axis defines a direction vector analogous to the vector defined by point B and V in the image above. unfortunately, if I were to rotate this camera around the optical axis. Perhaps a full 180 degrees such that the camera is no upside down. This would effect the image.

So what I need help with is determining that amount of rotation, using the three points I mentioned above. If possible I would also like to express this direction and rotation, in a 3D direction vector.

I have done some research, and have only found how to rotate an object around a arbitrary vector, unfortunately, there is nothing about determining the rotation of a point(s) around a arbitrary vector.

If anyone could offer help, experience, knowledge or resources I would greatly appreciate it.

Thanks,
Taylor S. Amarel
Learning is living

1.
And I know that those points are orthogonal to each other.
Points aren't orthogonal to anything. Vectors or lines can be orthogonal. This statement is a category error.

2. Since the RBYV system appears to be attached to your object, where is your origin? Is it V? If not, I don't see how you can compute the location of V using only the coordinates of R, B, and Y. You would have to know lengths from those points to V, and even then you'd have two solutions, probably. At least, as an example, if V is equidistant from R, B, and Y, then there are two possible locations for V, one on either side of the plane containing R, B, and Y. Is there a handed-ness that you can invoke? Such as VY x VR = VB? (That's a vector cross product there). That could eliminate one of your two solutions, I think.

3. Use rotation matrices to represent rotations of a vector about a particular axis.

Hope this helps.

3. Thank you very much Adrian! The information on Rotation matrices is thick but very helpful.

I researched the information you posted, about rotation matrices, and vector cross product and WOW I learned a lot. Thanks!

As for the problem, to obtain the 3D direction vector BV, I have come up with two solutions. Unfortunately, I am not sure if they are entirely correct. Here they are;

The first way, and probably the most simplistic way would be to use the vector cross-product of point VY, and VR. Thus resulting in a 3D vector from point V to B. I'll denote this vector as VB. Then to calculate the 3D direction vector. I would, simply multiply vector VB by -1. To my knowledge this should reverse the direction vector, thus resulting in the vector BV. Analogous to the purple vector in the image above. Unfortunately, although this should get me the vector BV, I am magnitude. Do I need to normalize the vector before I do the cross product? It seems to be that I would not because I am only looking for direction, not magnitude.

The second way is still kind of under development, but I will give it a shot. This method would utilize the rotation matrices. I have not worked the entire method out, but from what I have read, it appears I may be able to work backwards using rotation matrices. If I know the starting and ending points, I should be able to use the inverse trigonometry functions to calculate the amount of rotations. Does this make sense? As I have said rotation matrices reading is thick, and I'm still working on it. My main concern, is that it will not be as simple calculating the inverse and then solving.

Thanks for the information, you have no idea how much just a little push in the right direction helps!

Taylor S. Amarel
Learning Is Living

4. Just to clarify: are you given vectors VY and VR? It sounds like you are. If so, you can compute a vector parallel or anti-parallel to VB in the way you have described. It's certainly the most direct way to do so. If you take the cross product VY x VR, you will get a vector orthogonal to both VY and VR. In addition, multiplying the result by -1 will indeed reverse the vector. However, I don't know how to answer the magnitude question. If you're not interested in the magnitude of VB, but only its direction, then it doesn't matter whether you normalize ahead of time or after the fact! Normalization is just multiplication by a positive scalar. It won't change the direction of anything. I would avoid normalization if you're not interested in magnitudes.

As for the rotation matrix approach: you can make it work, if you don't overthink it. The inverse of an elementary rotation matrix (i.e., about one of the three cartesian axes) is the same rotation matrix with a negative angle substituted in. (Don't think inverse trig functions here.) That makes sense, right? If I rotate about the x axis through $\alpha$ radians, I can reverse that operation by going back $\alpha$ radians, or in other words, if I rotate through $-\alpha$ radians, I get back to where I started.

If you apply multiple rotations, you have to "undo" them in the reverse order in which you applied them (like a stack in computer science: last in, first out).

5. Thanks a lot! Your posts never cease to educate.

I decided to go with the straightforward vector method. And using the information provided in the previous posts decided to normalize them after multiplying them. (In the end result I'm going to need some degree of consistency, that why I chose to normalize even though it has no effect of direction.

Originally Posted by Ackbeet
Just to clarify: are you given vectors VY and VR? It sounds like you are. If so, you can compute a vector parallel or anti-parallel to VB in the way you have described. It's certainly the most direct way to do so. If you take the cross product VY x VR, you will get a vector orthogonal to both VY and VR. In addition, multiplying the result by -1 will indeed reverse the vector.
And to clarify, I am not given the vectors VY, and VR. (I jumped ahead of myself on that one.) The only know points I have are R, G, B. I hope it was possible to calculate V. Unfortunately, as you stated, there are two points that V could be. This is were I jumped ahead, I previously though that it might be possible to eliminate one of the angles by comparing the heights of the different points. I was very wrong, there is a range of degrees where the direction vector is pointing along the horizon that this method will not compute the right point for V.

I did some research on how to eliminate one of the points using a cross product, but was unsuccessful. My gut thought be that this elimination would require a system of equations such that VY x VR = VB. Although wouldn't that be the case for both points of V? I seem to be stuck again. What would you suggest? I will try to do some research but as I said I've found limited materials on the web.

Once I can confidently determine V, I am positive that I can integrate everything together. I've learned a lot from this project!

Originally Posted by Ackbeet
As for the rotation matrix approach: you can make it work, if you don't overthink it. The inverse of an elementary rotation matrix (i.e., about one of the three cartesian axes) is the same rotation matrix with a negative angle substituted in. (Don't think inverse trig functions here.) That makes sense, right? If I rotate about the x axis through $\alpha$ radians, I can reverse that operation by going back $\alpha$ radians, or in other words, if I rotate through $-\alpha$ radians, I get back to where I started.

If you apply multiple rotations, you have to "undo" them in the reverse order in which you applied them (like a stack in computer science: last in, first out).
Wow, that sense now! Although I decided against implementing a rotation matrix algorithm. You explanation was superb, along with some research I did, I feel confident that if I did need to utilize a rotation matrix, I could!

Thanks very much.
Taylor S. Amarel
Learning is Living

6. So, to go back to the basic question here: what is your goal, in a precisely framed mathematical question?

It appears that one step towards a "solution", whatever that is, is to find a point V such that all three vectors VB, VY, and VR are orthogonal to each other. To find the points V that satisfy that condition, I would set up the following equations:

$V=\langle v_{1},v_{2},v_{3}\rangle.$

$VB = B - V$

$VY = Y - V$

$VR = R - V$

$VB\cdot VY = 0$

$VB\cdot VR = 0$

$VY\cdot VR = 0.$

I think there will be two solutions for this (nonlinear) system of equations. To eliminate one of them, here's one possibility: does V have to occur in the object? You've got three points that are on the object. If V has to be on the object as well, that might eliminate one of your two solutions. Just a thought.

7. ???

Weird duplication of a line of the OP. Should be deleted.

8. In Mathematical terms. I want to accurately, and consistently calculate the Vector BV. (Shown in purple in the original image).

The method of calculating BV must work for all possible spacial positions of the three points. For example, I hope to calculate BV successfully regardless of the probe is facing down, up, rotated, or tilted in various direction.

The roadblock is the two possible coordinates for V. And to answer your question; V is connected to the object, but only to some degree. The object would be attached below V such that it would lie on the vector BV. (Assuming the magnitude of the vector extends to such a length). So in reality, I am using the probe to calculate the spacial positioning of the object. Thus making it impossible to eliminate one solution if it does NOT lie on the object.

Mathematically, it seams as if I need more information about this situation in order to eliminate the other coordinate.

9. If you can't use the object, the only other thing that comes to mind (which, by the way, does not rule out other possibilities!) is if you can assign a "handedness" to the coordinate system you're trying to define. In your model in the pictures, you've got (assuming all vectors have unit length) VY x VR = VB. Now, if you imagine the opposite solution (where V is on the other side of the plane defined by Y, R, and B), then I think you can see that VY x VR = - VB.

Like I said, this is the only other possible way I know of to eliminate the other solution. Can you use this method?