Value accessĬoordinate values can be accessed with dict-like syntax ( coord, coord.get('y', 2)) or, for convenience,Īttribute-like ( coord.z) if the keys are strings. from coordinates import spaced_coordinate CoordinateXYZC = spaced_coordinate ( 'CoordinateXYZC', 'xyzc' ) # this will raise a ValueError CoordinateXYZC ( x = 1, y = 2, z = 3 ) If you're working in one space, the spaced_coordinate factory can create custom subclasses with a fixed set of coord3 = Coordinate ( x = 1, y = 2, z = 3, order = 'zxy' ) coord3. If neither an instance order or a class default_order is set, it falls back to reverse lexicographic. Override their order if it was set explicitly. This affects existing instances, but does not The default order for all Coordinates can be set on the class. The default order for a single instance can be given on instantiation, or mutated (this does not affect equality). You can get the keys, values or items of the Coordinate in a specific order: coord. prod () = 24 > True Coordinate ( x = 3, y = 4 ). They also have some convenience methods for getting the sum, product or norm of their keys. floor ( Coordinate ( x = 0.5 )) = Coordinate ( x = 0 ) > True ceil ( Coordinate ( x = 0.5 )) = Coordinate ( x = 1 ) > True math. coord = Coordinate ( x = 1, y = 2, z = 3 ) coord * 2 = Coordinate ( x = 2, y = 4, z = 6 ) > True coord ** 2 = Coordinate ( x = 1, y = 4, z = 9 ) > True coord + coord = Coordinate ( x = 2, y = 4, z = 3 ) > True coord += 1 # coord is a reference to a new object no mutation coord = Coordinate ( x = 2, y = 3, z = 4 ) > True abs ( Coordinate ( x =- 10, y = 10 )) = Coordinate ( x = 10, y = 10 ) > True import math math. Use a comprehension here instead: om_sequence(zip('xy', row) for row in sequence)Ĭoordinates do maths like you might expect them to, where the other operand is anything dict-like In mathematics, a spherical coordinate system is a coordinate system for three-dimensional space where the position of a point is. In this image, r equals 4/6, equals 90°, and equals 30°. Instantiation from a sequence of tuples will fail in 2D because it will be interpreted as A globe showing the radial distance, polar angle and azimuthal angle of a point P with respect to a unit sphere, in the mathematics convention.order-dependent instantiation is incompatible with **kwargs.from coordinates import Coordinate Coordinate (], z = 10 ) Some keyword arguments, or a mixture of the above). They can be instantiated in any of the ways a dict can (from another Mapping, a sequence of pairs, We're all consenting adults so if you really want to modify the internal _dict, I won't They don't expose an interface for mutation, but stick with numpy) Installation pip install coordinatesĬoordinates are Mappings (i.e. Numpy arrays are great for doing maths with coordinates stored as arrays.ĭicts are great for dealing with coordinate systems where the order keeps changing Convenience class for dealing with coordinates which need both maths and explicit ordering.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |