Q:

(Geometry: points in triangle?) Suppose a right triangle is placed in a plane as shown below. The right-angle point is placed at (0, 0), and the other two points are placed at (200, 0), and (0, 100)

0

(Geometry: points in triangle?) Suppose a right triangle is placed in a plane as shown below. The right-angle point is placed at (0, 0), and the other two points are placed at (200, 0), and (0, 100). 
Write a program that prompts the user to enter a point with x- and y-coordinates and determines whether the point is inside the triangle. Here are the sample runs:

Output:

Enter a point's x- and y-coordinates: 100.5  25.5

The point is in the triangle.

Enter a point's x- and y-coordinates: 100.5  50.5

The point is not in the triangle.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

/*
(Geometry: points in triangle?) Suppose a right triangle is placed in a plane as
shown below. The right-angle point is placed at (0, 0), and the other two points
are placed at (200, 0), and (0, 100). Write a program that prompts the user to enter
a point with x- and y-coordinates and determines whether the point is inside the
triangle. Here are the sample runs:
*/
import java.util.Scanner;

public class Exercise_03_27 {
	public static void main(String[] args) {
		Scanner input = new Scanner(System.in); 	// Create a Scanner object

		// Prompt the user to enter a point with x and y coordinates
		System.out.print("Enter a point's x- and y-coordinates: ");
		double x = input.nextDouble();
		double y = input.nextDouble();

		// Determine whether the point is inside the triangle
		// getting the point of ina line that starts at point 

		// Get the intersecting point with the hypotenuse side of the triangle
		// of a line that starts and points (0, 0) and touches the user points
		double intersectx = (-x * (200 * 100)) / (-y * 200 - x * 100);
		double intersecty = (-y * (200 * 100)) / (-y * 200 - x * 100);

		// Display results
		System.out.println("The point " + ((x > intersectx || y > intersecty)
			? "is not " : "is " ) + "in the triangle");
	}
}

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now