Constructor
new Point2D(xopt, yopt)
- Source:
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
x |
number |
<optional> |
0
|
x coordinate of the point. |
y |
number |
<optional> |
0
|
y coordinate of the point. |
Members
x :number
- Description:
- X coordinate of the point.
- Source:
X coordinate of the point.
Type:
- number
y :number
- Description:
- Y coordinate of the point.
- Source:
Y coordinate of the point.
Type:
- number
Methods
add(point) → {module:shared.Point2D}
- Description:
- Add the given point to this point.
- Source:
Parameters:
Name | Type | Description |
---|---|---|
point |
module:shared.Point2D | The point to add. |
Returns:
this
angleTo(pointnon-null) → {number}
- Description:
- Calculates the angle between this point and the given point.
- Source:
Parameters:
Name | Type | Description |
---|---|---|
point |
module:shared.Point2D | Projected point for calculating the angle. |
Returns:
Radians along the unit circle where the projected point
lies.
- Type
- number
averageDistanceTo(pointsnon-null) → {number}
- Description:
- Determine the average distance from this point to the provided array of points.
- Source:
Parameters:
Name | Type | Description |
---|---|---|
points |
Array.<module:shared.Point2D> | the Point2D objects to calculate the average distance to. |
Returns:
The average distance from this point to the provided
points.
- Type
- number
clone() → {module:shared.Point2D}
- Description:
- Clones this point.
- Source:
Returns:
An exact clone of this point.
distanceTo(pointnon-null) → {number}
- Description:
- Calculates the distance between two points.
- Source:
Parameters:
Name | Type | Description |
---|---|---|
point |
module:shared.Point2D | Point to which the distance is calculated. |
Returns:
The distance between the two points, a.k.a. the
hypoteneuse.
- Type
- number
divideBy(coefficient) → {module:shared.Point2D}
- Description:
- Divide the point's values by the given amount.
- Source:
Parameters:
Name | Type | Default | Description |
---|---|---|---|
coefficient |
number |
1
|
divide x,y by this amount. |
Returns:
this
isLeftOf(p0, p1) → {number|number|number}
- Description:
- Tests if a point is Left|On|Right of an infinite line. Assumes that the given points are such that one is above and one is below this point. Note that the semantics of left/right is based on the normal coordinate space, not the y-axis-inverted coordinate space of images and the canvas.
- Source:
- See:
Parameters:
Name | Type | Description |
---|---|---|
p0 |
module:shared.Point2D | first point of the line. |
p1 |
module:shared.Point2D | second point of the line. |
Returns:
-
>0 if this point is left of the line through p0 and p1
- Type
- number
-
=0 if this point is on the line
- Type
- number
-
<0 if this point is right of the line
- Type
- number
minus(p) → {module:shared.Point2D}
- Description:
- Subtracts the given point from this point to form a new point.
- Source:
Parameters:
Name | Type | Description |
---|---|---|
p |
module:shared.Point2D | Point to subtract from this point. |
Returns:
A new point which is the simple subraction
of the given point from this point.
multiplyBy(coefficient) → {module:shared.Point2D}
- Description:
- Multiply this point by the given point, in-place.
- Source:
Parameters:
Name | Type | Default | Description |
---|---|---|---|
coefficient |
number |
1
|
Amount by which to multiply the values in this point. |
Returns:
this
rotate(theta) → {module:shared.Point2D}
- Description:
- Rotate the point by theta radians.
- Source:
Parameters:
Name | Type | Default | Description |
---|---|---|---|
theta |
number |
0
|
Amount of rotation to apply, in radians. |
Returns:
this
totalDistanceTo(pointsnon-null) → {number}
- Description:
- Calculates the total distance from this point to an array of points.
- Source:
Parameters:
Name | Type | Description |
---|---|---|
points |
Array.<module:shared.Point2D> | The array of Point2D objects to calculate the total distance to. |
Returns:
The total distance from this point to the provided points.
- Type
- number
(static) midpoint(points) → (nullable) {module:shared.Point2D}
- Description:
- Calculates the midpoint of a list of points.
- Source:
Parameters:
Name | Type | Description |
---|---|---|
points |
Array.<module:shared.Point2D> | The array of Point2D objects for which to calculate the midpoint |
Returns:
The midpoint of the provided points. Null
if the provided array is empty.
(static) sum(points) → {module:shared.Point2D}
- Description:
- Calculates the sum of the given points.
- Source:
Parameters:
Name | Type | Description |
---|---|---|
points |
Array.<module:shared.Point2D> | The Point2D objects to sum up. |
Returns:
A new Point2D representing the sum of the
given points.