Java Angle Calculate angle(Point2D.Double vec)

Here you can find the source of angle(Point2D.Double vec)

Description

Computes "angle" of a vector using the Math.atan method.

License

Apache License

Parameter

Parameter Description
vec the vector

Return

angle in the range of -pi to pi, as computed by Math.atan

Declaration

public static double angle(Point2D.Double vec) 

Method Source Code


//package com.java2s;
/*// w  w w .j  a  v a 2 s . com
 * #%L
 * BlaiseMath
 * --
 * Copyright (C) 2009 - 2015 Elisha Peterson
 * --
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * #L%
 */

import java.awt.geom.Point2D;
import static java.lang.Math.*;

public class Main {
    /**
     * Computes "angle" of a vector using the <code>Math.atan</code> method.
     * @param vec the vector
     * @return angle in the range of -pi to pi, as computed by <code>Math.atan</code>
     */
    public static double angle(Point2D.Double vec) {
        if (Double.isInfinite(vec.x)) {
            return vec.y > PI ? vec.y - 2 * PI : vec.y;
        }
        return atan2(vec.y, vec.x);
    }

    /**
     * Determines whether provided point is infinite.
     * @param point point to check
     * @return <code>true</code> if this represents an infinite point.
     */
    public static boolean isInfinite(Point2D.Double point) {
        return Double.isInfinite(point.x);
    }
}

Related

  1. angle(Point2D from, Point2D to)
  2. angle2D(Point p1, Point p2)
  3. angleBetween(Point2D.Double vec1, Point2D.Double vec2)
  4. angleOf(Point2D a, Point2D b)
  5. anglePI(Point2D top, Point2D corner1, Point2D corner2)