/***********************************************************************************************************\
线与面的交点
@PlanePt:平面内一点
@PlaneVector:平面的法向量
@LinePt:直线上一点
@LineVector:直线的向量
************************************************************************************************************/
Point3d_s point2PlaneProjectionPoint(Point3d_s PlanePt, double PlaneVector[], Point3d_s LinePt, double LineVector[])
{
Point3d_s returnPoint; //(x,y,z)
double vp1, vp2, vp3, n1, n2, n3, v1, v2, v3, m1, m2, m3, t, vpt;
vp1 = PlaneVector[0]; //平面的法线向量 x,y,z//
vp2 = PlaneVector[1];
vp3 = PlaneVector[2];
n1 = PlanePt.x; //平面经过的一点坐标
n2 = PlanePt.y;
n3 = PlanePt.z;
v1 = LineVector[0]; //直线的方向向量 //【这个地方需要再次计算求出】
v2 = LineVector[1];
v3 = LineVector[2];
m1 = LinePt.x; //直线经过的一点坐标
m2 = LinePt.y;
m3 = LinePt.z;
vpt = v1 * vp1 + v2 * vp2 + v3 * vp3;
//首先判断直线是否与平面平行
if (vpt == 0)
{
returnPoint.x = -999;
returnPoint.y = -999;
returnPoint.z = -999;
}
else
{
t = ((n1 - m1) * vp1 + (n2 - m2) * vp2 + (n3 - m3) * vp3) / vpt;
returnPoint.x = m1 + v1 * t;
returnPoint.y = m2 + v2 * t;
returnPoint.z = m3 + v3 * t;
}
printf("pointtoPlaneProjectionPoint.xyz= %f, %f, %f\n", returnPoint.x, returnPoint.y, returnPoint.z);
//getchar();
return returnPoint;
}
3D空间位置计算 — 线与面的交点
最新推荐文章于 2024-04-23 14:48:29 发布