Point

class compas.geometry.Point(x, y, z=0.0, **kwargs)[source]

Bases: compas.geometry.primitives._primitive.Primitive

A point is defined by XYZ coordinates.

Parameters
  • x (float) – The X coordinate of the point.

  • y (float) – The Y coordinate of the point.

  • z (float, optional) – The Z coordinate of the point. Default is 0.0.

Attributes
  • data (dict) – The data representation of the point.

  • x (float) – The X coordinate of the point.

  • y (float) – The Y coordinate of the point.

  • z (float) – 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.

>>> p1 + p2
Point(5.000, 7.000, 9.000)
>>> p1 * 2
Point(2.000, 4.000, 6.000)
>>> p1 ** 2
Point(1.000, 4.000, 9.000)
>>> p1
Point(1.000, 2.000, 3.000)

Points and lists can be used interchangeably.

>>> p1 + [4, 5, 6]
Point(5.000, 7.000, 9.000)

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

>>> p1 += p2
>>> p1 *= 2
>>> p1 **= 2
>>> p1
Point(100.000, 196.000, 324.000)

Attributes

DATASCHEMA

The schema of the data of this object.

JSONSCHEMANAME

data

The data representing the point.

x

The X coordinate of the point.

y

The Y coordinate of the point.

z

The Z coordinate of the point.

Inherited Attributes

JSONSCHEMA

The schema of the JSON representation of the data of this object.

dtype

The type of the object in the form of a '2-level' import and a class name.

guid

The globally unique identifier of the object.

jsondefinitions

Reusable schema definitions.

jsonstring

The representation of the object data in JSON format.

jsonvalidator

JSON schema validator for draft 7.

name

The name of the object.

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.

from_data

Construct a point from a data dict.

in_circle

Determine if the point lies inside the given circle.

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_line

Determine if the point lies on the given line.

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.

transform_collection

Transform a collection of points.

transformed_collection

Create a collection of transformed points.

Inherited Methods

copy

Make an independent copy of the data object.

from_json

Construct an object from serialized data contained in a JSON file.

from_jsonstring

Construct an object from serialized data contained in a JSON string.

to_data

Convert an object to its native data representation.

to_json

Serialize the data representation of an object to a JSON file.

to_jsonstring

Serialize the data representation of an object to a JSON string.

transformed

Returns a transformed copy of this geometry.

validate_data

Validate the object's data against its data schema (self.DATASCHEMA).

validate_json

Validate the object's data against its json schema (self.JSONSCHEMA).