Module org.dyn4j

Class Ray


  • public class Ray
    extends java.lang.Object
    Implementation of a ray.

    A ray is a vector with a start point.

    Since:
    2.0.0
    Version:
    3.4.0
    Author:
    William Bittle
    • Constructor Summary

      Constructors 
      Constructor Description
      Ray​(double direction)
      Creates a ray from the origin in the given direction.
      Ray​(Vector2 direction)
      Creates a ray from the origin in the given direction.
      Ray​(Vector2 start, double direction)
      Creates a ray from the given start point in the given direction.
      Ray​(Vector2 start, Vector2 direction)
      Creates a ray from the given start point in the given direction.
    • Field Detail

      • start

        protected Vector2 start
        The start point
      • direction

        protected Vector2 direction
        The direction
    • Constructor Detail

      • Ray

        public Ray​(double direction)
        Creates a ray from the origin in the given direction.
        Parameters:
        direction - the direction in radians
        Since:
        3.0.2
      • Ray

        public Ray​(Vector2 direction)
        Creates a ray from the origin in the given direction.
        Parameters:
        direction - the direction
      • Ray

        public Ray​(Vector2 start,
                   double direction)
        Creates a ray from the given start point in the given direction.
        Parameters:
        start - the start point
        direction - the direction in radians
        Since:
        3.0.2
      • Ray

        public Ray​(Vector2 start,
                   Vector2 direction)
        Creates a ray from the given start point in the given direction.
        Parameters:
        start - the start point
        direction - the direction
        Throws:
        java.lang.NullPointerException - if start or direction is null
        java.lang.IllegalArgumentException - if direction is the zero vector
    • Method Detail

      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • getStart

        public Vector2 getStart()
        Returns the start point.
        Returns:
        Vector2
      • setStart

        public void setStart​(Vector2 start)
        Sets the start point.
        Parameters:
        start - the start point
        Throws:
        java.lang.NullPointerException - if start is null
      • setDirection

        public void setDirection​(double direction)
        Sets the direction of this ray in radians.
        Parameters:
        direction - the direction in radians
        Since:
        3.0.2
      • getDirection

        public double getDirection()
        Returns the direction of this ray in radians.
        Returns:
        double the direction in radians between [-π, π]
        Since:
        3.0.2
      • setDirection

        public void setDirection​(Vector2 direction)
        Sets the direction.
        Parameters:
        direction - the direction; should be normalized
        Throws:
        java.lang.NullPointerException - if direction is null
        java.lang.IllegalArgumentException - if direction is the zero vector
      • getDirectionVector

        public Vector2 getDirectionVector()
        Returns the direction.
        Returns:
        Vector2
        Since:
        3.0.2