Question: Computer Graphics (Java) (Java Applet Please) Write a program that for four points A, B, C and P, which: - Draws a TRIANGLE formed by

Computer Graphics (Java) (Java Applet Please)

Write a program that for four points A, B, C and P, which:

- Draws a TRIANGLE formed by ABC and a small cross showing the position of P

- Displays a line of text indicating which of the following three cases applies: inside ABC, outside ABC, or on an edge of ABC.

- Displays the computed distance of P to the (infinite) lines AB, BC and CA, and draws the shortest possible line that connects P with the nearest of those three lines.

The user will specify the four points by clicking!!!!

Picture for how it should look in the case P is inside ABC. Triangle ABC, point P is the crosshairs inside ABC so once it should display a line of text "Inside ABC", as well as display the distance between P to lines AB, BC and CA and draws the shortest line possible that connects P to the nearest of the three lines.

Computer Graphics (Java) (Java Applet Please) Write a program that for four

Example Tools that can be edited on which may be helpful in implementation:

// Tools2D.java: Class to be used in other program files. // Uses: Point2D (Section 1.5).

class Tools2D { static float area2(Point2D a, Point2D b, Point2D c) { return (a.x - c.x) * (b.y - c.y) - (a.y - c.y) * (b.x - c.x); } static float distance2(Point2D p, Point2D q) { float dx = p.x - q.x, dy = p.y - q.y; return dx * dx + dy * dy; }

static boolean insideTriangle(Point2D a, Point2D b, Point2D c, Point2D p){ // ABC is assumed to be counter-clockwise return area2(a, b, p) >= 0 && area2(b, c, p) >= 0 && area2(c, a, p) >= 0; } /* static boolean intersect(Point2D a, Point2D b, Point2D p, Point2D q){ // Do P and Q lie on the different sides of the line through // A and B, while A and B lie on the different sides of the // line through P and Q? return area2(a, b, p) * area2(a, b, q)

Please take screenshots of the output. Thank you.

X X

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!