Class: Point

MC.Point(xopt, yopt) → {MC.Point}

new Point(xopt, yopt) → {MC.Point}


Creates a 2 Dimensional Point / Vector
This:
Parameters:
Name Type Attributes Default Description
x Number | Object <optional>
0 The x value for the Point, if an Object is entered which has numeric >x & y properties, such as another MC.Point, then the new Point is created with these values
y Number <optional>
0 The y value for the Point
Properties:
Name Type Description
x Number
y Number
Source:
Returns:
Type
MC.Point

Methods

abs() → {this}


Returns the Point with Absolute values, e.g. (5,-4) is returned as (5,4)
Source:
Returns:
Enables method chaining
Type
this

add(point_or_x, yopt) → {this}


Adds another point/vector or (x,y) to the calling point
N.B Any object with numeric x and y properties can be added to a Point
Parameters:
Name Type Attributes Description
point_or_x MC.Point | Number Point (or x value) to add
y Number <optional>
y value to add
Source:
Returns:
Enables method chaining
Type
this

angleTo(target) → {Number}


Calculates the angle from one vector to another N.B. +ve = clockwise, so in some circumstances this can be used to determine direction (i.e. a velocity vector with a relational direction vector as target)
0-90 -- target is bearing front right
90-180 -- target is bearing rear right
180-270 -- target is bearing rear left
270-360 -- target is bearing front left
Parameters:
Name Type Description
target MC.Point Target vector/point
Source:
Throws:
Console warning if target does not have x and y properties (or they are non-numeric). Calling vector is unchanged and 0 (zero) returned
Returns:
Angle from calling vector to target vector/point (in degrees)
Type
Number

clamp(minopt, max) → {this}


Clamps the length of the vector to a maximum value OR between a pair of values
N.B. Useful for limiting velocities
Parameters:
Name Type Attributes Default Description
min Number <optional>
0 Minimum length of clamp value
max Number Maximum length of clamp value
Source:
Returns:
Enables method chaining
Type
this

clone() → {MC.Point}


Clones the Point/Vector and returns a copy
Source:
Returns:
A NEW Point Object
Type
MC.Point

div(number) → {this}


Divides the point/vector by a scalar value
Parameters:
Name Type Description
number Number Number to divide Point by
Source:
Throws:
Console warning if attempting to divide by 0 (zero). Point is returned unchanged.
Returns:
Enables method chaining
Type
this

equals(item) → {Boolean}


Checks if the Point's x and y properties match those of another item (which may, or may not be another Point)
Parameters:
Name Type Description
item Object Object for comparison
Source:
Returns:
true if both x and y properties match
Type
Boolean

getAngle() → {Number}


Returns the angle of the vector (as if it's a line with origin 0,0)
Source:
Returns:
The angle of the vector (in degrees clockwise)
Type
Number
Example
..........| 270
       (0,-1)
 180      |        360
 ------------(1,0)---->
          |         0
          |  (1,1)
      90  |
var pnt = new MC.Point(1,0);
var angle = pnt.getAngle(); // 0
pnt.set(1,1);
angle = pnt.getAngle(); // 45
pnt.set(0,-1);
angle = pnt.getAngle(); // 270

getLength() → {Number}


Reports the scalar length of the vector / point
Source:
Returns:
Length of the vector
Type
Number

getLengthSqr() → {Number}


Reports the scalar length SQUARED of the vector / point
Source:
Returns:
Length of the vector
Type
Number

invert() → {this}


Inverts / reverses the direction of the vector
Source:
Returns:
Enables method chaining
Type
this

isLeft(Vector) → {Boolean}


Checks if the Point (as a vector) it to the left of another
Parameters:
Name Type Description
Vector MC.Point to be checked against.
N.B anything with .x and .y properties can be checked against
Source:
Returns:
true if the vector is to the left, else false
Type
Boolean

isRight(Vector) → {Boolean}


Checks if the Point (as a vector) it to the right of another
Parameters:
Name Type Description
Vector MC.Point to be checked against.
N.B anything with .x and .y properties can be checked against
Source:
Returns:
true if the vector is to the right, else false
Type
Boolean

log() → {this}


Console logs the value of a Point (for debugging and testing purposes)
Source:
Returns:
Enables method chaining
Type
this

minus(point_or_x, yopt) → {this}


Subtracts another point/vector or (x,y) from the calling point
N.B Any object with numeric x and y properties can be subtracted from a Point
Parameters:
Name Type Attributes Description
point_or_x MC.Point | Number Point (or x value) to subtract
y Number <optional>
y value to subtract
Source:
Returns:
Enables method chaining
Type
this

normalise() → {this}


Normalises the Vector.
NB. See MS.maths.normalOf() if you need the normal but want to keep the original vector
Both Point.normalise() OR Point.normalize() will work.
Source:
Returns:
Enables method chaining
Type
this

rotate(degrees, originopt) → {this}


Rotates a vector (as if it's a line with origin 0,0 ... or if as a coordinate with optional MC.Point as an origin)
Parameters:
Name Type Attributes Description
degrees Number Angle to rotate by (+ve = clockwise)
origin MC.Point <optional>
optional origin for a coordinate rotation
Source:
Returns:
Enables method chaining
Type
this

scale(scale) → {this}


Scales the vector
Parameters:
Name Type Description
scale Number Scale (aka multiplier) to be applied
Source:
Throws:
Console warning if a non-numeric or 0 (zero) scale applied. Original Point returned
Returns:
Enables method chaining
Type
this

set(point_or_x, yopt) → {this}


Sets the point to equal another point/vector OR a (x,y)
N.B Any object with numeric x and y properties can be used
Parameters:
Name Type Attributes Description
point_or_x MC.Point | Number Point to equal OR the new x value
y Number <optional>
y value
Source:
Returns:
Enables method chaining
Type
this

setAngle(angle) → {this}


Set a vector to an angle (as if it's a line with origin 0,0)
Parameters:
Name Type Description
angle Number Desired angle
Source:
Returns:
Enables method chaining
Type
this

setLength(length) → {this}


Sets the length of a vector
Parameters:
Name Type Description
length Number Desired vector length
Source:
Returns:
Enables method chaining
Type
this

times(x, yopt) → {this}


Multiplies the point/vector by a scalar value
Parameters:
Name Type Attributes Description
x Number Number to multiply the Point by OR (if y is included) number to multiply the x property by
y Number <optional>
Number to multiply the y value by
Source:
Returns:
Enables method chaining
Type
this