Compute angle into image system basis where positive angle are defined in a ClockWise orientation - Java 2D Graphics

Java examples for 2D Graphics:Image

Description

Compute angle into image system basis where positive angle are defined in a ClockWise orientation

Demo Code


//package com.java2s;

import java.awt.geom.Point2D;

public class Main {
    /**/*from  www .j  a  v a  2  s.c om*/
     * @return angle between BA & BC line segment in Degree <br>
     *         0 is returned if any argument is invalid
     */
    public static double getAngleRad(Point2D ptA, Point2D ptB, Point2D ptC) {
        if (ptA != null && ptB != null && ptC != null) {
            return getAngleRad(ptB, ptC) - getAngleRad(ptB, ptA);
        }
        return 0;
    }

    /**
     * Compute angle into image system basis where positive angle are defined in a ClockWise orientation<br>
     * Note : angle should be computed with "Math.atan2(ptB.getY() - ptA.getY(), ptB.getX() - ptA.getX())" in an
     * ortho-normal basis system where positive angle is defined in a CounterClockWise orientation.
     * 
     * @return angle of AB line segment in radiant<br>
     *         0 is returned if any argument is invalid
     */

    public static double getAngleRad(Point2D ptA, Point2D ptB) {
        return (ptA != null && ptB != null) ? Math.atan2(
                ptA.getY() - ptB.getY(), ptB.getX() - ptA.getX()) : null;
    }
}

Related Tutorials