在与 3d 中给定线相同的平面上的垂直线上找到 t 距离的点 [英] Finding point of t distance on a perpendicular line on the same plane as a given line in 3d

查看:27
本文介绍了在与 3d 中给定线相同的平面上的垂直线上找到 t 距离的点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

点 A (x1,y1,z1) 是一条线的起点".点 B (x2,y2,z2) 是一条线的终点".

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

只知道 3d 空间中的线 AB 我需要沿着两条垂直线分别在同一点 A 和 B 处与线 AB 相交找到点 -tt 距离平面为AB线.

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.

我在 java 中的代码目前可以在 3d 中沿着一条线获得一个点,但我无法弄清楚如何在只给出一条线的情况下找到垂直线的方向向量,这是我唯一的信息.

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.

提前致谢.

在线上获取点工作正常,但是我认为我不明白如何从单条线上找到平面法向量或如何使用它来获得垂直线.

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


}

编辑 2:在任意距离找到垂直点的明显解决方案,欢迎校对.

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

推荐答案

单线不定义唯一的平面——因为它属于空间中无限多个平面.因此,您必须提供有关飞机的其他信息.

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:

让我们 (dx, dy, dz) 是你的方向向量.找出2个量级较大的元素,交换它们,并取反其中的一个.将第三个元素(具有最小量级)设置为零.该向量与方向向量垂直.

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.

示例:

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

然后归一化这个向量uP = PV/|PV|还有你的目标点

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

Ta = A +- t * uP(两分)

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

Tb = B +- t * uP(两分)

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

注意AB线和所有点A、B、Ta1、Ta2、Tb1、Tb2位于同一平面(任意选择)

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

这篇关于在与 3d 中给定线相同的平面上的垂直线上找到 t 距离的点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