计算几何
作者:互联网
判断线段相交,求交点
首先判断两条线段是否相交
图中,设两线段交点为 \(E\)
\(\because \frac{|CE|}{|DE|}=\frac{△ACD在CD边上的高}{△BCD在CD边上的高}\;\;=\frac{S_{△ACD}}{S_{△BCD}}=\frac{CD×CA}{CB×CD}=\frac{(x_D-x_C)(y_A-y_C)-(x_A-x_C)(y_D-y_C)}{(x_B-x_C)(y_D-y_C)-(x_D-x_C)(y_B-y_C)}=k\)
\(\therefore E=(\frac{k*x_B+x_A}{k+1},\frac{k*y_B+y_A}{k+1}),CE=\frac{k}{k+1}CD\)
point intersect(point P,Vector v,point Q,Vector w){
point ret;
Vector u=P-Q;
if(sgn(v*w)==0)return false;
double t=(w*u)/(v*w);
ret=P+v*t;
return ret;
}
标签:frac,point,ACD,ret,CD,Vector,计算,几何 来源: https://www.cnblogs.com/BlogOfchc1234567890/p/10385532.html