如何求两条线段交点的三维坐标,并且两条线段在水平面的投影重合?
在三维空间中,有两条线段AB和CD,他们的坐标分别是A(x1,y1,z1),B(x2,y2,z2),C(x3,y3,z3),D(x4,y4,z4),并且A点的x坐标和y坐标与C点的x坐标和y坐标一样,B点的x坐标和y坐标与D点的x坐标和y坐标一样,假设线段AB和CD相交于点E,求出点E的三维坐标,下面是我的代码,经过测试,得到的结果不正确,希望能够得到一些指点,谢谢大家
private double[] calculateIntersectionPoint(double x1, double y1, double x2, double y2, double[] z3, double[] z4) { double[] intersection = new double[3];
double t=(z3-z1)/((z2-z1)-(z4-z3));
intersection[0]=x1+t*(x2-x1);
intersection[1]=y1+t*(y2-y1);
intersection[2]=z1+t*(z2-z1);
return intersection;
}
回答:
private double[] calculateIntersectionPoint(double x1, double y1, double z1, double x2, double y2, double z2, double x3, double y3, double z3, double x4, double y4, double z4) { double[] intersection = new double[3];
直接用x1, y1, x2, y2作为交点的xy坐标
intersection[0] = x1;
intersection[1] = y1;
double t = (z3 - z1) / ((z2 - z1) - (z4 - z3));
// 计算交点的z坐标
intersection[2] = z1 + t * (z2 - z1);
return intersection;
}
以上是 如何求两条线段交点的三维坐标,并且两条线段在水平面的投影重合? 的全部内容, 来源链接: utcz.com/p/945342.html