public final class PGS_Transformation extends Object
Notably, these transformation methods affect the vertex coordinates of PShapes, unlike Processing's transform methods that affect the affine matrix of shapes only (and thereby leave vertex coordinates in-tact).
Modifier and Type | Method and Description |
---|---|
static processing.core.PShape |
align(processing.core.PShape sourceShape,
processing.core.PShape transformShape)
Aligns one polygon shape to another, using Procrustes analysis to find the
optimal transformation.
|
static processing.core.PShape |
align(processing.core.PShape alignShape,
processing.core.PShape baseShape,
double alignmentRatio)
Aligns one polygon shape to another, using Procrustes analysis to find the
optimal transformation.
|
static processing.core.PShape |
flipHorizontal(processing.core.PShape shape)
Flips the shape horizontally based on its centre point.
|
static processing.core.PShape |
flipHorizontal(processing.core.PShape shape,
double y)
Flips the shape horizontally based on a line given by its Y location.
|
static processing.core.PShape |
flipVertical(processing.core.PShape shape)
Flips the shape vertically based on its centre point.
|
static processing.core.PShape |
flipVertical(processing.core.PShape shape,
double x)
Flips the shape vertically based on a line given by its X location.
|
static processing.core.PShape |
homotheticTransformation(processing.core.PShape shape,
processing.core.PVector center,
double scaleX,
double scaleY)
Calculates a Homothetic Transformation of a shape.
|
static processing.core.PShape |
originScale(processing.core.PShape shape,
double scale)
Scales a shape relative to the origin (0,0).
|
static processing.core.PShape |
resize(processing.core.PShape shape,
double targetWidth,
double targetHeight)
Resizes a shape (based on its envelope) to the given dimensions, relative to
its center point.
|
static processing.core.PShape |
resizeByHeight(processing.core.PShape shape,
double targetHeight)
Resizes a shape (based on its envelope) to the given height relative to its
center point; the width is resized accordingly to maintain the shape's aspect
ratio.
|
static processing.core.PShape |
resizeByMajorAxis(processing.core.PShape shape,
double targetSize)
Resizes a shape (based on the longest axis of its envelope) to the given size
relative to its center point.
|
static processing.core.PShape |
resizeByWidth(processing.core.PShape shape,
double targetWidth)
Resizes a shape (based on its envelope) to the given width relative to its
center point; the height is resized accordingly to maintain the shape's
aspect ratio.
|
static processing.core.PShape |
rotate(processing.core.PShape shape,
processing.core.PVector point,
double angle)
Rotates a shape around a given point.
|
static processing.core.PShape |
rotateAroundCenter(processing.core.PShape shape,
double angle)
Rotates a shape around its centroid.
|
static processing.core.PShape |
scale(processing.core.PShape shape,
double scale)
Scales the dimensions of the shape by a scaling factor relative to its center
point.
|
static processing.core.PShape |
scale(processing.core.PShape shape,
double scaleX,
double scaleY)
Scales the shape relative to its center point.
|
static processing.core.PShape |
scaleArea(processing.core.PShape shape,
double scale)
Scales the area of a given shape by a specified scale factor.
|
static processing.core.PShape |
scaleAreaTo(processing.core.PShape shape,
double targetArea)
Scales the given PShape to the target area, relative to its center point.
|
static processing.core.PShape |
shear(processing.core.PShape shape,
double angleX,
double angleY)
Shears a given shape by specified angles along the x and y axis and returns
the result as a new PShape.
|
static processing.core.PShape |
touchScale(processing.core.PShape shape,
processing.core.PShape boundary,
double tolerance)
Scales a shape (based on its centroid) so that it touches the boundary of
another shape.
|
static processing.core.PShape |
translate(processing.core.PShape shape,
double x,
double y)
Translates a shape by the given coordinates.
|
static processing.core.PShape |
translateCentroidTo(processing.core.PShape shape,
double x,
double y)
Translates a shape such that its centroid aligns with the specified
(x, y) coordinates.
|
static processing.core.PShape |
translateCornerTo(processing.core.PShape shape,
double x,
double y)
Translates the given shape such that the upper-left corner of its bounding
box aligns with the specified (x, y) coordinates.
|
static processing.core.PShape |
translateEnvelopeTo(processing.core.PShape shape,
double x,
double y)
Translates a shape such that the centroid of its bounding box
is equivalent to the given coordinates.
|
static processing.core.PShape |
translateTo(processing.core.PShape shape,
double x,
double y)
Deprecated.
Use
translateCentroidTo() instead. |
static processing.core.PShape |
translateToOrigin(processing.core.PShape shape)
Translates the given shape such that the upper-left corner of its bounding
box aligns with the origin point (0, 0) of the Processing coordinate system.
|
public static processing.core.PShape scale(processing.core.PShape shape, double scale)
shape
- scale
- X and Y axis scale factorpublic static processing.core.PShape scale(processing.core.PShape shape, double scaleX, double scaleY)
shape
- scaleX
- X-axis scale factorscaleY
- Y-axis scale factorpublic static processing.core.PShape originScale(processing.core.PShape shape, double scale)
shape
- scale
- scale factorpublic static processing.core.PShape scaleArea(processing.core.PShape shape, double scale)
shape
- The PShape to be scaled.scale
- The scale factor by which the area of the shape should be
scaled.public static processing.core.PShape scaleAreaTo(processing.core.PShape shape, double targetArea)
shape
- The PShape to be scaled.targetArea
- The target area for the shape.targetArea
).public static processing.core.PShape resize(processing.core.PShape shape, double targetWidth, double targetHeight)
shape
- targetWidth
- width of the output copytargetHeight
- height of the output copypublic static processing.core.PShape resizeByWidth(processing.core.PShape shape, double targetWidth)
shape
- the shape to resizetargetWidth
- width of the outputresizeByHeight(PShape, double)
,
#resizeByLargest(PShape, double)
public static processing.core.PShape resizeByHeight(processing.core.PShape shape, double targetHeight)
shape
- the shape to resizetargetHeight
- height of the outputresizeByWidth(PShape, double)
,
#resizeByLargest(PShape, double)
public static processing.core.PShape resizeByMajorAxis(processing.core.PShape shape, double targetSize)
For example, if the shape's width is larger than its height, the width is set
to targetSize
and the height is resized to maintain the shape's
aspect ratio.
shape
- the shape to resizetargetLargest
- the new length of its longest axisresizeByWidth(PShape, double)
,
resizeByHeight(PShape, double)
public static processing.core.PShape touchScale(processing.core.PShape shape, processing.core.PShape boundary, double tolerance)
shape
- the shape to scale. its centroid should be outside containerboundary
- tolerance
- >=0public static processing.core.PShape translate(processing.core.PShape shape, double x, double y)
shape
- shape to translatex
- the value to translate by in the x directiony
- the value to translate by in the y directionpublic static processing.core.PShape translateTo(processing.core.PShape shape, double x, double y)
translateCentroidTo()
instead.shape
- shape to translatex
- target centroid Xy
- target centroid Ypublic static processing.core.PShape translateCentroidTo(processing.core.PShape shape, double x, double y)
shape
- The PShape instance to be translated.x
- The horizontal coordinate to which the centroid of the shape's
bounding polygon should be aligned. Measured in pixels from the
left of the container.y
- The vertical coordinate to which the centroid of the shape's
bounding polygon should be aligned. Measured in pixels from the
top of the container.translateTo()
public static processing.core.PShape translateEnvelopeTo(processing.core.PShape shape, double x, double y)
translateTo()
because that uses
center of shape's "mass", whereas this is visual center (however both are
usually similar, if not identical).shape
- shape to translatex
- the x-coordinate of new position of the shape's bounding box
centroid pointy
- the y-coordinate of new position of the shape's bounding box
centroid pointpublic static processing.core.PShape translateCornerTo(processing.core.PShape shape, double x, double y)
shape
- The PShape instance to be translated.x
- The horizontal coordinate to which the upper-left corner of the
shape's bounding box is to be aligned. Measured in pixels from
the left of the container.y
- The vertical coordinate to which the upper-left corner of the
shape's bounding box is to be aligned. Measured in pixels from
the top of the container.public static processing.core.PShape translateToOrigin(processing.core.PShape shape)
shape
- The PShape instance to be translated.public static processing.core.PShape homotheticTransformation(processing.core.PShape shape, processing.core.PVector center, double scaleX, double scaleY)
A Homothetic Transformation is a special geometric transformation that enlarges or shrinks geometries by a scale factor that is the same in all directions according to a centric point.
shape
- shape inputcenter
- coordinate of the center/origin position of the operationscaleX
- X scale factorscaleY
- Y scale factorpublic static processing.core.PShape align(processing.core.PShape sourceShape, processing.core.PShape transformShape)
alignShape
- the polygon shape to be transformed and aligned to the
other shape.baseShape
- the shape that the other shape will be aligned to.public static processing.core.PShape align(processing.core.PShape alignShape, processing.core.PShape baseShape, double alignmentRatio)
This method signature aligns the shape according to a provided ratio, indicating how much alignment transformation to apply.
alignShape
- the polygon shape to be transformed and aligned to the
other shape.baseShape
- the shape that the other shape will be aligned to.alignmentRatio
- a value in [0,1] indicating how much to transform the
shape from its original position to its most aligned
position. 0 means no transformation, 1 means maximum
alignment.public static processing.core.PShape rotate(processing.core.PShape shape, processing.core.PVector point, double angle)
shape
- the shape to tranform/rotatepoint
- rotation pointangle
- the rotation angle, in radiansrotateAroundCenter(PShape, double)
public static processing.core.PShape rotateAroundCenter(processing.core.PShape shape, double angle)
shape
- angle
- the rotation angle, in radiansrotate(PShape, PVector, double)
public static processing.core.PShape flipHorizontal(processing.core.PShape shape)
shape
- public static processing.core.PShape flipHorizontal(processing.core.PShape shape, double y)
shape
- y
- y-coordinate of horizontal reflection linepublic static processing.core.PShape flipVertical(processing.core.PShape shape)
shape
- public static processing.core.PShape flipVertical(processing.core.PShape shape, double x)
shape
- x
- x-coordinate of vertical reflection linepublic static processing.core.PShape shear(processing.core.PShape shape, double angleX, double angleY)
shape
- The shape to be sheared.angleX
- The angle by which the shape should be sheared along the
x-axis, in radians.angleY
- The angle by which the shape should be sheared along the
y-axis, in radians.Copyright © 2023. All rights reserved.