Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please use C to answer the question, thank you. (2) Intersection Test In many areas of science (e.g., computer graphics, computational geometry, image analysis, robotics

Please use C to answer the question, thank you.

image text in transcribedimage 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 (2,17)(c, Cy)- Ex, Cy 19 (2, 17) (3, 17) (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) (7,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 0 Sts1 and 0uS1 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 8, 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. (3) Histogram Generation Write a program called histogram.c that creates an array of 100 randomly-generated char values ranging from 0 to 9. The program should then display a histogram showing (as a string of4 characters) the number of times that a certain number was generated. The histogram should have a format like the one shown here (although results will vary each time that you run it) ->10** 121 Note that there will always be 100 * characters shown. Also, the numbers on the left/vertical axis will vary depending on the random distribution. Therefore, the height of the histogram will vary. The width will always be the same, with the same horizontal axis 9* 8 7 61 5* 41 31 21 In your code, you MUST ensure that the random numbers are different each time that you run your program. Also, your code must have three stages to it: (1) generate the random numbers into one array, (2) create the histogram in a different array, (3) display the histogram. 01 23 4567 8 9

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

Step: 3

blur-text-image

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

Relational Database Design A Practical Approach

Authors: Marilyn Campbell

1st Edition

1587193175, 978-1587193170

More Books

Students also viewed these Databases questions