Menu
Question Index
...


Write a program to find if the given point lies in a triangle. In the input, the first three points define the triangle and last point is the search point.

Input (Point, Point, Point, Point) Output (boolean)
[0, 0], [10, 30], [20, 0], [10, 15] true
[3, -6], [5, -6], [4.5, -9], [4, -8] true
[5, 5], [-5, 5], [0, 0], [-2, 3] true
[2, 3], [5, 3], [4, 6], [3, 5] false
[0, 0], [10, 30], [20, 0], [30, 15] false

class IsPointInTriangle

{    public static void main(String s[])
    {
        Point firstPoint = new Point(0, 0);
        Point secondPoint = new Point(10, 30);
        Point thirdPoint = new Point(20, 0);
        Point searchPoint = new Point(10, 15);
        System.out.println("Given point lies in the triangle : " + isPointInTriangle(firstPoint, secondPoint, thirdPoint, searchPoint));

    }


public static boolean isPointInTriangle(Point firstPoint, Point secondPoint, Point thirdPoint, Point searchPoint) {
//Write code here to find if the given point is lies in a triangle
}

//If required write any additional methods here
}
class Point {

double x;
double y;

Point(double x, double y) {
this.x = x;
this.y = y;
}
}

Doubts

Problems

Topic: Behavior Of Java Classes Using Methods

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App