Point

class compas.geometry.Point[source]

Bases: Geometry

A point is defined by XYZ coordinates.

Parameters:
xfloat

The X coordinate of the point.

yfloat

The Y coordinate of the point.

zfloat, optional

The Z coordinate of the point.

namestr, optional

The name of the point.

Attributes:
xfloat

The X coordinate of the point.

yfloat

The Y coordinate of the point.

zfloat

The Z coordinate of the point.

Notes

A Point object supports direct access to its xyz coordinates through the dot notation, as well list-style access using indices. Indexed access is implemented such that the Point behaves like a circular list [1].

References

[1]

Stack Overflow. Pythonic Circular List. Available at: https://stackoverflow.com/questions/8951020/pythonic-circular-list.

Examples

>>> p1 = Point(1, 2, 3)
>>> p2 = Point(4, 5, 6)

The XYZ coordinates of point objects can be accessed as object attributes or by trating the points as lists.

>>> p1.x
1.0
>>> p1.y
2.0
>>> p1.z
3.0
>>> p1[0]
1.0
>>> p1[1]
2.0
>>> p1[2]
3.0

Point objects support basic arithmetic operations.

>>> result = p1 + p2
>>> print(result)
Point(x=5.000, y=7.000, z=9.000)
>>> result = p1 * 2
>>> print(result)
Point(x=2.000, y=4.000, z=6.000)
>>> result = p1**2
>>> print(result)
Point(x=1.000, y=4.000, z=9.000)
>>> print(p1)
Point(x=1.000, y=2.000, z=3.000)

Points and lists can be used interchangeably.

>>> result = p1 + [4, 5, 6]
>>> print(result)
Point(x=5.000, y=7.000, z=9.000)

Arithmetic operations can also be applied to modify a point object in-place.

>>> p1 += p2
>>> p1 *= 2
>>> p1 **= 2
>>> print(p1)
Point(x=100.000, y=196.000, z=324.000)

Methods

distance_to_line

Compute the distance to a line.

distance_to_plane

Compute the distance to a plane.

distance_to_point

Compute the distance to another point.

in_circle

Determine if the point lies inside the given circle.

in_convex_polygon

Determine if the point lies inside the given convex polygon.

in_polygon

Determine if the point lies inside the given polygon.

in_polyhedron

Determine if the point lies inside the given polyhedron.

in_triangle

Determine if the point lies inside the given triangle.

on_circle

Determine if the point lies on the given circle.

on_curve

Determine if the point lies on the given curve.

on_line

Determine if the point lies on the given line.

on_plane

Determine if the point lies on the given plane.

on_polyline

Determine if the point lies on the given polyline.

on_segment

Determine if the point lies on the given segment.

transform

Transform this point.

Inherited Methods

ToString

Converts the instance to a string.

compute_aabb

Compute the axis-aligned bounding box of the geometry.

compute_obb

Compute the oriented bounding box of the geometry.

copy

Make an independent copy of the data object.

from_json

Construct an object of this type from a JSON file.

from_jsonstring

Construct an object of this type from a JSON string.

rotate

Rotate the geometry.

rotated

Returns a rotated copy of this geometry.

scale

Scale the geometry.

scaled

Returns a scaled copy of this geometry.

sha256

Compute a hash of the data for comparison during version control using the sha256 algorithm.

to_json

Convert an object to its native data representation and save it to a JSON file.

to_jsonstring

Convert an object to its native data representation and save it to a JSON string.

transformed

Returns a transformed copy of this geometry.

translate

Translate the geometry.

translated

Returns a translated copy of this geometry.

validate_data

Validate the data against the object's data schema.