0

I have two points A = (x0, y0, z0) and B = (x1, y1, z1) giving the centreline for a cylinder. I want to add a series of surface points with radius r from centreline, perpendicular to the line AB, to get a point cloud of the cylinder surface.

How can I best get a code that calculates points with r distance from centerline, perpendicular to AB, 360 degrees around the centreline, along the distance of AB.

  • The first step is to find a vector perpendicular to AB. Do you know how to do that? – Beta Jul 25 '21 at 14:26
  • Not 100% sure. We can get the AB vector by (x1-x0, y1-y0, z1-z0), and then a perpendicular vector would have a cross product of zero? But I don't get how to come up with a solution for getting perpendicular vectors 360 degrees around the centreline. – H.Helle Jul 25 '21 at 16:44
  • Does this answer your question? [Generating 3D Cylinder with Rotationmatrix](https://stackoverflow.com/questions/41494329/generating-3d-cylinder-with-rotationmatrix) – Spektre Aug 02 '21 at 08:13

1 Answers1

0

We have the vector from A to B, call it C. We can normalise it: c = C/|C|

The first step is to find a vector perpendicular to c. We pick one of the basis vectors, x, y or z. (If the dot product reveals that we picked one close or equal to c, we pick one of the other two instead.) Suppose we have picked x. We find the component of x in the direction of c:

(x•c)c

and subtract it from x to get a vector perpendicular to c:

J = x - (x•c)c

which we can then normailse to get j. Now use the cross product to get another unit vector, perpendicular to both c and j:

k = c × j

Now we can pick any angle θ and get a point on the unit circle centered on the origin and normal to c:

p = cos(θ)j + sin(θ)k

If we choose a point D on the line between A and B, we can find a point on the inot circle centered on D and normal to c:

q = cos(θ)j + sin(θ)k + D

Now vary D from A to B, and θ from 0 to 2π, and you're done.

Beta
  • 96,650
  • 16
  • 149
  • 150