double glc::pointLineDistance(const GLC_Point3d& point, const GLC_Line3d& line) { const GLC_Vector3d lineDirection(line.direction().normalize()); double t= lineDirection * (point - line.startingPoint()); GLC_Point3d projectedPoint= line.startingPoint() + (t * lineDirection); return (point - projectedPoint).length(); }
GLC_Point3d glc::project(const GLC_Point3d& point, const GLC_Line3d& line) { const GLC_Vector3d lineDirection(line.direction().normalize()); double t= lineDirection * (point - line.startingPoint()); GLC_Point3d projectedPoint= line.startingPoint() + (t * lineDirection); return projectedPoint; }
GLC_Point3d glc::project(const GLC_Point3d& point, const GLC_Line3d& line) { // Create the plane from the point with normal define by the line direction const GLC_Plane plane(line.direction().normalize(), point); GLC_Point3d intersection; const bool intersect= lineIntersectPlane(line, plane, &intersection); Q_ASSERT(intersect == true); return intersection; }
bool glc::lineIntersectPlane(const GLC_Line3d& line, const GLC_Plane& plane, GLC_Point3d* pPoint) { const GLC_Vector3d n= plane.normal(); const GLC_Point3d p= line.startingPoint(); const GLC_Vector3d d= line.direction(); const double denominator= d * n; if (qFuzzyCompare(fabs(denominator), 0.0)) { qDebug() << " glc::lineIntersectPlane : Line parallel to the plane"; // The line is parallel to the plane return false; } else { // The line intersect the plane by one point const double t= -((n * p) + plane.coefD()) / denominator; (*pPoint)= p + (t * d); return true; } }