Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- double x1, y1, x2, y2, x3, y3, x4, y4, a1, b1, c1, a2, b2, c2, x, y;
- double fk(int x1,int y1,int x2,int y2)
- {
- double k=(y1-y2)/(x1-x2);
- return k;
- }
- double fb(double k, int y1, int x1)
- {
- double b=y1-k*x1;
- return b;
- }
- double findx(double k1, double k2,double b1,double b2)
- {
- double x=(b2-b1)/(k1-k2);
- return x;
- }
- double findy(double x,int y1)
- {
- double y=x*y1;
- }
- double fa(double y1,double y2)
- {
- return y1-y2;
- }
- double fb(double x1,double x2)
- {
- return x2-x1;
- }
- double fc(double x1,double x2,double y1,double y2)
- {
- return x1 * y2 - x2 * y1;
- }
- int main()
- { cout.precision(15);
- cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3 >> x4 >> y4;
- a1 = fa(y1,y2);
- b1 = fb(x1,x2);
- c1 = fc(x1,x2,y1,y2);
- a2 = fa(y3,y4);
- b2 = fb(x3,x4);
- c2 =fc(x3,y3,x4,y4);
- if(a1 * b2 - a2 * b1 == 0)
- {
- if(a1 * c2 - a2 * c1 == 0 && b1 * c2 - b2 * c1 == 0 )
- {
- cout << 2 << '\n';
- }
- else
- {
- cout << 0 << '\n';
- }
- }
- else
- {
- x = (((c1 * b2) - (c2 * b1)) / ((a1 * b2) - (a2 * b1)));
- y = (((a1 * c2) -(a2 * c1)) / ((a1 * b2) - (a2 * b1)));
- x *= -1;
- y *= -1;
- if(a1 == a2 && b1 == b2 && c1 == c2)
- {
- cout << 2 << '\n';
- }
- else
- {
- cout << fixed << 1 << " " << x << " " << y << '\n';
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement