Find the Area of a Triangle Using coordinates

Objective – Given three vertices coordinates or (X, Y) coordinates, write a program to find the area of a triangle.

Example:

Approach:

Given the coordinates of the three vertices of any triangle are (X1, Y1), (X2, Y2) and (X3, Y3)

Java Code:

This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.

 public class AreaOfTriangleCoordinates { public static void printArea(double [] X, double [] Y){ //find area of triangle double area = Math.abs(X[0]*(Y[1]-Y[2]) + X[1]*(Y[2]-Y[0]) + X[2]*(Y[0]-Y[1]))/2; System.out.println("Area of Triangle: " + area); } public static void main(String[] args) { double [] x_coordinates = {1,2,5}; double [] y_coordinates = {0, 6, 10}; printArea(x_coordinates, y_coordinates); } }

Output:

```Area of Triangle: 7.0
```

1 thought on “Find the Area of a Triangle Using coordinates”

1. The formula in the approach is wrong.