Loading ...
Global Do...
News & Politics
29
0
Try Now
Log In
Pricing
Creating a cylinder between two points or a plane/disk perpendicular to a line Written by Paul Bourke February 1997 There are a number of 3D geometric construction techniques that require a coordinate system perpendicular to a line segment, some examples are: Creating a disk given its center, radius and normal. ● Forming a cylinder given its two end points and radii at each end. ● Creating a plane coordinate system perpendicular to a line. ● A straightforward method will be described which facilitiates each of these. The key is deriving a pair of orthonormal vectors on the plane perpendicular to a line segment P1, P2. Procedure 1. Choose any point P randomly which doesn't lie on the line through P1 and P2 2. Calculate the vector R as the cross product between the vectors P - P1 and P2 - P1. This vector R is now perpendicular to P2 - P1. (If R is 0 then 1. wasn't satisfied) 3. Calculate the vector S as the cross product between the vectors R and P2 - P1. This vector S is now perpendicular to both R and the P2 - P1. 4. The unit vectors ||R|| and ||S|| are two orthonormal vectors in the plane perpendicular to P2 - P1. Points on the plane through P1 and perpendicular to n = P2 - P1 can be found from linear combinations of the unit vectors R and S, for example, a point Q might be Qx = P1x + alpha Rx + beta Sx Qy = P1y + alpha Ry + beta Sy Qz = P1z + alpha Rz + beta Sz Creating a cylinder or plane/disk perpendicular to a line segment file:///F|/Geometry/Display 09 Algorithms/Creating a cylinder or plane-disk perpendicular to a line segment.htm (1 of 2) [12/22/2000 03:43:02 PM] for all alpha and beta. A disk of radius r, centered at P1, with normal n = P2 - P1 is described as follows Qx = P1x + r cos(theta) Rx + r sin(theta) Sx Qy = P1y + r cos(theta) Ry + r sin(theta) Sy Qz = P1z + r cos(theta) Rz + r sin(theta) Sz for 0 <= theta <= 2 pi Example The following is a simple example of a disk and the C source stub that generated it. { XYZ origin={0.0,0.0,0.0},p1={0.0,1.0,1.0},p2={1.0,2.0,3.0}; XYZ plane[3]; XYZ n,p,r,s,p1p2; double theta,dtheta; p1p2 = VectorSub(p1,p2); p.x = rand(); /* Create a random vector */ p.y = rand(); p.z = rand(); CROSSPROD(p1p2,p,r); CROSSPROD(p1p2,r,s); Normalise(&r); Normalise(&s); dtheta = TWOPI / 36; for (theta=0;theta<TWOPI;theta+=dtheta) { n.x = r.x * cos(theta) + s.x * sin(theta); n.y = r.y * cos(theta) + s.y * sin(theta); n.z = r.z * cos(theta) + s.z * sin(theta); Normalise(&n); plane[0].x = p1.x + r.x * cos(theta) + s.x * sin(theta); plane[0].y = p1.y + r.y * cos(theta) + s.y * sin(theta); plane[0].z = p1.z + r.z * cos(theta) + s.z * sin(theta); plane[1] = p1; plane[2].x = p1.x + r.x * cos(theta+dtheta) + s.x * sin(theta+dtheta); plane[2].y = p1.y + r.y * cos(theta+dtheta) + s.y * sin(theta+dtheta); plane[2].z = p1.z + r.z * cos(theta+dtheta) + s.z * sin(theta+dtheta); WRITE THE FACET "PLANE" IN WHATEVER FORMAT YOU LIKE } } Creating a cylinder or plane/disk perpendicular to a line segment file:///F|/Geometry/Display 09 Algorithms/Creating a cylinder or plane-disk perpendicular to a line segment.htm (2 of 2) [12/22/2000 03:43:02 PM]