Hi,

This is how I do it:

    /**
     * @param a_Point2D
     * @param b_Point2D
     * @param c_Point2D
     * @return The inside Angle at b_Point for a Linear Ring assuming the ring
     * is clockwise and the Linear Ring Sequence is a_Point, b_Point, c_Point.
     */
    public static double getInsideAngleClockwise(
            Point2D a_Point2D,
            Point2D b_Point2D,
            Point2D c_Point2D) {
        double angle_aby = (Math.PI * 2.0d) - a_Point2D.getAngle(b_Point2D);
        //double angle_aby_deg = getRadToDeg(angle_aby);
        double angle_bcy = Math.PI - b_Point2D.getAngle(c_Point2D);
        //double angle_bcy_deg = getRadToDeg(angle_bcy);
        double result = angle_bcy - angle_aby;
        if (result < 0) {
            result = (Math.PI * 2.0d) + result;
        }
        //double result_deg = getRadToDeg(result);
        return result;
    }

Here is the getAngle(Point2D) method in my Point2D class:

    /**
     * Imprecise
     * @param a_Point2D
     * @return Angle to the y axis clockwise. Default 0.0d.
     */
    public double getAngle(Point2D a_Point2D) {
        double dx = a_Point2D._x.doubleValue() - _x.doubleValue();
        double dy = a_Point2D._y.doubleValue() - _y.doubleValue();
        if (dy == 0.0d) {
            if (dx == 0.0d) {
                return 0.0d;
            } else {
                if (dx > 0.0d) {
                    return Math.PI / 2.0d;
                } else {
                    return (3.0d * Math.PI) / 2.0d;
                }
            }
        } else {
            if (dy > 0.0d) {
                if (dx == 0.0d) {
                    return 0.0d;
                } else {
                    if (dx > 0.0d) {
                        return Math.atan(dx / dy);
                    } else {
                        return (2.0d * Math.PI) - Math.atan(Math.abs(dx) / dy);
                    }
                }
            } else {
                // dy < 0.0d
                if (dx == 0.0d) {
                    return Math.PI;
                } else {
                    if (dx > 0.0d) {
                        return Math.PI - Math.atan(dx / Math.abs(dy));
                    } else {
                        return Math.PI + Math.atan(Math.abs(dx) / Math.abs(dy));
                    }
                }
            }
        }
    }

BTW I'm working to improving precision and provide arbitrary fixed decimal 
precision for these kinds of methods in my vector code (which is all open 
source). Basically I use BigDecimal for each coordinate and the methods will 
return a BigDecimal. The methods will also input an integer scale value which 
will specif the number of decimal places for which the returned result must be 
accurate.

Best wishes,

Andy
http://www.geog.leeds.ac.uk/people/a.turner/
 
-----Original Message-----
From: Pyro14 [mailto:[email protected]] 
Sent: 10 April 2010 17:45
To: [email protected]
Subject: [Geotools-gt2-users] Angle between 3 points


Hi all,

can anybody tell me how to calculate the angle between 3 points?

Thx Pyro
-- 
View this message in context: 
http://n2.nabble.com/Angle-between-3-points-tp4882609p4882609.html
Sent from the geotools-gt2-users mailing list archive at Nabble.com.

------------------------------------------------------------------------------
_______________________________________________
Geotools-gt2-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users

------------------------------------------------------------------------------
_______________________________________________
Geotools-gt2-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users

Reply via email to