Poj 1269 intersecting lines (calculate the point of intersection of geometric straight lines in parallel on a straight line)

Source: Internet
Author: User
Intersecting lines
Time limit:1000 ms   Memory limit:10000 K
Total submissions:8417   Accepted:3821

Description

We all know that a pair of distinct points on a plane defines a line and that a pair of lines on a plane will intersect in one of three ways: 1) no intersection because they are parallel, 2) intersect in a line because they are on top of one another (I. e. they
Are the same line), 3) intersect in a point. In this problem you will use your algebraic knowledge to create a program that determines how and where two lines intersect.
Your program will repeatedly read in four points that define two lines in the x-y plane and determine how and where the lines intersect. all numbers required by this problem will be reasonable, say between-1000 and 1000.

Input

The first line contains an integer n between 1 and 10 describing how many pairs of lines are represented. the next n lines will each contain eight integers. these integers represent the coordinates of four points on the plane in the order x1y1x2y2x3y3x4y4.
Thus each of these input lines represents two lines on the plane: The line through (x1, Y1) and (X2, Y2) and the line through (X3, Y3) and (X4, y4 ). the point (x1, Y1) is always distinct from (X2, Y2 ). likewise with (X3, Y3) and (X4, Y4 ).

Output

There shoshould be n + 2 lines of output. the first line of output shocould read intersecting lines output. there will then be one line of output for each pair of planar lines represented by a line of input, describing how the lines intersect: None, line, or point.
If the intersection is a point then your program shocould output the X and Y coordinates of the point, correct to two decimal places. The final line of output shocould read "End of output ".

Sample Input

50 0 4 4 0 4 4 05 0 7 6 1 0 2 35 0 7 6 3 -6 4 -32 0 2 27 1 5 18 50 3 4 0 1 2 2 5

Sample output

INTERSECTING LINES OUTPUTPOINT 2.00 2.00NONELINEPOINT 2.00 5.00POINT 1.07 2.20END OF OUTPUT

Source

Mid-Atlantic 1996

This is an introduction to computational ry.

To solve the problem, first determine whether two straight lines are parallel. If they are parallel, then determine whether the two straight lines overlap the output result.

If the intersection of two straight lines is not obtained in parallel, the output result is

Precision requirements

# Include <iostream> # include <stdio. h >#include <algorithm >#include <cmath> using namespace STD; # define EPS 1e-8struct point {Double X; Double Y ;}; struct line {point; point B;}; line line_a, line_ B; bool zero (double A) // determine whether the result is 0 {return FABS (a) <= EPS ;} bool parallel (line & U, line & V) // determine whether the straight line U and straight line V are parallel {return zero (U. a. x-u. B .x) * (v. a. y-v. B .y)-(V. a. x-v. B .x) * (U. a. y-u. B .y);} bool parallel (point & u1, point & U2, point & V1, point & V2) // determine whether the straight line U1 U2 and V1 V2 is parallel {return zero (u1.x-u2.x) * (v1.y-v2.y)-(v1.x-v2.x) * (u1.y-u2.y);} bool dot_in_line (point & A, point & B, point & C) // determine whether point A is online on the BC section {return parallel (B, a, a, c); // determines whether the line segments B A and a C are parallel} point intersection (line & U, line & V) {point ret = u. a; Double T = (U. a. x-v.a.x) * (v. a. y-v. B .y)-(U. a. y-v.a.y) * (v. a. x-v. B .x)/(U. a. x-u. B .x) * (v. a. y-v. B .y)-(U. a. y-u. B .y) * (v. a. x-v. B .x); ret. X + = (U. b. x-u.a.x) * t; ret. Y + = (U. b. y-u.a.y) * t; return ret;} int find_ans () {point P; If (parallel (line_a, line_ B) {If (dot_in_line (line_a.a, line_ B .a, line_ B. B )) {printf ("line \ n"); Return 0;} else {printf ("None \ n"); Return 0 ;}} else {P = intersection (line_a, line_ B); printf ("Point %. 2lf %. 2lf \ n ", p. x, p. y); Return 0;} return 0;} int main () {int I, j, T; scanf ("% d", & T ); printf ("intersecting lines output \ n"); While (t --) {scanf ("% lf ", & line_a.a.x, & line_a.a.y, & line_a. B .x, & line_a. B .y, & line_ B .a.x, & line_ B .a.y, & line_ B. B .x, & line_ B. B .y); find_ans ();} printf ("End of output \ n"); Return 0 ;}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.