JAL-3032 adds Java 8 functionality (2/2)
[jalview.git] / src2 / fr / orsay / lri / varna / models / geom / MiscGeom.java
1 /**
2  * File written by Raphael Champeimont
3  * UMR 7238 Genomique des Microorganismes
4  */
5 package fr.orsay.lri.varna.models.geom;
6
7 import java.awt.geom.Point2D;
8
9
10 /**
11  * @author Raphael Champeimont
12  * Misc geometry functions.
13  */
14 public class MiscGeom {
15
16         /**
17          * Compute the angle made by a vector.
18          */
19         public static double angleFromVector(Point2D.Double v) {
20                 return MiscGeom.angleFromVector(v.x, v.y);
21         }
22
23         public static double angleFromVector(double x, double y) {
24                 double l = Math.hypot(x, y);
25                 if (y > 0) {
26                         return Math.acos(x / l);
27                 } else if (y < 0) {
28                         return - Math.acos(x / l);
29                 } else {
30                         return x > 0 ? 0 : Math.PI;
31                 }
32         }
33
34 }