Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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.

image text in transcribed

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

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

Building The Data Lakehouse

Authors: Bill Inmon ,Mary Levins ,Ranjeet Srivastava

1st Edition

1634629663, 978-1634629669

More Books

Students also viewed these Databases questions