Module org.dyn4j

Class Link

  • All Implemented Interfaces:
    DataContainer, Convex, Rotatable, Shape, Transformable, Translatable, Wound

    public class Link
    extends Segment
    implements Convex, Wound, Shape, Transformable, DataContainer
    This class is a specialization of the Segment class that provides smooth sliding across a chain of line segments. This is achieved by storing the connectivity information between the links. With this, a correction process is performed to avoid the 'internal edge' problem.

    A Link is an infinitely thin line segment and will behave like the Segment class in collision response.

    Like the Segment class, this class can be locally rotated or translated. However, doing so will also translate/rotated the next or previous Links.

    For ease of use, it's recommended to use the Geometry class to create chains of Links.

    Since:
    3.2.2
    Version:
    3.2.2
    Author:
    William Bittle
    • Field Detail

      • previous

        Link previous
        The previous link in the chain
      • next

        Link next
        The next link in the chain
    • Constructor Detail

      • Link

        public Link​(Vector2 point1,
                    Vector2 point2)
        Creates a new link.
        Parameters:
        point1 - the first vertex
        point2 - the last vertex
    • Method Detail

      • getPoint0

        public Vector2 getPoint0()
        Returns the last vertex of the previous segment.
        Returns:
        Vector2
      • getPoint3

        public Vector2 getPoint3()
        Returns the first vertex of the next segment.
        Returns:
        Vector2
      • getNext

        public Link getNext()
        Returns the next link in the chain.
        Returns:
        Link
      • getPrevious

        public Link getPrevious()
        Returns the previous link in the chain.
        Returns:
        Link
      • setNext

        public void setNext​(Link next)
        Sets the next link in the chain.

        This method will also:

        1. Unlink the current next (if applicable) and this link
        2. Link the given next and this link
        Parameters:
        next - the next link
      • setPrevious

        public void setPrevious​(Link previous)
        Sets the previous link in the chain.

        This method will also:

        1. Unlink the current previous (if applicable) and this link
        2. Link the given previous and this link
        Parameters:
        previous - the previous link
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class Segment
      • rotate

        public final void rotate​(double theta,
                                 double x,
                                 double y)
        Description copied from interface: Rotatable
        Rotates the object about the given coordinates.
        Specified by:
        rotate in interface Rotatable
        Overrides:
        rotate in class AbstractShape
        Parameters:
        theta - the angle of rotation in radians
        x - the x coordinate to rotate about
        y - the y coordinate to rotate about
      • translate

        public final void translate​(double x,
                                    double y)
        Description copied from interface: Translatable
        Translates the object the given amounts in the respective directions.
        Specified by:
        translate in interface Translatable
        Overrides:
        translate in class Segment
        Parameters:
        x - the translation in the x direction
        y - the translation in the y direction