已知点A(x1,y1)、B(x2,y2)、M(m,n),求点M在线段AB上的投影坐标。


 

double CTrackLineView::PointToXianDuanChuiYingPointjingdu(double m, double n, double x1, double y1, double x2, double y2)
{//计算点到线垂影坐标
	return 
		(
		(m*(x2-x1)*(x2-x1)+n*(y2-y1)*(x2-x1)+(x1*y2-x2*y1)*(y2-y1))
		/((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1))
		);


}
double CTrackLineView::PointToXianDuanChuiYingPointweidu(double m, double n, double x1, double y1, double x2, double y2)
{//计算点到线垂影坐标
	return
	(
		(m*(x2-x1)*(y2-y1)+n*(y2-y1)*(y2-y1)+(x2*y1-x1*y2)*(x2-x1))
		/((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1))
	);

}

  

 


posted on 2016-05-30 20:52  奶味洋葱头  阅读(5657)  评论(0编辑  收藏  举报