Parallelogram


abstract class Parallelogram

Known direct subclasses
ImmutableParallelogram

Immutable parallelogram (i.e. a quadrilateral with parallel sides), defined by its center, width, height, rotation, and shearFactor.

MutableParallelogram

Mutable parallelogram (i.e. a quadrilateral with parallel sides), defined by its center, width, height, rotation, and shearFactor.


This class represents a parallelogram (i.e. a quadrilateral with parallel sides), defined by its center, width, height, rotation, and shearFactor.

Parameters of a Parallelogram are used to define a pair of vector semi-axes:

u = {.5 * w * cos(θ), .5 * w * sin(θ)}
v = {.5 * h * (s * cos(θ) - sin(θ)), .5 * h * (s * sin(θ) + cos(θ))}

where w is the width, h is the height, s is the shearFactor and θ is the angle of rotation. From the semi-axes, we define the shape of the parallelogram as the set of all points c + 𝛼 * u + 𝛽 * v, where c is the center, and 𝛼 and 𝛽 are real numbers in the interval -1, 1.

Note: Java code should use the factory function Parallelogram.from*.

A Parallelogram may have a positive or negative height; a positive height indicates that the angle from the first semi-axis to the second will also be positive.

A Parallelogram may have a positive or negative shear factor; a positive shear factor indicates a smaller absolute angle between the semi-axes (the shear factor is, in fact, the cotangent of that angle).

A Parallelogram may not have a negative width. If an operation on a parallelogram or the construction of a parallelogram would result in a negative width, it is instead normalized, by negating both the width and the height, adding π to the angle of rotation, and normalizing rotation to the range [0, 2π).

A Parallelogram may also be degenerate; that is, its width or height, or both, may be zero. Degenerate Parallelograms may still have a non-zero rotation and/or shearFactor. A Parallelogram that has both width and height of zero is effectively a point, and so rotation and shearFactor do not affect the values of the axes or corners. A Parallelogram that has either width or height of zero (but not both) is effectively a line segment, and so is similarly unaffected by shearFactor.

More intuitively, you can think of the shape of the Parallelogram, before taking the center and rotation into account, like this:

         s*h
|------|__________
/ /
/ /
/ /
h / /
/ /
/ /
/_________/
|---------|
w

Where w is the width, h is the height, and s is the shearFactor. You then rotate, and translate such that the center is in the correct position.

A few geometric objects can be represented as special cases of a Parallelogram. A generic rectangle is a Parallelogram with shearFactor of zero. (It can be rotated with respect to the axes, and hence might have a non-zero rotation). A Box, an axis-aligned rectangle; is a Parallelogram with both rotation and shearFactor of zero.

Summary

Public functions

Float

Returns the signed area of the Parallelogram.

Public properties

abstract Vec
abstract Float

A Parallelogram may have a positive or negative height; a positive height indicates that the angle from the first semi-axis to the second will also be positive.

abstract Float
abstract Float

A Parallelogram] may have a positive or negative shear factor; a positive shear factor indicates a smaller absolute angle between the semi-axes (the shear factor is, in fact, the cotangent of that angle).

abstract Float

A Parallelogram may not have a negative width.

Public functions

computeSignedArea

Added in 1.0.0-alpha01
fun computeSignedArea(): Float

Returns the signed area of the Parallelogram. If either the width or the height is zero, this will be equal to zero; if the width is non-zero, then this will have the same sign as the height.

Public properties

center

Added in 1.0.0-alpha01
abstract val centerVec

height

Added in 1.0.0-alpha01
abstract val heightFloat

A Parallelogram may have a positive or negative height; a positive height indicates that the angle from the first semi-axis to the second will also be positive.

rotation

Added in 1.0.0-alpha01
abstract val rotationFloat

shearFactor

Added in 1.0.0-alpha01
abstract val shearFactorFloat

A Parallelogram] may have a positive or negative shear factor; a positive shear factor indicates a smaller absolute angle between the semi-axes (the shear factor is, in fact, the cotangent of that angle).

width

Added in 1.0.0-alpha01
abstract val widthFloat

A Parallelogram may not have a negative width. If an operation on a parallelogram would result in a negative width, it is instead normalized, by negating both the width and the height, adding π to the angle of rotation, and normalizing rotation to the range [0, 2π).