Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Plane

A 2d frame with a center point (origin) and two perpendicular axes (xAxis and yAxis). The axes are always right-handed.

Example

import { Plane, Point, Vector } from 'shapetypes';

// Create a plane
const plane = new Plane(new Point(3,4), Vector.worldX());

// Map a point from the global coordinate system to the plane's local coordinates
const worldPoint = new Point(5,6);
const planePoint = plane.remapToPlaneSpace(worldPoint);
console.log(planePoint.toString());
// => [2,2]

// Remap the local point back to the global coordinate system
const output = plane.pointAt(planePoint);
console.log(output.toString());
// => [5,6]

// Translate the plane
const moved = plane.translate(new Vector(10,20));
console.log(moved.origin.toString());
// => (13,24)

Hierarchy

Index

Constructors

constructor

  • Creates a plane from a center point and x-axis.

    Parameters

    • origin: Point

      The center of the plane.

    • Optional xAxis: Vector

      The direction of the xAxis. If not specified, it will use Vector.worldX. The y-axis will be automatically generated perpendicular to this axis and will obey the right-hand rule.

    Returns Plane

Accessors

origin

xAxis

yAxis

  • Gets the plane's y-axis.

    This vector is always perpendicular to the plane's xAxis and orientated to obey the right-hand rule.

    Returns Vector

Create Methods

Static fromPoints

  • Creates a plane defined by a center point and a point on the x-axis.

    Parameters

    • origin: Point

      The center of the plane.

    • axisPoint: Point

      A point on the plane's x-axis.

    Returns Plane

Static worldXY

Other Methods

equals

  • equals(plane: Plane, tolerance?: number): boolean
  • Checks whether another plane has the same origin and xAxis. Returns true if it does.

    Parameters

    • plane: Plane

      The plane to compare against.

    • Default value tolerance: number = shapetypesSettings.absoluteTolerance

      The amount the origin points can differ and still be considered equal.

    Returns boolean

pointAt

  • Remaps a point from the u-v space of the plane to the global coordinate system. This is the opposite of remapToPlaneSpace.

    Example

    import { Plane, Point, Vector } from 'shapetypes'
    
    // Create a plane
    const plane = new Plane(new Point(3,4), Vector.worldX());
    
    // Map a point from the global coordinate system to the plane's local coordinates
    const worldPoint = new Point(5,6);
    const planePoint = plane.remapToPlaneSpace(worldPoint);
    console.log(planePoint.toString());
    // => [2,2]
    
    // Remap the local point back to the global coordinate system
    const output = plane.pointAt(planePoint);
    console.log(output.toString());
    // => [5,6]
    
    

    Parameters

    • u: number

      The location of the point measured as a distance along the plane's xAxis.

    • v: number

      The location of the point measured as a distance along the plane's yAxis.

    Returns Point

    The u-v point remapped to the global coordinate system.

  • Remaps a point from the u-v space of the plane to the global coordinate system. This is the opposite of remapToPlaneSpace.

    Parameters

    • uvPoint: Point

      The location of the point in the plane's coordinate system. The x coordinate of this point is the location of the point measured as a distance along the plane's xAxis. The y coordinate of this point is the location of the point measured as a distance along the plane's yAxis.

    Returns Point

    The u-v point remapped to the global coordinate system.

remapToPlaneSpace

  • Remaps a point to the u-v space of the plane. This is the opposite of pointAt.

    Parameters

    • point: Point

      Point to remap.

    Returns Point

    A point in the u-v coordinates of the plane. See pointAt for more details.

toString

  • toString(): string
  • Gets the plane as a string in the format: [origin,xAxis].

    Returns string

withOrigin

withXAxis

  • Creates a copy of the plane with a different xAxis. This will also change the y-axis.

    Parameters

    • newXAxis: Vector

      The x-axis of the new plane.

    Returns Plane

Transform Methods

