Point class

Class Point represents a point in two or three-dimensional space. The point coordinates are represented by x, y and optionally z.

The Point class supports a wide variety of operations such as basic arithmetic operations, transformation operations (like rotation and scaling), distance and angle calculations, conversion to/from polar coordinates, and geometric operations related to lines, triangles, circles, and polygons.

Inheritance
Available Extensions

Constructors

Point(num x, num y, [num? z])
Constructor for creating a new Point.
Point.fromList(List<num> coords)
Constructs a new Point from a list of numbers.
factory
Point.fromPolarCoordinates(num r, num theta, [Point? origin])
Create a point and sets the coordinates of the point given polar coordinates r and theta (in radians), and an optional origin.
factory
Point.fromSphericalCoordinates(num r, num theta, num phi)
Creates a 3D point and sets the coordinates of the point given spherical coordinates r, theta, and phi.
factory
Point.origin([bool is3DPoint = true])
Creates a point at the origin of the coordinate system. If is3DPoint is true, the point will have a z-coordinate of zero. Otherwise, the point will be a 2D point with only x and y coordinates.
factory

Properties

elements Iterable
Getter to retrieve an iterable over all elements in the matrix, regardless of their row or column.
no setterinherited
first num
The first element.
no setterinherited
hashCode int
The hash code for this object.
no setteroverride
isEmpty bool
Whether this collection has no elements.
no setterinherited
isNotEmpty bool
Whether this collection has at least one element.
no setterinherited
iterator Iterator<num>
Overrides the iterator getter to provide a VectorIterator. This iterator iterates over the elements of the vector.
no setterinherited
last num
The last element.
no setterinherited
length int
Returns the length (number of elements) of the vector.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
single num
Checks that this iterable has only one element, and returns that element.
no setterinherited
x num
The x-coordinate of the point.
getter/setter pair
y num
The y-coordinate of the point.
getter/setter pair
z num?
The z-coordinate of the point. If the point is 2D, this value is null.
getter/setter pair

Methods

