Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hello Experts! Please answer the following question for me as I am having problems with it. I'd like to see other solutions that could clarify

Hello Experts! Please answer the following question for me as I am having problems with it. I'd like to see other solutions that could clarify the problem for me. I keep getting a NaN when performing the computation for the coordinates. I got 5/8 of the test cases correct but I can't seem to get the rest for some reason. Will upvote! Thanks!

in programming language C please

image text in transcribed

(2) Intersection Test In many areas of science (e.g., computer graphics, computational geometry, image analysis, robotics, physics), it is often necessary to determine whether or not two line segments intersect. Assume that we have two 2D line segments one line segment has endpoints (Ax,Ay) and (Bx,By) and the other segment has endpoints (Cx,Cy) and (Dx,Dy). Write a C program called intersectionTester that asks the user for the eight values of the integer coordinates for two line segments and then displays a message indicating whether or not the line segments intersect. Assume that all coordinates are entered as integer values. Here are some examples: (Ax, Ay)(Ck, Cy) (2,17) (3,17) (7, 19) (Bx, By) 15, 10) (8, 10) (15, 10) 7, 10) (15, 10) (Dx, Dy) (3, 6) (3, 6) (3, 6) (4, 18) (3, 17) (2,17) (, 17) (12, 17 (18, 17) (15, 18) (15, 14) (4, 14) (1,10 (15, 10) (2,10) (7,10) (12, 10) (18, 10) (4, 6) (15, 6) (15, 4) (3, 6) (4, 3) In your code, you should write a function called calculate() that takes all 8 integer parameters and returns 1 if the line segments intersect and 0 otherwise. To determine intersection, you will need to handle vertical and horizontal lines as special cases. Otherwise, you can use the following equations to determine whether or not the line segments intersect t - (Ax-Cx) (Cy-Dy) - (Ay-Cy) (Cx-Dx) (Ax-Bx)(Cy-Dy) (Ay-By) (Cx-Dx) u (Bx-Ax) (Ay-Cy)(Ay-By) (Ax-Cx) (Ax-Bx) (Cy-Dy) (Ay-By) (Cx-Dx) When using the above equations, if O St1 and 0S u1 then the line segments intersect. This extra check ensures that the intersection of the two lines actually lies on the segments. In your main function, you may hard code some calls to calculate() with the coordinates for the 8 examples in the image above. Make sure that they all give the correct answer. Your output must be in this format (color added for highlighting purposes only): Line segments 2,17)-(15,10) and 7, 19-3,6) intersect Line segments 2,17)-(15,10) and , 10)-3,6) do not intersect Line segments 3,17)-3, 6) and 7, 10)->(15,10) do not intersect Line segments 4,18)-4,14) and 4, 6)->4, 3) do not intersect Line segments (15,18)-> (15, 6) and (15, 14)->(15, 4) intersect Line segments 3,17)-3, 6) and 1, 10)->(15,10) intersect Line segments 2,17)-(12,17) and 7, 17)->(18,17) intersect. Line segments 2,10)-7,10) and (12, 10)-> (18,10) do not intersect

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2017 Skopje Macedonia September 18 22 2017 Proceedings Part 3 Lnai 10536

Authors: Yasemin Altun ,Kamalika Das ,Taneli Mielikainen ,Donato Malerba ,Jerzy Stefanowski ,Jesse Read ,Marinka Zitnik ,Michelangelo Ceci ,Saso Dzeroski

1st Edition

3319712721, 978-3319712727

More Books

Students also viewed these Databases questions