Point in a two dimentional coordinate system.
Several methods return an adjusted value or perform adjustments in their
operation when two points are close enough as to be considered equal.
When the the difference of each coordinate of two points is under the
equalityThreshold the points are
considered equal. The equals method performs
this check.
instance.Point
Instances of Rac contain a convenience
rac.Point function to create Point objects with
fewer parameters. This function also contains ready-made convenience
objects, like rac.Point.origin, listed under
instance.Point.
Example
let rac = new Rac()
// new instance with constructor
let point = new Rac.Point(rac, 55, 77)
// or convenience function
let otherPoint = rac.Point(55, 77)
- See also:
Constructor
new Point(rac, x, y)
Creates a new Point instance.
Parameters:
| Name | Type | Description |
|---|---|---|
rac |
Rac
|
Instance to use for drawing and creating other objects |
x |
Number
|
The x coordinate |
y |
Number
|
The y coordinate |
Members
rac :Rac
Instance of Rac used for drawing and passed along to any created
object.
Methods
add(x, y) → {Rac.Point}
Returns a new Point by adding the x and y components to this.
Parameters:
| Name | Type | Description |
|---|---|---|
x |
Number
|
The x coodinate to add |
y |
Number
|
The y coodinate to add |
addPoint(point) → {Rac.Point}
Returns a new Point by adding the components of point to this.
Parameters:
| Name | Type | Description |
|---|---|---|
point |
Rac.Point
|
A |
addX(x) → {Rac.Point}
Returns a new Point with x added to this.x.
Parameters:
| Name | Type | Description |
|---|---|---|
x |
Number
|
The x coordinate to add |
addY(y) → {Rac.Point}
Returns a new Point with y added to this.y.
Parameters:
| Name | Type | Description |
|---|---|---|
y |
Number
|
The y coordinate to add |
angleToPoint(point, defaultAngleopt) → {Rac.Angle}
Returns the angle from this to point.
When this and point are considered equal,
returns the angle produced with defaultAngle.
- See also:
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
point |
Rac.Point
|
A |
||
defaultAngle |
Rac.Angle
|
Number
|
<optional> |
rac.Angle.zero
|
An |
arc(radius, startopt, endopt, clockwiseopt) → {Rac.Arc}
Returns a new Arc with center at this and the given arc properties.
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
radius |
Number
|
The radius of the new |
||
start |
Rac.Angle
|
Number
|
<optional> |
rac.Angle.zero
|
The start |
end |
Rac.Angle
|
Number
|
<optional> |
null
|
The end |
clockwise |
Boolean
|
<optional> |
true
|
The orientation of the new |
distanceToPoint(point) → {Number}
Returns the distance from this to point.
When this and point are considered equal,
returns the angle produced with defaultAngle.
- See also:
Parameters:
| Name | Type | Description |
|---|---|---|
point |
Rac.Point
|
A |
equals(otherPoint) → {Boolean}
Returns true when the difference with otherPoint for each
coordinate is under rac.equalityThreshold;
otherwise returns false.
When otherPoint is any class other that Rac.Point, returns false.
Values are compared using rac.equals.
- See also:
Parameters:
| Name | Type | Description |
|---|---|---|
otherPoint |
Rac.Point
|
A |
negative() → {Rac.Point}
Returns a new Point with the negative coordinate values of this.
pointAtBisector(point) → {Rac.Point}
Returns a new Point located in the middle between this and point.
Parameters:
| Name | Type | Description |
|---|---|---|
point |
Rac.Point
|
A |
pointToAngle(angle, distance) → {Rac.Point}
Returns a new Point at a distance from this in the direction of
angle.
Parameters:
| Name | Type | Description |
|---|---|---|
angle |
Rac.Angle
|
Number
|
An |
distance |
Number
|
The distance to the new |
ray(angle) → {Rac.Ray}
Returns a new Ray from this towards angle.
Parameters:
| Name | Type | Description |
|---|---|---|
angle |
Rac.Angle
|
Number
|
The |
rayTangentToArc(arc, clockwiseopt) → (nullable) {Rac.Ray}
Returns a new Ray that starts at this and is tangent to arc, when
no tangent is possible returns null.
The resulting Ray is in the clockwise side of the ray formed
from this towards arc.center. arc is considered a complete
circle.
When this is inside arc, returns null since no tangent segment is
possible.
A special case is considered when arc.radius is considered to be 0
and this is equal to arc.center. In this case the angle between
this and arc.center is assumed to be the inverse of arc.start,
thus the resulting Ray defaults to an angle perpendicular to
arc.start.inverse(), in the clockwise orientation.
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
arc |
Rac.Arc
|
An |
||
clockwise |
Boolean
|
<optional> |
true
|
the orientation of the new |
rayToPoint(point, defaultAngleopt) → {Rac.Ray}
Returns a new Ray from this towards point.
When this and point are considered equal,
the resulting Ray uses the angle produced with defaultAngle.
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
point |
Rac.Point
|
A |
||
defaultAngle |
Rac.Angle
|
Number
|
<optional> |
rac.Angle.zero
|
An |
rayToProjectionInRay(ray) → {Rac.Ray}
Returns a new Ray from this to the projection of this in ray.
When the projected point and this are
considered equal the resulting Ray defaults
to an angle perpendicular to ray in the clockwise direction.
Parameters:
| Name | Type | Description |
|---|---|---|
ray |
Rac.Ray
|
A |
segmentTangentToArc(arc, clockwiseopt) → (nullable) {Rac.Segment}
Returns a new Segment that starts at this and is tangent to arc,
when no tangent is possible returns null.
The resulting Segment is in the clockwise side of the ray formed
from this towards arc.center, and ends at the contact point with
arc which is considered as a complete circle.
When this is inside arc, returns null since no tangent segment is
possible.
A special case is considered when arc.radius is considered to be 0
and this is equal to arc.center. In this case the angle between
this and arc.center is assumed to be the inverse of arc.start,
thus the resulting Segment defaults to an angle perpendicular to
arc.start.inverse(), in the clockwise orientation.
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
arc |
Rac.Arc
|
An |
||
clockwise |
Boolean
|
<optional> |
true
|
the orientation of the new |
segmentToAngle(angle, length) → {Rac.Segment}
Returns a new Segment from this towards angle with the given
length.
Parameters:
| Name | Type | Description |
|---|---|---|
angle |
Rac.Angle
|
Number
|
An |
length |
Number
|
The length of the new |
segmentToPoint(point, defaultAngleopt) → {Rac.Segment}
Returns a new Segment from this to point.
When this and point are considered equal,
the resulting Segment defaults to the angle produced with
defaultAngle.
- See also:
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
point |
Rac.Point
|
A |
||
defaultAngle |
Rac.Angle
|
Number
|
<optional> |
rac.Angle.zero
|
An |
segmentToProjectionInRay(ray) → {Rac.Segment}
Returns a new Segment from this to the projection of this in
ray.
When the projected point is equal to this, the resulting Segment
defaults to an angle perpendicular to ray in the clockwise direction.
Parameters:
| Name | Type | Description |
|---|---|---|
ray |
Rac.Ray
|
A |
subtract(x, y) → {Rac.Point}
Returns a new Point by subtracting the x and y components.
Parameters:
| Name | Type | Description |
|---|---|---|
x |
Number
|
The x coodinate to subtract |
y |
Number
|
The y coodinate to subtract |
subtractPoint(point) → {Rac.Point}
Returns a new Point by subtracting the components of point.
Parameters:
| Name | Type | Description |
|---|---|---|
point |
Rac.Point
|
A |
text(string, formatopt) → {Rac.Text}
Returns a new Text located at this with the given string and
format.
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
string |
String
|
The string of the new |
||
format |
Rac.Text.Format
|
<optional> |
rac.Text.Format.topLeft
|
The format of the new |
toString(digitsopt) → {String}
Returns a string representation intended for human consumption.
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
digits |
Number
|
<optional> |
null
|
The number of digits to print after the decimal point, when ommited all digits are printed |
Example
rac.Point(55, 77).toString()
// returns: 'Point(55,77)'
vertex()
Calls p5.vertex to represent this Point.
Added to Rac.Point.prototype when Rac.P5Drawer is setup as
rac.drawer.
withX(newX) → {Rac.Point}
Returns a new Point with x set to newX.
Parameters:
| Name | Type | Description |
|---|---|---|
newX |
Number
|
The x coordinate for the new |
withY(newY) → {Rac.Point}
Returns a new Point with x set to newX.
Parameters:
| Name | Type | Description |
|---|---|---|
newY |
Number
|
The y coordinate for the new |