点到直线的垂足算法.docVIP

  • 12
  • 0
  • 约1.19千字
  • 约 2页
  • 2020-04-25 发布于江西
  • 举报
点到直线的垂足算法 // 二维空间点到直线的垂足 struct Point {   double x,y; } Point GetFootOfPerpendicular( const Point pt, // 直线外一点 const Point begin, // 直线开始点 const Point end) // 直线结束点 { Point retVal; double dx = begin.x - end.x; double dy = begin.y - end.y; if(abs(dx) 0 abs(dy) 0) { retVal = begin; return retVal; } double u = (pt.x - begin.x)*(begin.x - end.x) + (pt.y - begin.y)*(begin.y - end.y); u = u/((dx*dx)+(dy*dy)); retVal.x = begin.x + u*dx; retVal.y = begin.y + u*dy; return retVal; } // 三维空间点到直线的垂足 struct Point {   double x,y,z; } Point GetFootOfPerpendi

文档评论(0)

1亿VIP精品文档

相关文档