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

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

问题描述

点A(x1,y1,z1)是一行的起点".点B(x2,y2,z2)是直线的末端".

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

我在Java中的代码目前可以在3d中沿一条线得到一个点,但是我不知道如何找到仅给出一条线的垂直线的方向向量,这是我唯一的信息./p>

提前谢谢.

在直线上获取点工作正常,但是我认为我不理解如何从一条直线上查找平面法线向量或如何使用该法线来获得一条垂直线.

 公共类ParameterizedLine {私有Vector3f originVector;私有Vector3f directionVector;public ParameterizedLine(Line line){originVector =新的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点=新的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);返回点}public ParameterizedLine getPerpendicularLineAtDistance(浮动距离){Vector3f perpindicularOriginVector = getPointAtDistance(distance);Vector3f planeNormalVector = originVector.cross(originVector.add(directionVector));Vector3f perpindicularDirectionVector = directionVector.cross(planeNormalVector);ParameterizedLine perpindicularLine =新的ParameterizedLine(perpindicularOriginVector,perpindicularDirectionVector);返回perpindicularLine;}私人浮动getDistanceRatio(浮动距离){返回距离/(originVector.distance(originVector.add(directionVector))));}公共Vector3f getOrigin(){返回originVector;}公共Vector3f getDirection(){返回directionVector;}@Override公共字符串toString(){返回"ParameterizedLine {" +"originVector =" + originVector +,directionVector =" + directionVector +'}';}} 

明显的解决方案,可以找到任意距离的垂直点,欢迎进行校对.

  public Vector3f getPerpendicularPoint(float parametricDistance,float verticalDistance){Vector3f parametricPoint = getPointAtDistance(parametricDistance);Vector3f verticalVector =新的Vector3f();if(directionVector.x< = directionVector.y&&direction; VectorVector x< = directionVector.z){verticalVector.set(0,-directionVector.z,directionVector.y);}否则,如果(directionVector.y< = directionVector.x&& directionVector.y< = directionVector.z){verticalVector.set(-directionVector.z,0,directionVector.x);}否则,如果(directionVector.z< = directionVector.x&& directionVector.z< = directionVector.y){verticalVector.set(-directionVector.y,directionVector.x,0);}Vector3f normalizedPerpendicularVector = verticalVector.normalize();Vector3f verticalPoint = parametricPoint.add(normalizedPerpendicularVector.mult(perpendicularDistance));返回verticalPoint;} 

解决方案

单行没有定义唯一的平面-因为它属于空间中无限数量的平面.因此,您必须提供有关飞机的其他信息.

如果没有关于此平面的其他信息,则可能要选择该线所属的任意平面:

让我们的(dx,dy,dz)是您的directionVector.找到2个幅度更大的元素,交换它们,然后取反其中之一.将第三个元素(幅度最小)设置为零.此向量垂直于directionVector.

示例:

 如果(dx< = dy)和(dx< = dz),则PV =(0,-dz,dy) 

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

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

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

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

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

解决方案

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)

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

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