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;
}