angle(Vector other) double
Returns the angle (in radians) between this vector and other.
inherited
angleBetween(Point otherPoint) Angle
Calculates the angle (in radians) between this point and another, considering the line between them as the hypotenuse of a right triangle.
any(bool test(num element)) bool
Checks whether any element of this iterable satisfies test.
inherited
bearingTo(Point point, {bool isXAxis = true}) Angle
Computes the bearing from this point to another point.
cast<R>() Iterable<R>
A view of this iterable as an iterable of R instances.
inherited
contains(Object? element) bool
Whether the collection contains an element equal to element.
inherited
distance(Vector other, {DistanceType distance = DistanceType.frobenius}) num
Sets all elements of this vector to value.
inherited
distanceTo(Point otherPoint) double
Computes the Euclidean distance between this point and another.
distanceToCircle(Point center, double radius) double
Calculates the shortest distance from this point to a circle. If this point is inside the circle, the distance is 0.
distanceToLine(Point linePoint1, Point linePoint2) double
Calculates the shortest distance from this point to a line defined by two points.
distanceToPolyline(List<Point> polyline) double
Calculates the shortest distance from this point to a polyline, which is a list of points forming a broken line.
elementAt(int index) num
Returns the indexth element.
inherited
every(bool test(num element)) bool
Checks whether every element of this iterable satisfies test.
inherited
expand<T>(Iterable<T> toElements(num element)) Iterable<T>
Expands each element of this Iterable into zero or more elements.
inherited
firstWhere(bool test(num element), {num orElse()?}) num
The first element that satisfies the given predicate test.
inherited
flip() Vector
Flips elements of the vector.
inherited
fold<T>(T initialValue, T combine(T previousValue, num element)) → T
Reduces a collection to a single value by iteratively combining each element of the collection with an existing value
inherited
followedBy(Iterable<num> other) Iterable<num>
Creates the lazy concatenation of this iterable and other.
inherited
forEach(void action(num element)) → void
Invokes action on each element of this iterable in iteration order.
inherited
getVector(List<String> mapping) Vector
Generates a new Vector (Vector2, Vector3, Vector4) based on the mapping provided.
inherited
interpolate(Point point1, Point point2) Point
Interpolates between two points, using this point as the ratio. If z is null for any of the points, the resulting point will be 2-dimensional.
is3DPoint() bool
Checks if this point is a 3D point.
isCollinear(Point a, Point b) bool
Checks if this point is collinear with two other points.
isInsidePolygon(List<Point> polygon, [double tolerance = 1e-10]) bool
Checks if this point is inside a polygon or on its boundary. The polygon is represented by a list of points in counter-clockwise order. A tolerance value is used to handle floating point inaccuracies.
isOnLineSegment(Point pointA, Point pointB, [double tolerance = 1e-10]) bool
Checks if the point is on a line segment defined by two points. A tolerance value is used to handle floating point inaccuracies.
isUnit() bool
Returns true if this is a unit vector, i.e., its norm is 1.
inherited
isZero() bool
Returns true if this is a zero vector, i.e., all its elements are zero.
inherited
join([String separator = ""]) String
Converts each element to a String and concatenates the strings.
inherited
lastWhere(bool test(num element), {num orElse()?}) num
The last element that satisfies the given predicate test.
inherited
map<T>(T toElement(num e)) Iterable<T>
The current elements of this iterable modified by toElement.
inherited
midpointTo(Point otherPoint) Point
Computes the midpoint between this point and another.
move(num dx, num dy, [num? dz]) Point
Moves the point by a given delta along each axis.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
polarCoordinates() → (num, Angle)
Returns the polar coordinates (r, theta) of the point, where r is the distance from the origin and theta is the angle in radians.
pop() num
Removes the last value in the row.
inherited
projection(Vector other) Vector
Returns the projection of this vector onto other.
inherited
push(num value) → void
Adds a new value at the end of the row.
inherited
reduce(num combine(num value, num element)) num
Reduces a collection to a single value by iteratively combining elements of the collection using the provided function.
inherited
reflect([Point? origin]) Point
Reflects the point through the given origin.
roll(dynamic shift) Vector
Rolls the elements in a 1D list by a certain amount.
inherited
rotate(Angle angle) Point
Rotates the point around the origin (0, 0) by a given angle (in radians).
rotateBy(Angle angle, [Point? origin]) Point
Rotates the point around a given origin by a specific `angle (in radians).
scale(num factor) Point
Scales the point by a given factor.
shift() → dynamic
Removes the first value in the row.
inherited
singleWhere(bool test(num element), {num orElse()?}) num
The single element that satisfies test.
inherited
skip(int count) Iterable<num>
Creates an Iterable that provides all but the first count elements.
inherited
skipWhile(bool test(num value)) Iterable<num>
Creates an Iterable that skips leading elements while test is satisfied.
inherited
slopeTo(Point otherPoint) double
Calculates the slope of the line formed by this point and another.
splice(int start, int deleteCount, [List<num> newItems = const []]) → void
Adds/removes elements at an arbitrary position in the row.
inherited
subVector({List<int>? indices, String range = '', int? start, int? end}) Vector
Extracts a subVector from the given vector using the specified indices or range.
inherited
swap(int index1, int index2) → void
Swaps two elements in the row.
inherited
take(int count) Iterable<num>
Creates a lazy iterable of the count first elements of this iterable.
inherited
takeWhile(bool test(num value)) Iterable<num>
Creates a lazy iterable of the leading elements satisfying test.
inherited
toCylindrical() List<double>
Converts the Vector from Cartesian to Cylindrical coordinates.
inherited
toDiagonal() Matrix
Returns the leading diagonal matrix from a vector.
inherited
toList({bool growable = true}) List<num>
Creates a List containing the elements of this Iterable.
inherited
toMatrix(int rows, int cols, {bool fillWithZeros = true}) Matrix
Constructs a new Matrix from a vector.
inherited
toPoint() Point
inherited
toPolar() List<double>
Converts the Vector from Cartesian to Polar coordinates.
inherited
toSet() Set<num>
Creates a Set containing the same elements as this iterable.
inherited
toSpherical() List<double>
Converts the Vector from Cartesian to Spherical coordinates.
inherited
toString() String
A custom toString method for better readability.
override
toVector() Vector
Converts this Point to a list of numbers, which can be used to represent it as a vector.
translate(num dx, num dy, [num? dz]) Point
Translates the point by the given amounts dx, dy, and dz.
triangleArea(Point point1, Point point2) double
Calculates the area of the triangle formed by this point and two other points.
unShift(num value) → void
Adds a new value at the beginning of the row.
inherited
where(bool test(num element)) Iterable<num>
Creates a new lazy Iterable with all elements that satisfy the predicate test.
inherited
whereType<T>() Iterable<T>
Creates a new lazy Iterable with all elements that have type T.
inherited

Operators

operator *(num scalar) Point
Overrides the multiplication (*) operator.
operator +(Point other) Point
Overrides the addition (+) operator.
operator -(Point other) Point
Overrides the subtraction (-) operator.
operator /(num scalar) Point
Overrides the division (/) operator.
operator ==(Object other) bool
Overloads the == (equality) operator.
override
operator [](int index) num
Fetches the value at the given index of the vector.
inherited
operator []=(int index, num value) → void
Sets the value at the given index of the vector.
inherited