changeBasis

  • changeBasis(planeFrom: Plane, planeTo: Plane): this
  • Translates the geometry from one coordinate system to another while keeping the geometry in the same position. In other words, if the geometry is currently described relative to planeFrom, after changeBasis, it will be in the same position but described relative to planeTo.

    see

    Transform.changeBasis.

    Parameters

    • planeFrom: Plane

      The coordinate system the geometry is currently described relative to.

    • planeTo: Plane

      The coordinate system to describe the geometry relative to.

    Returns this

    The geometry in the new coordinate system.

planeToPlane

  • planeToPlane(planeFrom: Plane, planeTo: Plane): this

rotate

  • rotate(angle: number): this
  • rotate(angle: number, pivot: Point): this
  • Rotates the geometry about (0,0).

    see

    Transform.rotate.

    Parameters

    • angle: number

      Angle to rotate the geometry (in radians). The direction is counter-clockwise.

    Returns this

  • Rotates the geometry about a point.

    see

    Transform.rotate.

    category

    Transform

    Parameters

    • angle: number

      Angle to rotate the geometry (in radians). If the environment's y-axis points upwards, the direction is counter-clockwise.

    • pivot: Point

      Point to pivot the geometry about.

    Returns this

scale

  • scale(amount: number): this
  • scale(x: number, y: number): this
  • scale(x: number, y: number, center: Point): this
  • Scales the geometry and returns the resized geometry. The geometry will be scaled about (0,0), meaning everything will shrink or expand away from this point.

    see

    Transform.scale.

    Parameters

    • amount: number

      Magnitude to scale in x- and y-direction. If less than 1, the object will shrink. If greater than 1, it will grow.

    Returns this

  • Scales the geometry and returns the resized geometry. The geometry will be scaled about (0,0), meaning everything will shrink or expand away from this point.

    see

    Transform.scale.

    category

    Transform

    Parameters

    • x: number

      Magnitude to scale in x-direction. If less than 1, the object will shrink. If greater than 1, it will grow.

    • y: number

      Magnitude to scale in y-direction. If less than 1, the object will shrink. If greater than 1, it will grow.

    Returns this

  • Scales the geometry about a point and returns the resized geometry.

    see

    Transform.scale.

    category

    Transform

    Parameters

    • x: number

      Magnitude to scale in x-direction. If less than 1, the object will shrink. If greater than 1, it will grow.

    • y: number

      Magnitude to scale in y-direction. If less than 1, the object will shrink. If greater than 1, it will grow.

    • center: Point

      Center of scaling. Everything will shrink or expand away from this point.

    Returns this

transform

  • Transforms the plane by a Transform matrix and returns the result.

    Example

    import { Plane, Point, Transform, Vector } from 'shapetypes';
    
    // Create a plane
    const plane = new Plane(new Point(2,2), Vector.worldX());
    console.log(plane.origin.toString());
    // => (2,2)
    
    // Translate using a transform matrix
    const mover = Transform.translate(new Vector(3,4));
    const moved = plane.transform(mover);
    console.log(moved.origin.toString());
    // => (5,6)
    
    // Translate using the direct method
    const otherMoved = plane.translate(new Vector(3,4));
    console.log(otherMoved.origin.toString());
    // => (5,6)
    note

    If you're applying the same transformation a lot of geometry, creating the Transform matrix once and calling this function is faster than using the direct methods.

    Parameters

    Returns this

translate

  • translate(move: Vector): this
  • translate(move: Vector, distance: number | undefined): this
  • Moves the geometry along a vector and returns the moved geometry. The translation is always linear.

    see

    Transform.translate.

    Parameters

    • move: Vector

      The direction and distance to move the geometry.

    Returns this

  • Moves the geometry along a vector and returns the moved geometry. The translation is always linear.

    see

    Transform.translate.

    category

    Transform

    Parameters

    • move: Vector

      The direction to move the geometry.

    • distance: number | undefined

      The distance to move the geometry.

    Returns this

Generated using TypeDoc