Here you can find the source of angle(Point2D.Double vec)
Math.atan
method.
Parameter | Description |
---|---|
vec | the vector |
Math.atan
public static double angle(Point2D.Double vec)
//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); } }