Module org.dyn4j

Class Rectangle

    • Field Detail

      • width

        final double width
        The Rectangle's width
      • height

        final double height
        The Rectangle's height
    • Constructor Detail

      • Rectangle

        public Rectangle​(double width,
                         double height)
        Full constructor.

        The center of the rectangle will be the origin.

        A rectangle must have a width and height greater than zero.

        Parameters:
        width - the width
        height - the height
        Throws:
        java.lang.IllegalArgumentException - if width or height is less than or equal to zero
    • Method Detail

      • toString

        public java.lang.String toString()
        Overrides:
        toString in class Polygon
      • getHeight

        public double getHeight()
        Returns the height.
        Returns:
        double
      • getWidth

        public double getWidth()
        Returns the width.
        Returns:
        double
      • getRotationAngle

        public double getRotationAngle()
        Returns the rotation about the local center in radians in the range [-π, π].
        Returns:
        double the rotation in radians
        Since:
        3.0.1
      • getRotation

        public Rotation getRotation()
        Returns:
        the Rotation object that represents the local rotation
      • getAxes

        public Vector2[] getAxes​(Vector2[] foci,
                                 Transform transform)
        Description copied from interface: Convex
        Returns an array of separating axes to test for this Shape.

        The foci parameter is an array of circular focal points of the other Shape.

        If foci points are given, this method will return the separating axes for this Shape's voronoi regions also. The points in the foci array are assumed to be in world space.

        The returned axes are normalized and in world space.

        Specified by:
        getAxes in interface Convex
        Overrides:
        getAxes in class Polygon
        Parameters:
        foci - the world space points representing foci of curved Shapes; can be null
        transform - the local to world space Transform of this Convex Shape
        Returns:
        Vector2[]
      • contains

        public boolean contains​(Vector2 point,
                                Transform transform)
        Description copied from interface: Shape
        Returns true if the given point is inside this Shape.

        If the given point lies on an edge the point is considered to be inside the Shape.

        The given point is assumed to be in world space.

        Specified by:
        contains in interface Shape
        Overrides:
        contains in class Polygon
        Parameters:
        point - world space point
        transform - Transform for this Shape
        Returns:
        boolean
      • createMass

        public Mass createMass​(double density)
        Creates a Mass object using the geometric properties of this Rectangle and the given density.

        m = d * h * w I = m * (h2 + w2) / 12

        Specified by:
        createMass in interface Shape
        Overrides:
        createMass in class Polygon
        Parameters:
        density - the density in kg/m2
        Returns:
        Mass the Mass of this Rectangle