Class mathnetics.point2D

Extends Vector

class mathnetics.point2D
The point2D class defines a point in 2-dimensional Euclidean space via homogeneous coordinates (i.e. as a 3-vector (x,y,1)). This allows affine transformations to be applied to 2-D points via matrix multiplication.
Defined in point2D.js

Variable Summary
Number[] components
The components of the 2D point.
private int n
The "dimension" of the point; ALWAYS 2.
private Number x
The x value of the 2D point.
private Number y
The y value of the 2D point.
public static mathnetics.point2D zero
The 2-D "origin" (0,0)

Variables inherited from Vector
i, j, k

Constructor Summary
point2D (Number x, Number y)
Constructor function.

Function Summary
Converts a 2D point to a 3D point with a 0 z-component.
public mathnetics.point2D map (Function func)
Maps this point to a new 2D point according to a given function.
public mathnetics.point2D rotate (Number theta)
Rotates a point through a degree theta and returns a new point.
public String toString()
Produces a string representation of the point.
public Vector toVector()
Converts point2D object back to a Vector.
public mathnetics.point2D translate (Number dx, Number dy)
Translates a point (x,y,1) to (x+dx, y+dy, 1).


Variable Details

variable Number[] components

The components of the 2D point. This allows multiplication by affine transformation matrices and other useful Vector operations.

variable private int n

The "dimension" of the point; ALWAYS 2. Important that this.n != 3; gives "illusion" of 2-D vector while allowing multiplication by matrices with 3 columns for transformations

variable private Number x

The x value of the 2D point.

variable private Number y

The y value of the 2D point.

variable public static mathnetics.point2D zero

The 2-D "origin" (0,0)

Constructor Details

constructor point2D

point2D(Number x, Number y)
point2D(mathnetics.point2D point)
Constructor function. Makes a new 2D point (x,y,1).
Parameters:
components
x - the x component; if x is a point2D object, will create a duplicate of the point
y - the y component
clone
point - the point to clone

Function Details

function make3D

public mathnetics.point3D make3D()
Converts a 2D point to a 3D point with a 0 z-component.
Returns:
the 3D point

function map

public mathnetics.point2D map(Function func)
Maps this point to a new 2D point according to a given function. Overwrites the map function of the Vector class. Used internally for things like addition, multiplication, dot products, etc.
Parameters:
func - the mapping function
Returns:
the new, mapped point

function rotate

public mathnetics.point2D rotate(Number theta)
Rotates a point through a degree theta and returns a new point.
Parameters:
theta - the degree (in radians) by which to rotate the point
Returns:
a new point that is the old rotated through an angle theta

function toString

public String toString()
Produces a string representation of the point. Overwrites the toString function of the Vector class.
Returns:
the string (x,y)

function toVector

public Vector toVector()
Converts point2D object back to a Vector. Will no longer be homogeneous coordinates.
Returns:
the vector [x,y]

function translate

public mathnetics.point2D translate(Number dx, Number dy)
Translates a point (x,y,1) to (x+dx, y+dy, 1).
Parameters:
dx - the x translation
dy - the y translation
Returns:
a new point that is the old one translated