三维空间已知两个点坐标及在该直线上未知点到其中一个点的距离,求该未知点的坐标
2014 年 3 月 25 日 三维空间已知两个点坐标及在该直线上未知点到其中一个点的距离,求该未知点的坐标无评论
很久不用数学,尤其对三维空间的计算几乎完全忘光,在补了一些基本知识后经过了一些变换及换算,最后简化得到了如下的函数算法。
1.数据结构
class CPoint
{
public:
CPoint()
{
x = 0.0f;
y = 0.0f;
z = 0.0f;
}
double x;
double y;
double z;
};
{
public:
CPoint()
{
x = 0.0f;
y = 0.0f;
z = 0.0f;
}
double x;
double y;
double z;
};
2.函数实现
CPoint CPointInfo::getPoint( CPoint p1, CPoint p2, double mDistance )
{
CPoint point;
double distance = getDistance(p1,p2);
double theta = asin((p2.z-p1.z)/distance);
point.x = p1.x+mDistance/cos(theta)/distance*(p2.x-p1.x);
point.y = p1.y+mDistance/cos(theta)/distance*(p2.y-p1.y);
point.z = p1.z+mDistance/cos(theta)/distance*(p2.z-p1.z);
return point;
}
double CPointInfo::getDistance( CPoint p1, CPoint p2 )
{
return sqrt((p1.x-p2.x)*(p1.x-p2.x)+(p1.y-p2.y)*(p1.y-p2.y)+(p1.z-p2.z)*(p1.z-p2.z));
}
{
CPoint point;
double distance = getDistance(p1,p2);
double theta = asin((p2.z-p1.z)/distance);
point.x = p1.x+mDistance/cos(theta)/distance*(p2.x-p1.x);
point.y = p1.y+mDistance/cos(theta)/distance*(p2.y-p1.y);
point.z = p1.z+mDistance/cos(theta)/distance*(p2.z-p1.z);
return point;
}
double CPointInfo::getDistance( CPoint p1, CPoint p2 )
{
return sqrt((p1.x-p2.x)*(p1.x-p2.x)+(p1.y-p2.y)*(p1.y-p2.y)+(p1.z-p2.z)*(p1.z-p2.z));
}
其中mDistance为与p1的距离
Tags: 空间几何,3D计算
发表评论