`

计算几何_点到直线的垂足

阅读更多

struct point{
	double x, y;
};
//求点p到st->ed的垂足,列参数方程
point getRoot(point p, point st, point ed){
	point ans;
    double u=((ed.x-st.x)*(ed.x-st.x)+(ed.y-st.y)*(ed.y-st.y));
    u = ((ed.x-st.x)*(ed.x-p.x)+(ed.y-st.y)*(ed.y-p.y))/u;
    ans.x = u*st.x+(1-u)*ed.x;
    ans.y = u*st.y+(1-u)*ed.y;
    return ans;
}
 
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics