Class MathUtils


  • public class MathUtils
    extends Object
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static double EPSILON_D  
      static float EPSILON_F  
    • Constructor Summary

      Constructors 
      Constructor Description
      MathUtils()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static double angleDif​(double a, double b)  
      static double angleDifDeg​(double a, double b)  
      static double clamp​(double d, double min, double max)  
      static float clamp​(float d, float min, float max)  
      static int clamp​(int i, int min, int max)  
      static int gcd​(int a, int b)
      Returns the greatest common divisor of a and b (e.g.
      static boolean isFuzzyEqual​(double a, double b)  
      static boolean isFuzzyEqual​(double a, double b, double epsilon)  
      static boolean isFuzzyEqual​(float a, float b)  
      static boolean isFuzzyEqual​(float a, float b, float epsilon)  
      static boolean isFuzzyZero​(double a)  
      static boolean isFuzzyZero​(float a)  
      static double max​(double a, double b, double c)  
      static float max​(float a, float b, float c)  
      static double min​(double a, double b, double c)  
      static float min​(float a, float b, float c)  
      static double normalizeDegree​(double deg)  
      static boolean pnpoly​(int nvert, float[] vertx, float[] verty, float testx, float testy)
      Point Inclusion in Polygon Test.
      static double wrapAnglePiPi​(double a)  
      static float wrapAnglePiPi​(float a)  
    • Constructor Detail

      • MathUtils

        public MathUtils()
    • Method Detail

      • isFuzzyZero

        public static boolean isFuzzyZero​(float a)
      • isFuzzyZero

        public static boolean isFuzzyZero​(double a)
      • isFuzzyEqual

        public static boolean isFuzzyEqual​(float a,
                                           float b)
      • isFuzzyEqual

        public static boolean isFuzzyEqual​(float a,
                                           float b,
                                           float epsilon)
      • isFuzzyEqual

        public static boolean isFuzzyEqual​(double a,
                                           double b)
      • isFuzzyEqual

        public static boolean isFuzzyEqual​(double a,
                                           double b,
                                           double epsilon)
      • clamp

        public static float clamp​(float d,
                                  float min,
                                  float max)
      • clamp

        public static double clamp​(double d,
                                   double min,
                                   double max)
      • clamp

        public static int clamp​(int i,
                                int min,
                                int max)
      • wrapAnglePiPi

        public static float wrapAnglePiPi​(float a)
      • wrapAnglePiPi

        public static double wrapAnglePiPi​(double a)
      • angleDif

        public static double angleDif​(double a,
                                      double b)
      • angleDifDeg

        public static double angleDifDeg​(double a,
                                         double b)
      • normalizeDegree

        public static double normalizeDegree​(double deg)
      • max

        public static float max​(float a,
                                float b,
                                float c)
      • min

        public static float min​(float a,
                                float b,
                                float c)
      • max

        public static double max​(double a,
                                 double b,
                                 double c)
      • min

        public static double min​(double a,
                                 double b,
                                 double c)
      • gcd

        public static int gcd​(int a,
                              int b)
        Returns the greatest common divisor of a and b (e.g. gcd(12, 18) = 6)
        Parameters:
        a - first number
        b - second number
        Returns:
        greatest common divisor of a and b.
      • pnpoly

        public static boolean pnpoly​(int nvert,
                                     float[] vertx,
                                     float[] verty,
                                     float testx,
                                     float testy)
        Point Inclusion in Polygon Test. Defines if a points lies within a polygon
        Parameters:
        nvert - Number of vertices in the polygon. Whether to repeat the first vertex at the end is discussed below.
        vertx - Array containing the x-coordinates of the polygon's vertices.
        verty - Array containing the y-coordinates of the polygon's vertices.
        testx - X-coordinate of the test point.
        testy - Y-coordinate of the test point.
        Returns:
        true if point lies within the polygon, false otherwise