A点(x1,y1,z1)是一条线的“起点”。 B点(x2,y2,z2)是一条线的“末端”。
只知道3d空间中的AB线我需要在两条垂直线上找到点 -t 和 t 的距离,这两条垂直线分别在A点和B点与AB线相交飞机为AB线。
我在java中的代码当前可以在3d中沿着一条线得到一个点,但我无法弄清楚如何找到垂直线的方向向量,只给出一行,这是我唯一的信息。 / p>
提前致谢。
编辑: 在线上获得点工作正常,但我不认为我理解如何从单行找到平面法向量或如何使用它来获得垂直线。
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 + '}';
}
}
编辑2:在任意距离找到垂直点的明显解决方案,校对欢迎。
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;
}
答案 0 :(得分:1)
单行不定义唯一平面 - 因为它属于空间中无限多个平面。因此,您必须提供有关飞机的其他信息。
如果没有关于此平面的其他信息,您可能想要选择此线所属的任意平面:
让我们(dx,dy,dz)是你的directionVector。 找到2个更大的元素,交换它们,并否定其中一个元素。将第三个元素(幅度最小)设置为零。此向量垂直于directionVector。
示例:
if (dx <= dy) and (dx <= dz) then PV = (0, -dz, dy)
然后规范化此向量 uP = PV / | PV | 而你的目标点
Ta = A + - t * uP (两分)
Tb = B + - t * uP (两分)
注意AB线和所有A,B,Ta1,Ta2,Tb1,Tb2位于同一平面(任意选择)