calculate for checking whether the 3 points is upon on line - Java 2D Graphics

Java examples for 2D Graphics:Line

Description

calculate for checking whether the 3 points is upon on line

Demo Code


//package com.java2s;

public class Main {
    public static void main(String[] argv) throws Exception {
        double x0 = 2.45678;
        double y0 = 2.45678;
        double x1 = 2.45678;
        double y1 = 2.45678;
        double x = 2.45678;
        double y = 2.45678;
        System.out.println(dot(x0, y0, x1, y1, x, y));
    }/*from   w  w w . j  ava  2 s  . co m*/

    /**
     * calculate for checking whether the 3 points is upon on line 
     * @param  x0  double  start point's coordinate x
     * @param  y0  double  start point's coordinate y
     * @param  x1  double  target point's coordinate x
     * @param  y1  double  target point's coordinate y
     * @param  x  double  checking point's coordinate x
     * @param  y  double  checking point's coordinate y
     * @return  double
     * */
    private static double dot(double x0, double y0, double x1, double y1,
            double x, double y) {
        return (x - x0) * (x1 - x0) + (y - y0) * (y1 - y0);
    }
}

Related Tutorials