Class Points


  • public abstract class Points
    extends java.lang.Object
    A collection of utilities to assist with point manipulation.
    Author:
    Dimitrios Michail
    • Constructor Detail

      • Points

        public Points()
    • Method Detail

      • length

        public static double length​(Point2D v)
        Compute the length of a vector. The length of vector $(x,y)$ is given by $\sqrt{x^2+y^2}$.
        Parameters:
        v - the vector
        Returns:
        the length of a vector
      • add

        public static Point2D add​(Point2D a,
                                  Point2D b)
        Add 2-dimensional vectors
        Parameters:
        a - the first vector
        b - the second vector
        Returns:
        the vector $a+b$
      • subtract

        public static Point2D subtract​(Point2D a,
                                       Point2D b)
        Subtract 2-dimensional vectors
        Parameters:
        a - the first vector
        b - the second vector
        Returns:
        the vector $a-b$
      • negate

        public static Point2D negate​(Point2D a)
        Given a vector $a$ compute $-a$.
        Parameters:
        a - the vector
        Returns:
        the vector $-a$
      • scalarMultiply

        public static Point2D scalarMultiply​(Point2D a,
                                             double scalar)
        Multiply a vector with a scalar.
        Parameters:
        a - the vector
        scalar - the scalar
        Returns:
        the result of scalar multiplication
      • scalarMultiply

        public static <S> Point2D scalarMultiply​(Point2D a,
                                                 S scalar,
                                                 java.util.function.BiFunction<java.lang.Double,​S,​java.lang.Double> mult)
        Multiply a vector with a scalar.
        Type Parameters:
        S - the scalar type
        Parameters:
        a - the vector
        scalar - the scalar
        mult - the multiplication operator
        Returns:
        the result of scalar multiplication
      • equals

        public static boolean equals​(Point2D p1,
                                     Point2D p2)
        Compare two points for equality using tolerance 1e-9.
        Parameters:
        p1 - the first point
        p2 - the second point
        Returns:
        whether the two points are equal or not