Question

Point A (x1,y1,z1) being the "start" of a line. Point B (x2,y2,z2) being the "end" of a line.

Knowing only line AB in 3d space I need to find points -t and t distance along two perpendicular lines intersecting line AB at Points A and B respectively on the same plane as line AB.

My code in java can currently get a point along a line in 3d, but I can't figure out how to find the direction vector of the perpendicular lines with only one line given, which is the only information I have.

Thanks in advance.

Edit: Getting points on the line is working fine, however I do not think I understand how to find plane Normal vectors from a single line or how to use that to get a perpendicular line.

public class ParameterizedLine {

   private Vector3f originVector;
   private Vector3f directionVector;

   public ParameterizedLine(Line line) {
      originVector = new Vector3f(line.getOrigin());
      directionVector = line.getDirection().subtract(originVector);
   }

   public ParameterizedLine(Vector3f originVector, Vector3f directionVector) {
      this.originVector = originVector;
      this.directionVector = directionVector;
   }

   public Vector3f getPointAtDistance(float distance) {
      Vector3f point = new Vector3f();
      float distanceRatio = getDistanceRatio(distance);
      point.x = originVector.x + (directionVector.x * distanceRatio);
      point.y = originVector.y + (directionVector.y * distanceRatio);
      point.z = originVector.z + (directionVector.z * distanceRatio);
      return point;
   }

   public ParameterizedLine getPerpendicularLineAtDistance(float distance) {
      Vector3f perpindicularOriginVector = getPointAtDistance(distance);
      Vector3f planeNormalVector = originVector.cross(originVector.add(directionVector));
      Vector3f perpindicularDirectionVector = directionVector.cross(planeNormalVector);
      ParameterizedLine perpindicularLine = new ParameterizedLine(perpindicularOriginVector,
                                                                  perpindicularDirectionVector);
      return perpindicularLine;
   }

   private float getDistanceRatio(float distance) {
      return distance / (originVector.distance(originVector.add(directionVector)));
   }

   public Vector3f getOrigin() {
      return originVector;
   }

   public Vector3f getDirection() {
      return directionVector;
   }

   @Override
   public String toString() {
      return "ParameterizedLine{" + "originVector=" + originVector + ", directionVector=" + directionVector + '}';
   }


}

Edit 2: Apparent solution to finding perpendicular points at arbitrary distance, proofreading welcome.

public Vector3f getPerpendicularPoint(float parametricDistance, float perpendicularDistance) {
      Vector3f parametricPoint = getPointAtDistance(parametricDistance);
      Vector3f perpendicularVector = new Vector3f();
      if(directionVector.x <= directionVector.y && directionVector.x <= directionVector.z){
         perpendicularVector.set(0, -directionVector.z, directionVector.y);
      } else if (directionVector.y <= directionVector.x && directionVector.y <= directionVector.z){
         perpendicularVector.set(-directionVector.z, 0, directionVector.x);
      } else if (directionVector.z <= directionVector.x && directionVector.z <= directionVector.y){
         perpendicularVector.set(-directionVector.y, directionVector.x, 0);
      }
      Vector3f normalizedPerpendicularVector = perpendicularVector.normalize();
      Vector3f perpendicularPoint = parametricPoint.add(normalizedPerpendicularVector.mult(perpendicularDistance));
      return perpendicularPoint;
   }
Was it helpful?

Solution

Single line doesn't define unique plane - because it belongs to infinite number of planes in space. So you have to provide additional info about plane.

If there is no additional information concerning this plane, you might want to choose arbitrary plane which this line belongs to:

Let's (dx, dy, dz) is your directionVector. Find 2 elements with bigger magnitude, exchange them, and negate one of them. Set the third element (with the least magnitude) to zero. This vector is perpendicular to directionVector.

Example:

if (dx <= dy) and (dx <= dz) then PV = (0, -dz, dy)

Then normalize this vector uP = PV / |PV| And your target points

Ta = A +- t * uP (two points)

Tb = B +- t * uP (two points)

Note that line AB and all points A, B, Ta1, Ta2, Tb1, Tb2 lie in the same plane (arbitrarily chosen)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top