I'm trying to script the modeling of a set of 3D vectors. For a given vector, I have the start and end points in 3D space -- for example from 1,1,1 to 2,2,2. I'm not sure of the best way to approach this problem.

I'm imagining a cylinder with a cone on the end ("arrow") all grouped together that is located in some arbitrary location but with a unit length (e.g., 0,0,0 to 0,0,1). My inclination was parent the arrow to a bone and the translate the bone to the first position, followed by translation of the other end of the bone to the second position. Since the arrow is radially symmetric, rotation won't be an issue.

This solution seemed convoluted to me though (building an armature, etc.), since I have the endpoints where the geometry should go. It seems like there should be a way to translate the central node of the cylinder to point 1 and then translate/rotate the node at the tip of the cone to point 2.

I have read some of the other questions about orienting lights to normals (here, here, here), or rotating planes to be normal to a point, so I think the solution might be along those lines.


1 Answer 1


How do I construct a transformation matrix from 3 vertices? gives a generic technique to convert a triangle into a transformation matrix. You could use this to pick a transform matrix to apply to a generic cylinder.

If you don't like the choice of X as the primary axis, you can rearrange the arguments to Matrix([a2,b2,c2]) , although some of those orderings will be left-handed instead of right-handed, requiring you to reverse one of them. For example Matrix([b2,a2,-c2]).

Also, since your use case only includes 2 points, you'll need to pick a 3rd in order to construct the matrix. If you know something about the direction of the pairs of coordinates and can guarantee a 3rd coordinate that will always be non-colinear, use that. Otherwise, you'll have to add a little bit of logic that checks for things being "too colinear" and using a different 3rd axis.

If you want your cylinder to stretch with the distance between the points, you can use non-normalized a instead of a2.

If this narrative is a little too vague, go ahead and request some refinements in the comments.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .