figureone
    Preparing search index...

    Object representing a point or vector.

    Contains methods that makes it convenient to work with points and vectors.

    // get Point from Fig
    const { Point } = Fig;

    // define a point at (0, 2)
    const p = new Point(0, 2);

    // find the distance to another point (0, 1) which will be 1
    const d = p.distance([0, 1]);

    // add to another point (3, 1) which will result in (3, 3)
    const q = p.add(3, 1);
    Index

    Methods

    • Return x, y, z components as a length 3 tuple.

      Parameters

      • dimension: 2 | 3 = 3

      Returns [number, number, number] | [number, number]

    • Convert a cartesian point to polar coordiantes (will use x and y components of point only).

      Returns { mag: number; angle: number }

    • Convert the cartesian point to spherical coordinates.

      Returns { mag: number; theta: number; phi: number }

    • Multiply values of point by scalar

      Parameters

      • scalar: number

      Returns Point

      p = new Point(1, 1, 1);
      s = p.scale(3);
      // s = Point{x: 3, y: 3, z: 3}
    • Complex multiplication.

      Multiply two 2D points such that x is the real value and y is the imaginary value of a complex number. z is ignored.

      Parameters

      Returns Point

      p = new Point(1, 2); // represents 1 + 2i
      q = new Point(2, 3); // represents 2 + 3i
      m = p.cmul(q);
      // m = Point{x: -4, y: 7, z: 0}
      // which represents the complex value -4 + 7i
    • Complex division.

      Divide this point by complexPoint. Each point represents a complex number where x is the real value and y is the imaginary value. z is ignored.

      Parameters

      Returns Point

      p = new Point(-4, 7); // represents -4 + 7i
      q = new Point(1, 2); // represents 1 + 2i
      m = p.cdiv(q);
      // m = Point{x: 2, y: 3, z: 0}
      // which represents the complex value 2 + 3i
    • Subtract (x, y, z) values or a Point and return the difference as a new Point

      Parameters

      • pointOrX: number | Point
      • y: number = 0
      • z: number = 0

      Returns Point

      p = new Point(3, 3, 3);
      d = p.sub(1, 1, 1)
      // d = Point{x: 2, y: 2, z: 2}

      p = new Point(3, 3, 3);
      q = new Point(1, 1, 1);
      d = p.sub(q)
      // d = Point{x: 2, y: 2, z: 2}
    • Add (x, y, z) values or a Point and return the sum as a new Point

      Parameters

      • pointOrX: number | Point
      • y: number = 0
      • z: number = 0

      Returns Point

      p = new Point(3, 3, 3);
      d = p.add(1, 1, 1)
      // d = Point{x: 4, y: 4, z: 4}

      p = new Point(3, 3, 3);
      q = new Point(1, 1, 1);
      d = p.add(q)
      // d = Point{x: 4, y: 4, z: 4}
    • Return the distance between two points (or point and origin if no input supplied)

      Parameters

      Returns number

      p = new Point(1, 1, 1);
      q = new Point(0, 0, 0);
      d = q.distance(p);
      // d = 1.7320508075688772
    • Return the distance between (0, 0, 0) and the point. If the point represents a vector, then it is the length of the vector.

      Returns number

    • Returns true if the x, y, z components of the point when rounded with precision are zero.

      Parameters

      • precision: number = 8

      Returns boolean

    • Return a new point with (x, y, z) values rounded to some precision

      Parameters

      • precision: number = 8

      Returns Point

      p = new Point(1.234, 1.234, 1.234);
      q = p.round(2);
      // q = Point{x: 1.23, y: 1.23, z: 1.23}
    • Return a new point that is clipped to min and max values from the origin.

      Use a point as a parameter to define different (x, y) min/max values, a number to define the same (x, y) min/max values, or null to have no min/max values.

      Parameters

      • min: number | Point | null
      • max: number | Point | null

      Returns Point

      p = new Point(2, 2);
      q = p.clip(1, 1);
      // q = Point{x: 1, y: 1}

      p = new Point(2, 2);
      q = p.clip(1, null);
      // q = Point{x: 1, y: 2}

      p = new Point(-2, -2);
      minClip = new Point(-1, -1.5);
      q = p.clip(minClip, null);
      // q = Point{x: -1, y: -1.5}
    • Transform the point with a 4x4 matrix (3 dimensional transform in homogenous coordinates)

      Parameters

      • matrix: Type3DMatrix

      Returns Point

      // Transform a point with a (2, 2, 0) translation then 90º z rotation
      p = new Point(1, 1);
      m = new Transform3().translate(2, 2, 0).rotate(0, 0, Math.PI / 2).matrix();
      // m = [0, -1, 0, -2, 1, 0, 0, 2, 0, 0, 0, 1]
      q = p.transformBy(m)
      // q = Point{x: -3, y: 3, 0}
    • Compare two points for equality to some precision or delta

      Parameters

      • p: TypeParsablePoint

        point to compare

      • precision: number = 8

        precision to compare (8)

      • delta: boolean = false

        if true then precision is the delta value the two points must be within to be equal

      Returns boolean

      p = new Point(1.123, 1.123);
      q = new Point(1.124, 1.124);
      p.isEqualTo(q)
      // false

      p.isEqualTo(q, 2)
      // true
    • Compare two points for unequality to some precision

      Parameters

      • p: Point
      • precision: number = 8
      • delta: boolean = false

      Returns boolean

      p = new Point(1.123, 1.123);
      q = new Point(1.124, 1.124);
      p.isNotEqualTo(q)
      // true

      p.isNotEqualTo(q, 2)
      // false