###### Poj 1269

http://acm.pku.edu.cn/JudgeOnline/problem?id=1269

(p1-p0)X(p2-p0)=0

(p3-p0)X(p2-p0)=0

(y1-y2)x0+(x2-x1)y0+x1y2-x2y1=0

(y3-y4)x0+(x4-x3)y0+x3y4-x4y3=0

x0,y0作为变量求解二元一次方程组。

a1x+b1y+c1=0;

a2x+b2y+c2=0

x=(c1*b2-c2*b1)/(a2*b1-a1*b2);

y=(a2*c1-a1*c2)/(a1*b2-a2*b1);

/* Wrote by Dream , poj 1269, double 的零值判断不能直接写==0*/

#include <string>

#include <iostream>

#include <algorithm>

#include <cmath>

using namespace std;

struct Point

{

double x;

double y;

};

Point p1,p2,p3,p4;

const double ERR = 0.000001;

void DealData();

double Direction(Point p1, Point p2, Point p3);

int main()

{

//freopen("input.txt","r",stdin);

int n = 0;

scanf("%d", &n);

printf("INTERSECTING LINES OUTPUT/n");

for (int i = 0; i < n; ++i)

{

scanf("%lf %lf %lf %lf %lf %lf %lf %lf", &p1.x, &p1.y, &p2.x, &p2.y, &p3.x, &p3.y, &p4.x, &p4.y);

DealData();

}

printf("END OF OUTPUT/n");

return 0;

}

/* p1p2 与 p1p3的叉乘 */

double Direction(Point p1, Point p2, Point p3)

{

return (p2.x - p1.x)*(p3.y - p1.y) - (p3.x - p1.x)*(p2.y - p1.y);

}

void DealData()

{

if (fabs(Direction(p1,p2,p3)) <= ERR && fabs(Direction(p1,p2,p4)) <= ERR)

{

printf("LINE/n");

}

else if ((p2.x - p1.x) * (p4.y - p3.y) == (p4.x - p3.x) * (p2.y - p1.y))

{

printf("NONE/n");

}

else

{

double a1 = p1.y - p2.y;

double b1 = p2.x - p1.x;

double c1 = p1.x*p2.y - p2.x*p1.y;

double a2 = p3.y - p4.y;

double b2 = p4.x - p3.x;

double c2 = p3.x*p4.y - p4.x*p3.y;

double x = (b1*c2 - b2*c1)/(a1*b2 - a2*b1);

double y = (a2*c1 - a1*c2)/(a1*b2 - a2*b1);

printf("POINT %.2lf %.2lf/n", x, y);

}

}

#### 【计算几何】 poj1269 Intersecting Lines

2012-08-01 19:25:39

#### poj1269 Intersecting Lines（简单几何，直线平行，共线或相交）

2014-08-14 20:21:00

#### poj1269（两线段的关系，求交点）

2017-02-17 13:56:48

#### [POJ1269]Intersecting Lines（计算几何）

2017-01-01 20:37:06

#### poj1269

2011-08-06 20:50:04

#### POJ 1269(直线的交点)

2012-12-30 12:48:42

#### poj 1269

2016-08-12 17:26:21

#### POJ1269

2012-11-25 22:42:09

#### poj 1269 Intersecting Lines

2016-05-16 21:11:36

#### POJ 1269

2011-08-13 09:39:55

Poj 1269