Rac. Point

Point in a two dimentional coordinate system.

Several methods will 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.

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.

x :number

X coordinate of the point.

y :number

Y coordinate of the point.

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 Point to add

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:
Parameters:
Name Type Attributes Default Description
point Rac.Point

A Point to measure the angle to

defaultAngle Rac.Angle | number <optional>
instance.Angle.Zero

An Angle to return when this and point are equal

arc(radius, someStartopt, someEndopt, 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 Arc

someStart Rac.Angle | number <optional>
rac.Angle.zero

The start Angle of the new Arc

someEnd Rac.Angle | number <optional>
null

The end Angle of the new Arc; when null or ommited, start is used instead

clockwise boolean <optional>
true

The orientation of the new Arc

distanceToPoint(point) → {number}

Returns the distance from this to point, or returns 0 when this and point are considered equal.

See:
Parameters:
Name Type Description
point Rac.Point

A Point to measure the distance to

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:
Parameters:
Name Type Description
otherPoint Rac.Point

A Point to compare

negative() → {Rac.Point}

Returns a new Point with the negative coordinate values of this.

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 Angle towars the new Point

distance number

The distance to the new Point

ray(angle) → {Rac.Ray}

Returns a new Ray from this towards angle.

Parameters:
Name Type Description
angle Rac.Angle | number

The Angle of the new Ray

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 new Ray will be in the clockwise side of the ray formed from this towards arc.center. arc is considered a complete circle.

When this is inside arc no tangent segment is possible and null is returned.

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 new Ray will have an angle perpendicular to arc.start.inverse(), in the clockwise orientation.

Parameters:
Name Type Attributes Default Description
arc Rac.Arc

An Arc to calculate a tangent to, considered as a complete circle

clockwise boolean <optional>
true

the orientation of the new Ray

rayToPoint(point, defaultAngleopt) → {Rac.Ray}

Returns a new Ray from this towards point.

When this and point are considered equal, the new Ray will use the angle produced with defaultAngle.

Parameters:
Name Type Attributes Default Description
point Rac.Point

A Point to point the Ray towards

defaultAngle Rac.Angle | number <optional>
instance.Angle.Zero

An Angle to use when this and point are equal

rayToProjectionInRay(ray) → {Rac.Ray}

Returns a new Ray from this to the projection of this in ray.

When the projected point is equal to this the produced ray will have an angle perpendicular to ray in the clockwise direction.

Parameters:
Name Type Description
ray Rac.Ray

A Ray to project this onto

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 new Segment will be in the clockwise side of the ray formed from this towards arc.center, and its end point will be at the contact point with arc which is considered as a complete circle.

When this is inside arc no tangent segment is possible and null is returned.

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 new Segment will have an angle perpendicular to arc.start.inverse(), in the clockwise orientation.

Parameters:
Name Type Attributes Default Description
arc Rac.Arc

An Arc to calculate a tangent to, considered as a complete circle

clockwise boolean <optional>
true

the orientation of the new Segment

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 Angle to point the segment towards

length number

The length of the new Segment

segmentToPoint(point, defaultAngleopt) → {Rac.Segment}

Returns a new Segment from this to point.

When this and point are considered equal, the new Segment will use the angle produced with defaultAngle.

See:
Parameters:
Name Type Attributes Default Description
point Rac.Point

A Point to point the Segment towards

defaultAngle Rac.Angle | number <optional>
instance.Angle.Zero

An Angle to use when this and point are equal

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 new Segment will have an angle perpendicular to ray in the clockwise direction.

Parameters:
Name Type Description
ray Rac.Ray

A Ray to project this onto

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 Point to subtract

text(string, format) → {Rac.Text}

Returns a new Text with the given string and format.

Parameters:
Name Type Description
string string

The string of the new Text

format Rac.Text.Format

The format of the new Text

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

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 Point

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 Point