Java Program to Check Orientation of 3 Given Ordered Points

bookmark

import java.util.*;
public class Main
{
   public static void main(String[] args)
   {
       //coordinates declared
      double x1 = 1;
      double y1 = 2;
      double x2 = 3;
      double y2 = 4;
      double x3 = 5;
      double y3 = 6;
        // relation between the slopes of PQ, QR
        double value = (y2 - y1)*(x3 - x2) - (y3 - y2)*(x2 - x1);
        // checking condition for orientation
        if(value == 0)
            System.out.println("Point P,Q,R are co-linear");
        else if(value > 0)
            System.out.println("Point P,Q,R are clockwise");
        else
            System.out.println("Point P,Q,R are counter-clockwise");
   }
}

 


Output:

Point P,Q,R are co-linear