| ||||||||||
Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
Re:请问当倾斜角为0或PI/2时有没有方便的处理方法?In Reply To:Re:请问当倾斜角为0或PI/2时有没有方便的处理方法? Posted by:ZaeX at 2008-12-04 10:53:56 矩阵,点解? 用向量可避免角度讨论,代码如下: 大概思路,先用向量的叉乘来判断是否平行,再用两个向量方程解出交点x0,y0,直接输出方程解的表达式即可。 #include<stdio.h> int T,x1,x2,x3,x4,y1,y2,y3,y4; double t; int main(){ puts("INTERSECTING LINES OUTPUT"); for(scanf("%d",&T);T--;){ scanf("%d%d%d%d%d%d%d%d",&x1,&y1,&x2,&y2,&x3,&y3,&x4,&y4); x1-=x2;y1-=y2; x3-=x4,y3-=y4; t=x1*y3-y1*x3; if(!t){ x2-=x4;y2-=y4; puts(x2*y3==x3*y2?"LINE":"NONE"); }else{ printf("POINT %.2f %.2f\n",(x1*y2*x3-y1*x2*x3+x1*y3*x4-x1*x3*y4)/t,(x1*y2*y3-y1*x2*y3+y1*y3*x4-y1*x3*y4)/t); } } puts("END OF OUTPUT"); return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator