API Reference

A collection of classes for 2D/3D geometric modelling.

class opensolid.Angle

An angle in degrees, radians, turns etc.

Represented internally as a value in radians.

zero: Angle = Angle.radians(0.0)

The zero value.

golden_angle: Angle = Angle.radians(2.399963229728653)

The [golden angle](https://en.wikipedia.org/wiki/Golden_angle).

radian: Angle = Angle.radians(1.0)

One radian.

full_turn: Angle = Angle.radians(6.283185307179586)

One full turn, or 360 degrees.

half_turn: Angle = Angle.radians(3.141592653589793)

One half turn, or 180 degrees.

quarter_turn: Angle = Angle.radians(1.5707963267948966)

One quarter turn, or 90 degrees.

pi: Angle = Angle.radians(3.141592653589793)

π radians, or 180 degrees.

two_pi: Angle = Angle.radians(6.283185307179586)

2π radians, or 360 degrees.

static interpolate(start: Angle, end: Angle, parameter_value: float) Angle

Interpolate from one value to another, based on a parameter that ranges from 0 to 1.

static steps(start: Angle, end: Angle, n: int) list[Angle]

Interpolate between two values by subdividing into the given number of steps.

The result is an empty list if the given number of steps is zero (or negative). Otherwise, the number of values in the resulting list will be equal to one plus the number of steps. For example, for one step the returned values will just be the given start and end values; for two steps the returned values will be the start value, the midpoint and then the end value.

static leading(start: Angle, end: Angle, n: int) list[Angle]

Interpolate between two values like ‘steps’, but skip the first value.

static trailing(start: Angle, end: Angle, n: int) list[Angle]

Interpolate between two values like ‘steps’, but skip the last value.

static in_between(start: Angle, end: Angle, n: int) list[Angle]

Interpolate between two values like ‘steps’, but skip the first and last values.

static midpoints(start: Angle, end: Angle, n: int) list[Angle]

Subdivide a given range into the given number of steps, and return the midpoint of each step.

This can be useful if you want to sample a curve or other function at the midpoint of several intervals.

static radians(value: float) Angle

Construct an angle from a number of radians.

static degrees(value: float) Angle

Construct an angle from a number of degrees.

static turns(value: float) Angle

Construct an angle from a number of turns.

One turn is equal to 360 degrees.

static acos(value: float) Angle

Compute the inverse cosine of a value.

static asin(value: float) Angle

Compute the inverse sine of a value.

static atan(value: float) Angle

Compute the inverse tangent of a value.

in_radians() float

Convert an angle to a number of radians.

in_degrees() float

Convert an angle to a number of degrees.

in_turns() float

Convert an angle to a number of turns.

One turn is equal to 360 degrees.

is_zero() bool

Check if an angle is zero, within the current tolerance.

sin() float

Compute the sine of an angle.

cos() float

Compute the cosine of an angle.

tan() float

Compute the tangent of an angle.

__eq__(other: object) bool

Return self == other.

Note that this is an exact comparison; for a tolerant comparison (one which will return true if two values are almost equal) you’ll likely want to use an is_zero() method instead.

__lt__(other: Angle) bool

Return self < other.

__le__(other: Angle) bool

Return self <= other.

__ge__(other: Angle) bool

Return self >= other.

__gt__(other: Angle) bool

Return self > other.

__add__(rhs: Angle) Angle
__add__(rhs: AngleBounds) AngleBounds
__add__(rhs: AngleCurve) AngleCurve

Return self <> rhs.

__sub__(rhs: Angle) Angle
__sub__(rhs: AngleBounds) AngleBounds
__sub__(rhs: AngleCurve) AngleCurve

Return self - rhs.

__mul__(rhs: float) Angle
__mul__(rhs: Bounds) AngleBounds
__mul__(rhs: Curve) AngleCurve

Return self * rhs.

__truediv__(rhs: float) Angle
__truediv__(rhs: Angle) float
__truediv__(rhs: Bounds) AngleBounds
__truediv__(rhs: AngleBounds) Bounds
__truediv__(rhs: Curve) AngleCurve
__truediv__(rhs: AngleCurve) Curve

Return self / rhs.

__floordiv__(rhs: Angle) int

Return self // rhs.

__mod__(rhs: Angle) Angle

Return self % rhs.

__rmul__(lhs: float) Angle

Return lhs * self.

class opensolid.AngleBounds

A range of angle values, with a lower bound and upper bound.

static constant(value: Angle) AngleBounds

Construct a zero-width bounding range containing a single value.

static zero_to(value: Angle) AngleBounds

Create a bounding range with zero as one of its endpoints and the given value as the other.

static symmetric(*, width: Angle) AngleBounds

Create a bounding range symmetric about zero, with the given width.

The lower bound of the range will be -w/2 and the upper bound will be w/2.

static hull(values: list[Angle]) AngleBounds

Build a bounding range containing all values in the given non-empty list.

static aggregate(bounds: list[AngleBounds]) AngleBounds

Build a bounding range containing all ranges in the given non-empty list.

property endpoints: tuple[Angle, Angle]

Get the lower and upper bounds of a range.

property lower: Angle

Get the lower bound of a range.

property upper: Angle

Get the upper bound of a range.

intersection(other: AngleBounds) AngleBounds | None

Attempt to find the intersection of two bounding ranges.

includes(value: Angle) bool

Check if a given value is included in a bounding range.

Note that this does not use a tolerance, so use with care - for example, a value just outside the range (due to numerical roundoff) will be reported as not included.

contains(other: AngleBounds) bool

Check if one bounding range contains another.

Note that this does not use a tolerance, so use with care - for example, a range that extends just outside another range (due to numerical roundoff) will be reported as not contained by that range.

__add__(rhs: AngleBounds) AngleBounds
__add__(rhs: Angle) AngleBounds

Return self <> rhs.

__sub__(rhs: AngleBounds) AngleBounds
__sub__(rhs: Angle) AngleBounds

Return self - rhs.

__mul__(rhs: float) AngleBounds
__mul__(rhs: Bounds) AngleBounds

Return self * rhs.

__truediv__(rhs: float) AngleBounds
__truediv__(rhs: AngleBounds) Bounds
__truediv__(rhs: Angle) Bounds
__truediv__(rhs: Bounds) AngleBounds

Return self / rhs.

__rmul__(lhs: float) AngleBounds

Return lhs * self.

class opensolid.AngleCurve

A parametric curve definining an angle in terms of a parameter value.

zero: AngleCurve = <opensolid.AngleCurve object>

A curve equal to zero everywhere.

static constant(value: Angle) AngleCurve

Create a curve with the given constant value.

static line(start: Angle, end: Angle) AngleCurve

Create a curve that linearly interpolates from the first value to the second.

sin() Curve

Compute the sine of a curve.

cos() Curve

Compute the cosine of a curve.

evaluate(parameter_value: float) Angle

Evaluate a curve at a given parameter value.

The parameter value should be between 0 and 1.

zeros() list[Zero]

Find all points at which the given curve is zero.

This includes not only points where the curve crosses zero, but also where it is tangent to zero. For example, y=x-3 crosses zero at x=3, while y=(x-3)^2 is tangent to zero at x=3.

We define y=x-3 as having a zero of order 0 at x=3, since only the “derivative of order zero” (the curve itself) is zero at that point. Similarly, y=(x-3)^2 has a zero of order 1 at x=3, since the first derivative (but not the second derivative) is zero at that point.

Currently, this function up to third-order zeros (e.g. y=x^4 has a third-order zero at x=0, since everything up to the third derivative is zero at x=0).

The current tolerance is used to determine whether a given point should be considered a zero, and of what order. For example, the curve y=x^2-0.0001 is exactly zero at x=0.01 and x=-0.01. However, note that the curve is also very close to zero at x=0, and at that point the first derivative is also zero. In many cases, it is reasonable to assume that the 0.0001 is an artifact of numerical roundoff, and the curve actually has a single zero of order 1 at x=0. The current tolerance is used to choose which case to report. In this example, a tolerance of 0.000001 would mean that we consider 0.0001 a meaningful value (not just roundoff), so we would end up reporting two order-0 zeros at x=0.01 and x=-0.01. On the other hand, a tolerance of 0.01 would mean that we consider 0.0001 as just roundoff error, so we would end up reporting a single order-1 zero at x=0 (the point at which the first derivative is zero).

is_zero() bool

Check if a curve is zero everywhere, within the current tolerance.

__add__(rhs: AngleCurve) AngleCurve
__add__(rhs: Angle) AngleCurve

Return self <> rhs.

__sub__(rhs: AngleCurve) AngleCurve
__sub__(rhs: Angle) AngleCurve

Return self - rhs.

__mul__(rhs: float) AngleCurve
__mul__(rhs: Curve) AngleCurve

Return self * rhs.

__truediv__(rhs: float) AngleCurve
__truediv__(rhs: AngleCurve) Curve
__truediv__(rhs: Angle) Curve
__truediv__(rhs: Curve) AngleCurve

Return self / rhs.

__rmul__(lhs: float) AngleCurve

Return lhs * self.

class opensolid.Area

An area in square meters, square inches etc.

Represented internally as a value in square meters.

zero: Area = Area.square_meters(0.0)

The zero value.

static interpolate(start: Area, end: Area, parameter_value: float) Area

Interpolate from one value to another, based on a parameter that ranges from 0 to 1.

static steps(start: Area, end: Area, n: int) list[Area]

Interpolate between two values by subdividing into the given number of steps.

The result is an empty list if the given number of steps is zero (or negative). Otherwise, the number of values in the resulting list will be equal to one plus the number of steps. For example, for one step the returned values will just be the given start and end values; for two steps the returned values will be the start value, the midpoint and then the end value.

static leading(start: Area, end: Area, n: int) list[Area]

Interpolate between two values like ‘steps’, but skip the first value.

static trailing(start: Area, end: Area, n: int) list[Area]

Interpolate between two values like ‘steps’, but skip the last value.

static in_between(start: Area, end: Area, n: int) list[Area]

Interpolate between two values like ‘steps’, but skip the first and last values.

static midpoints(start: Area, end: Area, n: int) list[Area]

Subdivide a given range into the given number of steps, and return the midpoint of each step.

This can be useful if you want to sample a curve or other function at the midpoint of several intervals.

static square_meters(value: float) Area

Construct an area from a number of square meters.

static square_inches(value: float) Area

Construct an area from a number of square inches.

in_square_meters() float

Convert an area to a number of square meters.

in_square_inches() float

Convert an area to a number of square inches.

is_zero() bool

Check if an area is zero, within the current tolerance.

__eq__(other: object) bool

Return self == other.

Note that this is an exact comparison; for a tolerant comparison (one which will return true if two values are almost equal) you’ll likely want to use an is_zero() method instead.

__lt__(other: Area) bool

Return self < other.

__le__(other: Area) bool

Return self <= other.

__ge__(other: Area) bool

Return self >= other.

__gt__(other: Area) bool

Return self > other.

__add__(rhs: Area) Area
__add__(rhs: AreaBounds) AreaBounds
__add__(rhs: AreaCurve) AreaCurve

Return self <> rhs.

__sub__(rhs: Area) Area
__sub__(rhs: AreaBounds) AreaBounds
__sub__(rhs: AreaCurve) AreaCurve

Return self - rhs.

__mul__(rhs: float) Area
__mul__(rhs: Bounds) AreaBounds
__mul__(rhs: Curve) AreaCurve
__mul__(rhs: Direction2d) AreaVector2d
__mul__(rhs: Vector2d) AreaVector2d

Return self * rhs.

__truediv__(rhs: float) Area
__truediv__(rhs: Area) float
__truediv__(rhs: Length) Length
__truediv__(rhs: Bounds) AreaBounds
__truediv__(rhs: LengthBounds) LengthBounds
__truediv__(rhs: AreaBounds) Bounds
__truediv__(rhs: Curve) AreaCurve
__truediv__(rhs: LengthCurve) LengthCurve
__truediv__(rhs: AreaCurve) Curve

Return self / rhs.

__floordiv__(rhs: Area) int

Return self // rhs.

__mod__(rhs: Area) Area

Return self % rhs.

__rmul__(lhs: float) Area

Return lhs * self.

class opensolid.AreaBounds

A range of area values, with a lower bound and upper bound.

static constant(value: Area) AreaBounds

Construct a zero-width bounding range containing a single value.

static zero_to(value: Area) AreaBounds

Create a bounding range with zero as one of its endpoints and the given value as the other.

static symmetric(*, width: Area) AreaBounds

Create a bounding range symmetric about zero, with the given width.

The lower bound of the range will be -w/2 and the upper bound will be w/2.

static hull(values: list[Area]) AreaBounds

Build a bounding range containing all values in the given non-empty list.

static aggregate(bounds: list[AreaBounds]) AreaBounds

Build a bounding range containing all ranges in the given non-empty list.

property endpoints: tuple[Area, Area]

Get the lower and upper bounds of a range.

property lower: Area

Get the lower bound of a range.

property upper: Area

Get the upper bound of a range.

intersection(other: AreaBounds) AreaBounds | None

Attempt to find the intersection of two bounding ranges.

includes(value: Area) bool

Check if a given value is included in a bounding range.

Note that this does not use a tolerance, so use with care - for example, a value just outside the range (due to numerical roundoff) will be reported as not included.

contains(other: AreaBounds) bool

Check if one bounding range contains another.

Note that this does not use a tolerance, so use with care - for example, a range that extends just outside another range (due to numerical roundoff) will be reported as not contained by that range.

__add__(rhs: AreaBounds) AreaBounds
__add__(rhs: Area) AreaBounds

Return self <> rhs.

__sub__(rhs: AreaBounds) AreaBounds
__sub__(rhs: Area) AreaBounds

Return self - rhs.

__mul__(rhs: float) AreaBounds
__mul__(rhs: Bounds) AreaBounds

Return self * rhs.

__truediv__(rhs: float) AreaBounds
__truediv__(rhs: AreaBounds) Bounds
__truediv__(rhs: Length) LengthBounds
__truediv__(rhs: Area) Bounds
__truediv__(rhs: Bounds) AreaBounds
__truediv__(rhs: LengthBounds) LengthBounds

Return self / rhs.

__rmul__(lhs: float) AreaBounds

Return lhs * self.

class opensolid.AreaCurve

A parametric curve definining an area in terms of a parameter value.

zero: AreaCurve = <opensolid.AreaCurve object>

A curve equal to zero everywhere.

static constant(value: Area) AreaCurve

Create a curve with the given constant value.

static line(start: Area, end: Area) AreaCurve

Create a curve that linearly interpolates from the first value to the second.

sqrt() LengthCurve

Compute the square root of a curve.

evaluate(parameter_value: float) Area

Evaluate a curve at a given parameter value.

The parameter value should be between 0 and 1.

zeros() list[Zero]

Find all points at which the given curve is zero.

This includes not only points where the curve crosses zero, but also where it is tangent to zero. For example, y=x-3 crosses zero at x=3, while y=(x-3)^2 is tangent to zero at x=3.

We define y=x-3 as having a zero of order 0 at x=3, since only the “derivative of order zero” (the curve itself) is zero at that point. Similarly, y=(x-3)^2 has a zero of order 1 at x=3, since the first derivative (but not the second derivative) is zero at that point.

Currently, this function up to third-order zeros (e.g. y=x^4 has a third-order zero at x=0, since everything up to the third derivative is zero at x=0).

The current tolerance is used to determine whether a given point should be considered a zero, and of what order. For example, the curve y=x^2-0.0001 is exactly zero at x=0.01 and x=-0.01. However, note that the curve is also very close to zero at x=0, and at that point the first derivative is also zero. In many cases, it is reasonable to assume that the 0.0001 is an artifact of numerical roundoff, and the curve actually has a single zero of order 1 at x=0. The current tolerance is used to choose which case to report. In this example, a tolerance of 0.000001 would mean that we consider 0.0001 a meaningful value (not just roundoff), so we would end up reporting two order-0 zeros at x=0.01 and x=-0.01. On the other hand, a tolerance of 0.01 would mean that we consider 0.0001 as just roundoff error, so we would end up reporting a single order-1 zero at x=0 (the point at which the first derivative is zero).

is_zero() bool

Check if a curve is zero everywhere, within the current tolerance.

__add__(rhs: AreaCurve) AreaCurve
__add__(rhs: Area) AreaCurve

Return self <> rhs.

__sub__(rhs: AreaCurve) AreaCurve
__sub__(rhs: Area) AreaCurve

Return self - rhs.

__mul__(rhs: float) AreaCurve
__mul__(rhs: Curve) AreaCurve

Return self * rhs.

__truediv__(rhs: float) AreaCurve
__truediv__(rhs: AreaCurve) Curve
__truediv__(rhs: Length) LengthCurve
__truediv__(rhs: Area) Curve
__truediv__(rhs: Curve) AreaCurve
__truediv__(rhs: LengthCurve) LengthCurve

Return self / rhs.

__rmul__(lhs: float) AreaCurve

Return lhs * self.

class opensolid.AreaVector2d

A vector in 2D with units of area.

zero: AreaVector2d = AreaVector2d(Area.square_meters(0.0),Area.square_meters(0.0))

The zero vector.

static x(x_component: Area) AreaVector2d

Construct a vector from just an X component.

The Y component will be set to zero.

static y(y_component: Area) AreaVector2d

Construct a vector from just a Y component.

The X component will be set to zero.

static polar(magnitude: Area, angle: Angle) AreaVector2d

Construct a vector from its magnitude (length) and angle.

static square_meters(x_component: float, y_component: float) AreaVector2d

Construct a vector from its X and Y components given in square meters.

property components: tuple[Area, Area]

Get the X and Y components of a vector as a tuple.

property x_component: Area

Get the X component of a vector.

property y_component: Area

Get the Y component of a vector.

property angle: Angle

Get the angle of a vector.

The angle is measured counterclockwise from the positive X axis, so:

  • A vector in the positive X direction has an angle of zero.

  • A vector in the positive Y direction has an angle of 90 degrees.

  • A vector in the negative Y direction has an angle of -90 degrees.

  • It is not defined whether a vector exactly in the negative X direction has an angle of -180 or +180 degrees. (Currently it is reported as having an angle of +180 degrees, but this should not be relied upon.)

The returned angle will be between -180 and +180 degrees.

direction() Direction2d

Attempt to get the direction of a vector.

The current tolerance will be used to check if the vector is zero (and therefore does not have a direction).

normalize() Vector2d

Normalize a vector.

If the original vector is exactly zero, then the result will be zero as well. Otherwise, the result will be a unit vector.

angle_to(other: AreaVector2d) Angle

Measure the signed angle from one vector to another.

The angle will be measured counterclockwise from the first vector to the second, and will always be between -180 and +180 degrees.

is_zero() bool

Check if an area vector is zero, within the current tolerance.

__add__(rhs: AreaVector2d) AreaVector2d

Return self <> rhs.

__sub__(rhs: AreaVector2d) AreaVector2d

Return self - rhs.

__mul__(rhs: float) AreaVector2d

Return self * rhs.

__truediv__(rhs: float) AreaVector2d
__truediv__(rhs: Length) Displacement2d
__truediv__(rhs: Area) Vector2d

Return self / rhs.

dot(rhs: Vector2d) Area

Compute the dot product of two vector-like values.

cross(rhs: Vector2d) Area

Compute the cross product of two vector-like values.

__rmul__(lhs: float) AreaVector2d

Return lhs * self.

class opensolid.AreaVector3d

A vector in 3D with units of area.

zero: AreaVector3d = <opensolid.AreaVector3d object>

The zero vector.

static xyz(convention: Convention3d, components: tuple[Area, Area, Area]) AreaVector3d

Construct a vector from its XYZ components, given the coordinate convention to use.

static z_up(x_component: Area, y_component: Area, z_component: Area) AreaVector3d

Construct a vector from its XYZ components, using a Z-up convention.

This is a convention where positive X is rightward, positive Y is forward and positive Z is upward.

static y_up(x_component: Area, y_component: Area, z_component: Area) AreaVector3d

Construct a vector from its XYZ components, using a Y-up convention.

This is a convention where positive X is leftward, positive Y is upward, and positive Z is forward.

components(convention: Convention3d) tuple[Area, Area, Area]

Get the XYZ components of a vector, given an XYZ coordinate convention to use.

z_up_components() tuple[Area, Area, Area]

Get the XYZ components of a vector using a Z-up coordinate convention.

This is a convention where positive X is rightward, positive Y is forward and positive Z is upward.

y_up_components() tuple[Area, Area, Area]

Get the XYZ components of a vector using a Y-up coordinate convention.

This is a convention where positive X is leftward, positive Y is upward, and positive Z is forward.

direction() Direction3d

Attempt to get the direction of a vector.

The current tolerance will be used to check if the vector is zero (and therefore does not have a direction).

is_zero() bool

Check if an area vector is zero, within the current tolerance.

rotate_in(direction: Direction3d, angle: Angle) AreaVector3d

Rotate a vector in a given direction.

This is equivalent to rotating around an axis with the given direction.

rotate_around(axis: Axis3d, angle: Angle) AreaVector3d

Rotate around the given axis by the given angle.

mirror_in(direction: Direction3d) AreaVector3d

Mirror in a particular direction.

This is equivalent to mirroring across a plane with the given normal direction.

mirror_across(plane: Plane3d) AreaVector3d

Mirror across the given plane.

scale_in(direction: Direction3d, scale: float) AreaVector3d

Scale (stretch) in the given direction by the given scaling factor.

This is equivalent to scaling along an axis with the given direction.

scale_along(axis: Axis3d, scale: float) AreaVector3d

Scale (stretch) along the given axis by the given scaling factor.

place_in(frame: Frame3d) AreaVector3d

Convert a vectr defined in local coordinates to one defined in global coordinates.

relative_to(frame: Frame3d) AreaVector3d

Convert a vector defined in global coordinates to one defined in local coordinates.

__add__(rhs: AreaVector3d) AreaVector3d

Return self <> rhs.

__sub__(rhs: AreaVector3d) AreaVector3d

Return self - rhs.

__mul__(rhs: float) AreaVector3d

Return self * rhs.

__truediv__(rhs: float) AreaVector3d
__truediv__(rhs: Length) Displacement3d
__truediv__(rhs: Area) Vector3d

Return self / rhs.

dot(rhs: Vector3d) Area

Compute the dot product of two vector-like values.

cross(rhs: Vector3d) AreaVector3d

Compute the cross product of two vector-like values.

__rmul__(lhs: float) AreaVector3d

Return lhs * self.

class opensolid.Axis2d

An axis in 2D, defined by an origin point and direction.

x: Axis2d = <opensolid.Axis2d object>

The X axis.

y: Axis2d = <opensolid.Axis2d object>

The Y axis.

property origin_point: Point2d

Get the origin point of an axis.

property direction: Direction2d

Get the direction of an axis.

mirror_across(axis: Axis2d) Axis2d

Mirror across the given axis.

translate_by(displacement: Displacement2d) Axis2d

Translate by the given displacement.

translate_in(direction: Direction2d, distance: Length) Axis2d

Translate in the given direction by the given distance.

translate_along(axis: Axis2d, distance: Length) Axis2d

Translate along the given axis by the given distance.

rotate_around(point: Point2d, angle: Angle) Axis2d

Rotate around the given point by the given angle.

class opensolid.Axis3d

An axis in 3D, defined by an origin point and direction.

property origin_point: Point3d

Get the origin point of an axis.

property direction: Direction3d

Get the direction of an axis.

normal_plane() Plane3d

Construct a plane normal (perpendicular) to the given axis.

The origin point of the plane will be the origin point of the axis, and the normal direction of the plane will be the direction of the axis. The X and Y directions of the plane will be chosen arbitrarily.

move_to(point: Point3d) Axis3d

Move an axis so that its origin point is the given point.

The direction of the axis will remain unchanged.

reverse() Axis3d

Reverse an axis (negate/reverse its direction).

The origin point of the axis will remain unchanged.

place_in(frame: Frame3d) Axis3d

Convert an axis defined in local coordinates to one defined in global coordinates.

relative_to(frame: Frame3d) Axis3d

Convert an axis defined in global coordinates to one defined in local coordinates.

mirror_across(plane: Plane3d) Axis3d

Mirror across the given plane.

translate_by(displacement: Displacement3d) Axis3d

Translate by the given displacement.

translate_in(direction: Direction3d, distance: Length) Axis3d

Translate in the given direction by the given distance.

translate_along(axis: Axis3d, distance: Length) Axis3d

Translate along the given axis by the given distance.

rotate_around(axis: Axis3d, angle: Angle) Axis3d

Rotate around the given axis by the given angle.

class opensolid.Body3d

A solid body in 3D, defined by a set of boundary surfaces.

static extruded(sketch_plane: Plane3d, profile: Region2d, start: Length, end: Length) Body3d

Create an extruded body from a sketch plane and profile.

static revolved(sketch_plane: Plane3d, profile: Region2d, axis: Axis2d, angle: Angle) Body3d

Create a revolved body from a sketch plane and profile.

Note that the revolution profile and revolution axis are both defined within the given sketch plane.

A positive angle will result in a counterclockwise revolution around the axis, and a negative angle will result in a clockwise revolution.

static block(bounding_box: Bounds3d) Body3d

Create a rectangular block body.

Fails if the given bounds are empty (the length, width, or height is zero).

static sphere(*, center_point: Point3d, diameter: Length) Body3d

Create a sphere with the given center point and diameter.

Fails if the diameter is zero.

static cylinder(start_point: Point3d, end_point: Point3d, *, diameter: Length) Body3d

Create a cylindrical body from a start point, end point and diameter.

Fails if the cylinder length or diameter is zero.

static cylinder_along(axis: Axis3d, start: Length, end: Length, *, diameter: Length) Body3d

Create a cylindrical body along a given axis.

In addition to the axis itself, you will need to provide:

  • Where along the axis the cylinder starts and ends (given as a range of distances along the axis).

  • The cylinder diameter.

Failes if the cylinder length or diameter is zero.

place_in(frame: Frame3d) Body3d

Convert a body defined in local coordinates to one defined in global coordinates.

relative_to(frame: Frame3d) Body3d

Convert a body defined in global coordinates to one defined in local coordinates.

write_stl(path: str, convention: Convention3d, resolution: Resolution) None

Write a body to a binary STL file, using units of millimeters.

write_mitsuba(path: str, resolution: Resolution) None

Write a body to Mitsuba ‘serialized’ file.

class opensolid.Bounds

A range of unitless values, with a lower bound and upper bound.

unit_interval: Bounds = Bounds(0.0,1.0)

The bounding range with endoints [0,1].

static constant(value: float) Bounds

Construct a zero-width bounding range containing a single value.

static zero_to(value: float) Bounds

Create a bounding range with zero as one of its endpoints and the given value as the other.

static symmetric(*, width: float) Bounds

Create a bounding range symmetric about zero, with the given width.

The lower bound of the range will be -w/2 and the upper bound will be w/2.

static hull(values: list[float]) Bounds

Build a bounding range containing all values in the given non-empty list.

static aggregate(bounds: list[Bounds]) Bounds

Build a bounding range containing all ranges in the given non-empty list.

property endpoints: tuple[float, float]

Get the lower and upper bounds of a range.

property lower: float

Get the lower bound of a range.

property upper: float

Get the upper bound of a range.

intersection(other: Bounds) Bounds | None

Attempt to find the intersection of two bounding ranges.

includes(value: float) bool

Check if a given value is included in a bounding range.

Note that this does not use a tolerance, so use with care - for example, a value just outside the range (due to numerical roundoff) will be reported as not included.

contains(other: Bounds) bool

Check if one bounding range contains another.

Note that this does not use a tolerance, so use with care - for example, a range that extends just outside another range (due to numerical roundoff) will be reported as not contained by that range.

__add__(rhs: float) Bounds
__add__(rhs: Bounds) Bounds

Return self <> rhs.

__sub__(rhs: float) Bounds
__sub__(rhs: Bounds) Bounds

Return self - rhs.

__mul__(rhs: float) Bounds
__mul__(rhs: Bounds) Bounds
__mul__(rhs: Length) LengthBounds
__mul__(rhs: Area) AreaBounds
__mul__(rhs: Angle) AngleBounds
__mul__(rhs: LengthBounds) LengthBounds
__mul__(rhs: AreaBounds) AreaBounds
__mul__(rhs: AngleBounds) AngleBounds

Return self * rhs.

__truediv__(rhs: float) Bounds
__truediv__(rhs: Bounds) Bounds

Return self / rhs.

__radd__(lhs: float) Bounds

Return lhs <> self.

__rsub__(lhs: float) Bounds

Return lhs - self.

__rmul__(lhs: float) Bounds

Return lhs * self.

__rtruediv__(lhs: float) Bounds

Return lhs / self.

class opensolid.Bounds2d

A bounding box in 2D.

static constant(point: Point2d) Bounds2d

Construct a zero-size bounding box containing a single point.

static from_corners(first_point: Point2d, second_point: Point2d) Bounds2d

Construct a bounding box from two corner points.

static hull(points: list[Point2d]) Bounds2d

Construct a bounding box containing all vertices in the given non-empty list.

static aggregate(bounds: list[Bounds2d]) Bounds2d

Construct a bounding box containing all bounding boxes in the given non-empty list.

property coordinates: tuple[LengthBounds, LengthBounds]

Get the X and Y coordinate bounds of a bounding box.

property x_coordinate: LengthBounds

Get the X coordinate bounds of a bounding box.

property y_coordinate: LengthBounds

Get the Y coordinate bounds of a bounding box.

scale_along(axis: Axis2d, scale: float) Bounds2d

Scale (stretch) along the given axis by the given scaling factor.

scale_about(point: Point2d, scale: float) Bounds2d

Scale uniformly about the given point by the given scaling factor.

mirror_across(axis: Axis2d) Bounds2d

Mirror across the given axis.

translate_by(displacement: Displacement2d) Bounds2d

Translate by the given displacement.

translate_in(direction: Direction2d, distance: Length) Bounds2d

Translate in the given direction by the given distance.

translate_along(axis: Axis2d, distance: Length) Bounds2d

Translate along the given axis by the given distance.

rotate_around(point: Point2d, angle: Angle) Bounds2d

Rotate around the given point by the given angle.

__add__(rhs: Displacement2d) Bounds2d

Return self <> rhs.

__sub__(rhs: Displacement2d) Bounds2d

Return self - rhs.

class opensolid.Bounds3d

A bounding box in 3D.

static constant(point: Point3d) Bounds3d

Construct a zero-size bounding box containing a single point.

static from_corners(first_point: Point3d, second_point: Point3d) Bounds3d

Construct a bounding box from two corner points.

static hull(points: list[Point3d]) Bounds3d

Construct a bounding box containing all vertices in the given non-empty list.

static aggregate(bounds: list[Bounds3d]) Bounds3d

Construct a bounding box containing all bounding boxes in the given non-empty list.

coordinates(convention: Convention3d) tuple[LengthBounds, LengthBounds, LengthBounds]

Get the XYZ coordinate ranges of a bounding box, given an XYZ coordinate convention to use.

scale_along(axis: Axis3d, scale: float) Bounds3d

Scale (stretch) along the given axis by the given scaling factor.

scale_about(point: Point3d, scale: float) Bounds3d

Scale uniformly about the given point by the given scaling factor.

mirror_across(plane: Plane3d) Bounds3d

Mirror across the given plane.

translate_by(displacement: Displacement3d) Bounds3d

Translate by the given displacement.

translate_in(direction: Direction3d, distance: Length) Bounds3d

Translate in the given direction by the given distance.

translate_along(axis: Axis3d, distance: Length) Bounds3d

Translate along the given axis by the given distance.

rotate_around(axis: Axis3d, angle: Angle) Bounds3d

Rotate around the given axis by the given angle.

__add__(rhs: Displacement3d) Bounds3d

Return self <> rhs.

__sub__(rhs: Displacement3d) Bounds3d

Return self - rhs.

class opensolid.Camera3d

A perspective or orthographic camera in 3D.

static look_at(*, eye_point: Point3d, focal_point: Point3d, projection: Projection) Camera3d

Construct a camera at a given point, looking at a given focal point.

The camera will be oriented such that its local up direction will be as close as possible to the global up direction.

static orbit(*, focal_point: Point3d, azimuth: Angle, elevation: Angle, distance: Length, projection: Projection) Camera3d

Construct a camera orbiting around a given focal point, a given distance away.

The azimuth is the horizontal angle towards the camera from the focal point, measured clockwise from the global forward direction. The elevation is the vertical angle towards the camera from the focal point, measure upwards from the global top plane.

static perspective(*, vertical_fov: Angle) Projection

Define a perspective projection with a given vertical field of view.

static orthographic(*, viewport_height: Length) Projection

Define an orthographic projection with a given viewport height.

class Projection

What kind of projection (perspective or orthographic) a camera should use.

class opensolid.Color

An RGB color value.

red: Color = Color.rgb_int(204,0,0)

Scarlet Red from the Tango icon theme.

dark_red: Color = Color.rgb_int(164,0,0)

Dark Scarlet Red from the Tango icon theme.

light_orange: Color = Color.rgb_int(252,175,62)

Light Orange from the Tango icon theme.

orange: Color = Color.rgb_int(245,121,0)

Orange from the Tango icon theme.

dark_orange: Color = Color.rgb_int(206,92,0)

Dark Orange from the Tango icon theme.

light_yellow: Color = Color.rgb_int(255,233,79)

Light Butter from the Tango icon theme.

yellow: Color = Color.rgb_int(237,212,0)

Butter from the Tango icon theme.

dark_yellow: Color = Color.rgb_int(196,160,0)

Dark Butter from the Tango icon theme.

light_green: Color = Color.rgb_int(138,226,52)

Light Chameleon from the Tango icon theme.

green: Color = Color.rgb_int(115,210,22)

Chameleon from the Tango icon theme.

dark_green: Color = Color.rgb_int(78,154,6)

Dark Chameleon from the Tango icon theme.

light_blue: Color = Color.rgb_int(114,159,207)

Light Sky Blue from the Tango icon theme.

blue: Color = Color.rgb_int(52,101,164)

Sky Blue from the Tango icon theme.

dark_blue: Color = Color.rgb_int(32,74,135)

Dark Sky Blue from the Tango icon theme.

light_purple: Color = Color.rgb_int(173,127,168)

Light Plum from the Tango icon theme.

purple: Color = Color.rgb_int(117,80,123)

Plum from the Tango icon theme.

dark_purple: Color = Color.rgb_int(92,53,102)

Dark Plum from the Tango icon theme.

light_brown: Color = Color.rgb_int(233,185,110)

Light Chocolate from the Tango icon theme.

brown: Color = Color.rgb_int(193,125,17)

Chocolate from the Tango icon theme.

dark_brown: Color = Color.rgb_int(143,89,2)

Dark Chocolate from the Tango icon theme.

black: Color = Color.rgb_int(0,0,0)

Black.

white: Color = Color.rgb_int(255,255,255)

White.

light_grey: Color = Color.rgb_int(238,238,236)

Aluminium 1/6 from the Tango icon theme.

grey: Color = Color.rgb_int(211,215,207)

Aluminium 2/6 from the Tango icon theme.

dark_grey: Color = Color.rgb_int(186,189,182)

Aluminium 3/6 from the Tango icon theme.

light_gray: Color = Color.rgb_int(238,238,236)

Aluminium 1/6 from the Tango icon theme.

gray: Color = Color.rgb_int(211,215,207)

Aluminium 2/6 from the Tango icon theme.

dark_gray: Color = Color.rgb_int(186,189,182)

Aluminium 3/6 from the Tango icon theme.

light_charcoal: Color = Color.rgb_int(136,138,133)

Aluminium 4/6 from the Tango icon theme.

charcoal: Color = Color.rgb_int(85,87,83)

Aluminium 5/6 from the Tango icon theme.

dark_charcoal: Color = Color.rgb_int(46,52,54)

Aluminium 6/6 from the Tango icon theme.

static rgb_float(red: float, green: float, blue: float) Color

Construct a color from its RGB components, in the range [0,1].

static rgb_int(red: int, green: int, blue: int) Color

Construct a color from its RGB components, in the range [0,255].

static hsl(hue: Angle, saturation: float, lightness: float) Color

Construct a color from its hue, saturation and lightness values.

static from_hex(hex_string: str) Color

Construct a color from a hex string such as ‘#f3f3f3’ or ‘f3f3f3’.

property rgb_float_components: tuple[float, float, float]

Get the RGB components of a color as values in the range [0,1].

property rgb_int_components: tuple[int, int, int]

Get the RGB components of a color as values in the range [0,255].

to_hex() str

Convert a color to a hex string such as ‘#f3f3f3’.

class opensolid.Convention3d

A coordinate convention in 3D space.

This defines which of X, Y and Z mean ‘forward’ or ‘upward’ or ‘rightward’.

y_up: Convention3d = <opensolid.Convention3d object>

A convention where positive X is leftward, positive Y is upward, and positive Z is forward.

This is the convention used by (among other things) the glTF file format.

z_up: Convention3d = <opensolid.Convention3d object>

A convention where positive X is rightward, positive Y is forward and positive Z is upward.

This is the convention used by (among other things) the Blender animation package.

class opensolid.Curve

A parametric curve definining a unitless value in terms of a parameter value.

zero: Curve = <opensolid.Curve object>

A curve equal to zero everywhere.

t: Curve = <opensolid.Curve object>

A curve parameter.

In other words, a curve whose value is equal to its input parameter. When defining parametric curves, you will typically start with ‘Curve.t’ and then use arithmetic operators etc. to build up more complex curves.

static constant(value: float) Curve

Create a curve with the given constant value.

static line(start: float, end: float) Curve

Create a curve that linearly interpolates from the first value to the second.

squared() Curve

Compute the square of a curve.

sqrt() Curve

Compute the square root of a curve.

evaluate(parameter_value: float) float

Evaluate a curve at a given parameter value.

The parameter value should be between 0 and 1.

zeros() list[Zero]

Find all points at which the given curve is zero.

This includes not only points where the curve crosses zero, but also where it is tangent to zero. For example, y=x-3 crosses zero at x=3, while y=(x-3)^2 is tangent to zero at x=3.

We define y=x-3 as having a zero of order 0 at x=3, since only the “derivative of order zero” (the curve itself) is zero at that point. Similarly, y=(x-3)^2 has a zero of order 1 at x=3, since the first derivative (but not the second derivative) is zero at that point.

Currently, this function up to third-order zeros (e.g. y=x^4 has a third-order zero at x=0, since everything up to the third derivative is zero at x=0).

The current tolerance is used to determine whether a given point should be considered a zero, and of what order. For example, the curve y=x^2-0.0001 is exactly zero at x=0.01 and x=-0.01. However, note that the curve is also very close to zero at x=0, and at that point the first derivative is also zero. In many cases, it is reasonable to assume that the 0.0001 is an artifact of numerical roundoff, and the curve actually has a single zero of order 1 at x=0. The current tolerance is used to choose which case to report. In this example, a tolerance of 0.000001 would mean that we consider 0.0001 a meaningful value (not just roundoff), so we would end up reporting two order-0 zeros at x=0.01 and x=-0.01. On the other hand, a tolerance of 0.01 would mean that we consider 0.0001 as just roundoff error, so we would end up reporting a single order-1 zero at x=0 (the point at which the first derivative is zero).

is_zero() bool

Check if a curve is zero everywhere, within the current tolerance.

__add__(rhs: float) Curve
__add__(rhs: Curve) Curve

Return self <> rhs.

__sub__(rhs: float) Curve
__sub__(rhs: Curve) Curve

Return self - rhs.

__mul__(rhs: float) Curve
__mul__(rhs: Curve) Curve
__mul__(rhs: Length) LengthCurve
__mul__(rhs: Area) AreaCurve
__mul__(rhs: Angle) AngleCurve
__mul__(rhs: LengthCurve) LengthCurve
__mul__(rhs: AreaCurve) AreaCurve
__mul__(rhs: AngleCurve) AngleCurve

Return self * rhs.

__truediv__(rhs: float) Curve
__truediv__(rhs: Curve) Curve

Return self / rhs.

__radd__(lhs: float) Curve

Return lhs <> self.

__rsub__(lhs: float) Curve

Return lhs - self.

__rmul__(lhs: float) Curve

Return lhs * self.

__rtruediv__(lhs: float) Curve

Return lhs / self.

class Zero

A point where a given curve is equal to zero.

property location: float

The parameter value at which the curve is zero.

property order: int

The order of the solution: 0 for crossing, 1 for tangent, etc.

property sign: int

The sign of the solution: the sign of the curve to the right of the solution.

class opensolid.Curve2d

A parametric curve in 2D space.

static constant(point: Point2d) Curve2d

Create a degenerate curve that is actually just a single point.

static xy(x_coordinate: LengthCurve, y_coordinate: LengthCurve) Curve2d

Create a curve from its X and Y coordinate curves.

static line(start_point: Point2d, end_point: Point2d) Curve2d

Create a line between two points.

static arc(start_point: Point2d, end_point: Point2d, swept_angle: Angle) Curve2d

Create an arc with the given start point, end point and swept angle.

A positive swept angle means the arc turns counterclockwise (turns to the left), and a negative swept angle means it turns clockwise (turns to the right). For example, an arc with a swept angle of positive 90 degrees is quarter circle that turns to the left.

static polar_arc(*, center_point: Point2d, radius: Length, start_angle: Angle, end_angle: Angle) Curve2d

Create an arc with the given center point, radius, start angle and end angle.

static swept_arc(center_point: Point2d, start_point: Point2d, swept_angle: Angle) Curve2d

Create an arc with the given center point, start point and swept angle.

The start point will be swept around the center point by the given angle.

static corner_arc(corner_point: Point2d, *, incoming: Direction2d, outgoing: Direction2d, radius: Length) Curve2d

Create an arc for rounding off the corner between two straight lines.

static circle(*, center_point: Point2d, diameter: Length) Curve2d

Create a circle with the given center point and diameter.

static bezier(control_points: list[Point2d]) Curve2d

Construct a Bezier curve from its control points.

For example,

> Curve2d.bezier (NonEmpty.four p1 p2 p3 p4))

will return a cubic Bezier curve with the given four control points.

static hermite(start_point: Point2d, start_derivatives: list[Displacement2d], end_point: Point2d, end_derivatives: list[Displacement2d]) Curve2d

Construct a Bezier curve with the given endpoints and derivatives at those endpoints.

For example,

> Curve2d.hermite p1 [v1] p2 [v2]

will result in a cubic spline from @p1@ to @p2@ with first derivative equal to @v1@ at @p1@ and first derivative equal to @v2@ at @p2@.

The numbers of derivatives at each endpoint do not have to be equal; for example,

> Curve2d.hermite p1 [v1] p2 []

will result in a quadratic spline from @p1@ to @p2@ with first derivative at @p1@ equal to @v1@.

In general, the degree of the resulting spline will be equal to 1 plus the total number of derivatives given.

property start_point: Point2d

The start point of the curve.

property end_point: Point2d

The end point of the curve.

property derivative: DisplacementCurve2d

The derivative of the curve.

property x_coordinate: LengthCurve

Get the X coordinate of a 2D curve as a scalar curve.

property y_coordinate: LengthCurve

Get the Y coordinate of a 2D curve as a scalar curve.

evaluate(parameter_value: float) Point2d

Evaluate a curve at a given parameter value.

The parameter value should be between 0 and 1.

reverse() Curve2d

Reverse a curve, so that the start point is the end point and vice versa.

scale_along(axis: Axis2d, scale: float) Curve2d

Scale (stretch) along the given axis by the given scaling factor.

scale_about(point: Point2d, scale: float) Curve2d

Scale uniformly about the given point by the given scaling factor.

mirror_across(axis: Axis2d) Curve2d

Mirror across the given axis.

translate_by(displacement: Displacement2d) Curve2d

Translate by the given displacement.

translate_in(direction: Direction2d, distance: Length) Curve2d

Translate in the given direction by the given distance.

translate_along(axis: Axis2d, distance: Length) Curve2d

Translate along the given axis by the given distance.

rotate_around(point: Point2d, angle: Angle) Curve2d

Rotate around the given point by the given angle.

__add__(rhs: DisplacementCurve2d) Curve2d

Return self <> rhs.

__sub__(rhs: DisplacementCurve2d) Curve2d
__sub__(rhs: Curve2d) DisplacementCurve2d
__sub__(rhs: Point2d) DisplacementCurve2d

Return self - rhs.

class opensolid.Direction2d

A direction in 2D.

This is effectively a type-safe unit vector.

x: Direction2d = Vector2d(1.0,0.0)

The X direction.

y: Direction2d = Vector2d(0.0,1.0)

The Y direction.

static polar(angle: Angle) Direction2d

Construct a direction from an angle.

The angle is measured counterclockwise from the positive X direction, so:

  • An angle of zero corresponds to the positive X direction

  • An angle of 90 degrees corresponds to the positive Y direction

  • An angle of 180 degrees (or -180 degrees) corresponds to the negative X direction

static degrees(value: float) Direction2d

Construct a direction from an angle given in degrees.

See ‘polar’ for details.

static radians(value: float) Direction2d

Construct a direction from an angle given in radians.

See ‘polar’ for details.

property components: tuple[float, float]

Get the XY components of a direction as a tuple.

property x_component: float

Get the X component of a direction.

property y_component: float

Get the Y component of a direction.

rotate_left() Direction2d

Rotate a direction left (counterclockwise) by 90 degrees.

rotate_right() Direction2d

Rotate a direction right (clockwise) by 90 degrees.

class opensolid.Direction3d

A direction in 3D.

This is effectively a type-safe unit vector.

perpendicular_direction() Direction3d

Generate an arbitrary direction perpendicular to the given one.

angle_to(other: Direction3d) Angle

Measure the angle from one direction to another.

The result will always be between 0 and 180 degrees.

rotate_in(direction: Direction3d, angle: Angle) Direction3d

Rotate a direction in a given other direction.

This is equivalent to rotating around an axis with the given direction.

rotate_around(axis: Axis3d, angle: Angle) Direction3d

Rotate around the given axis by the given angle.

mirror_in(direction: Direction3d) Direction3d

Mirror a direction in a given other direction.

This is equivalent to mirroring across a plane with the given normal direction.

mirror_across(plane: Plane3d) Direction3d

Mirror across the given plane.

place_in(frame: Frame3d) Direction3d

Convert a direction defined in local coordinates to one defined in global coordinates.

relative_to(frame: Frame3d) Direction3d

Convert a direction defined in global coordinates to one defined in local coordinates.

class opensolid.Displacement2d

A displacement vector in 2D.

zero: Displacement2d = Displacement2d(Length.meters(0.0),Length.meters(0.0))

The zero vector.

static x(x_component: Length) Displacement2d

Construct a vector from just an X component.

The Y component will be set to zero.

static y(y_component: Length) Displacement2d

Construct a vector from just a Y component.

The X component will be set to zero.

static polar(magnitude: Length, angle: Angle) Displacement2d

Construct a vector from its magnitude (length) and angle.

static meters(x_component: float, y_component: float) Displacement2d

Construct a vector from its X and Y components given in meters.

static centimeters(x_component: float, y_component: float) Displacement2d

Construct a vector from its X and Y components given in centimeters.

static cm(x_component: float, y_component: float) Displacement2d

Construct a vector from its X and Y components given in centimeters.

Short form alias for ‘centimeters’.

static millimeters(x_component: float, y_component: float) Displacement2d

Construct a vector from its X and Y components given in millimeters.

static mm(x_component: float, y_component: float) Displacement2d

Construct a vector from its X and Y components given in millimeters.

Short form alias for ‘millimeters’.

static inches(x_component: float, y_component: float) Displacement2d

Construct a vector from its X and Y components given in inches.

property components: tuple[Length, Length]

Get the X and Y components of a vector as a tuple.

property x_component: Length

Get the X component of a vector.

property y_component: Length

Get the Y component of a vector.

property angle: Angle

Get the angle of a vector.

The angle is measured counterclockwise from the positive X axis, so:

  • A vector in the positive X direction has an angle of zero.

  • A vector in the positive Y direction has an angle of 90 degrees.

  • A vector in the negative Y direction has an angle of -90 degrees.

  • It is not defined whether a vector exactly in the negative X direction has an angle of -180 or +180 degrees. (Currently it is reported as having an angle of +180 degrees, but this should not be relied upon.)

The returned angle will be between -180 and +180 degrees.

direction() Direction2d

Attempt to get the direction of a vector.

The current tolerance will be used to check if the vector is zero (and therefore does not have a direction).

normalize() Vector2d

Normalize a vector.

If the original vector is exactly zero, then the result will be zero as well. Otherwise, the result will be a unit vector.

angle_to(other: Displacement2d) Angle

Measure the signed angle from one vector to another.

The angle will be measured counterclockwise from the first vector to the second, and will always be between -180 and +180 degrees.

is_zero() bool

Check if a displacement is zero, within the current tolerance.

__add__(rhs: Displacement2d) Displacement2d

Return self <> rhs.

__sub__(rhs: Displacement2d) Displacement2d

Return self - rhs.

__mul__(rhs: float) Displacement2d
__mul__(rhs: Length) AreaVector2d

Return self * rhs.

__truediv__(rhs: float) Displacement2d
__truediv__(rhs: Length) Vector2d

Return self / rhs.

dot(rhs: Displacement2d) Area
dot(rhs: Vector2d) Length

Compute the dot product of two vector-like values.

cross(rhs: Displacement2d) Area
cross(rhs: Vector2d) Length

Compute the cross product of two vector-like values.

__rmul__(lhs: float) Displacement2d

Return lhs * self.

class opensolid.Displacement3d

A displacement vector in 3D.

zero: Displacement3d = <opensolid.Displacement3d object>

The zero vector.

static xyz(convention: Convention3d, components: tuple[Length, Length, Length]) Displacement3d

Construct a vector from its XYZ components, given the coordinate convention to use.

static z_up(x_component: Length, y_component: Length, z_component: Length) Displacement3d

Construct a vector from its XYZ components, using a Z-up convention.

This is a convention where positive X is rightward, positive Y is forward and positive Z is upward.

static y_up(x_component: Length, y_component: Length, z_component: Length) Displacement3d

Construct a vector from its XYZ components, using a Y-up convention.

This is a convention where positive X is leftward, positive Y is upward, and positive Z is forward.

components(convention: Convention3d) tuple[Length, Length, Length]

Get the XYZ components of a vector, given an XYZ coordinate convention to use.

z_up_components() tuple[Length, Length, Length]

Get the XYZ components of a vector using a Z-up coordinate convention.

This is a convention where positive X is rightward, positive Y is forward and positive Z is upward.

y_up_components() tuple[Length, Length, Length]

Get the XYZ components of a vector using a Y-up coordinate convention.

This is a convention where positive X is leftward, positive Y is upward, and positive Z is forward.

direction() Direction3d

Attempt to get the direction of a vector.

The current tolerance will be used to check if the vector is zero (and therefore does not have a direction).

is_zero() bool

Check if a displacement is zero, within the current tolerance.

rotate_in(direction: Direction3d, angle: Angle) Displacement3d

Rotate a vector in a given direction.

This is equivalent to rotating around an axis with the given direction.

rotate_around(axis: Axis3d, angle: Angle) Displacement3d

Rotate around the given axis by the given angle.

mirror_in(direction: Direction3d) Displacement3d

Mirror in a particular direction.

This is equivalent to mirroring across a plane with the given normal direction.

mirror_across(plane: Plane3d) Displacement3d

Mirror across the given plane.

scale_in(direction: Direction3d, scale: float) Displacement3d

Scale (stretch) in the given direction by the given scaling factor.

This is equivalent to scaling along an axis with the given direction.

scale_along(axis: Axis3d, scale: float) Displacement3d

Scale (stretch) along the given axis by the given scaling factor.

place_in(frame: Frame3d) Displacement3d

Convert a vectr defined in local coordinates to one defined in global coordinates.

relative_to(frame: Frame3d) Displacement3d

Convert a vector defined in global coordinates to one defined in local coordinates.

__add__(rhs: Displacement3d) Displacement3d

Return self <> rhs.

__sub__(rhs: Displacement3d) Displacement3d

Return self - rhs.

__mul__(rhs: float) Displacement3d
__mul__(rhs: Length) AreaVector3d

Return self * rhs.

__truediv__(rhs: float) Displacement3d
__truediv__(rhs: Length) Vector3d

Return self / rhs.

dot(rhs: Displacement3d) Area
dot(rhs: Vector3d) Length

Compute the dot product of two vector-like values.

cross(rhs: Displacement3d) AreaVector3d
cross(rhs: Vector3d) Displacement3d

Compute the cross product of two vector-like values.

__rmul__(lhs: float) Displacement3d

Return lhs * self.

class opensolid.DisplacementCurve2d

A parametric curve defining a 2D displacement vector in terms of a parameter value.

zero: DisplacementCurve2d = <opensolid.DisplacementCurve2d object>

The constant zero vector.

static constant(value: Displacement2d) DisplacementCurve2d

Create a curve with a constant value.

static xy(x_component: LengthCurve, y_component: LengthCurve) DisplacementCurve2d

Create a curve from its X and Y component curves.

evaluate(parameter_value: float) Displacement2d

Evaluate a curve at a given parameter value.

The parameter value should be between 0 and 1.

class opensolid.Drawing2d

A 2D drawing composed of shapes with attributes such as colour and stroke width.

black_stroke: Attribute = <opensolid.Drawing2d.Attribute object>

Black stroke for curves and borders.

no_fill: Attribute = <opensolid.Drawing2d.Attribute object>

Set shapes to have no fill.

static group(drawings: list[Drawing2d]) Drawing2d

Group several drawings into a single drawing.

static group_with(attributes: list[Attribute], drawings: list[Drawing2d]) Drawing2d

Group several drawings into a single drawing, applying the given attributes to the group.

static polygon(vertices: list[Point2d]) Drawing2d

Create a polygon with the given vertices.

static polygon_with(attributes: list[Attribute], vertices: list[Point2d]) Drawing2d

Create a polygon with the given attributes and vertices.

static circle(*, center_point: Point2d, diameter: Length) Drawing2d

Create a circle with the given center point and diameter.

static circle_with(attributes: list[Attribute], *, center_point: Point2d, diameter: Length) Drawing2d

Create a circle with the given attributes, center point and diameter.

static curve(resolution: Resolution, curve: Curve2d) Drawing2d

Draw a curve with the given resolution.

static curve_with(attributes: list[Attribute], resolution: Resolution, curve: Curve2d) Drawing2d

Draw a curve with the given attributes and resolution.

static stroke_color(color: Color) Attribute

Set the stroke color for curves and borders.

static fill_color(color: Color) Attribute

Set the fill color for shapes.

to_svg(view_box: Bounds2d) str

Render a drawing to SVG.

The given bounding box defines the overall size of the drawing; anything outside of this will be cropped.

write_svg(path: str, view_box: Bounds2d) None

Render SVG to a file.

The given bounding box defines the overall size of the drawing; anything outside of this will be cropped.

class Attribute

A drawing attribute such as fill color or stroke width.

class opensolid.Frame3d

A frame of reference in 3D, defined by an origin point and orientation.

world: Frame3d = <opensolid.Frame3d object>

A frame of reference defining a new coordinate system.

static forward(reference_frame: Frame3d) Frame3d

Construct a forward-facing frame relative to a parent/reference frame.

This is just an identical copy of the parent frame, but can be used to define a new/different local space.

static backward(reference_frame: Frame3d) Frame3d

Construct a backward-facing frame relative to a parent/reference frame.

The forward direction of the frame will point backward, the upward direction of the frame will point upward, and the rightward direction of the frame will point leftward (all relative to the parent frame).

static rightward(reference_frame: Frame3d) Frame3d

Construct a rightward-facing frame relative to a parent/reference frame.

The forward direction of the frame will point rightward, the upward direction of the frame will point upward, and the rightward direction of the frame will point backward (all relative to the parent frame).

static leftward(reference_frame: Frame3d) Frame3d

Construct a leftward-facing frame relative to a parent/reference frame.

The forward direction of the frame will point leftward, the upward direction of the frame will point upward, and the rightward direction of the frame will point forward (all relative to the parent frame).

static upward(reference_frame: Frame3d) Frame3d

Construct an upward-facing frame relative to a parent/reference frame.

The forward direction of the frame will point upward, the upward direction of the frame will point forward, and the rightward direction of the frame will point leftward (all relative to the parent frame).

static downward(reference_frame: Frame3d) Frame3d

Construct a downward-facing frame relative to a parent/reference frame.

The forward direction of the frame will point downward, the upward direction of the frame will point upward, and the rightward direction of the frame will point rightward (all relative to the parent frame).

static from_front_plane(plane: Plane3d) Frame3d

Construct a plane from its front plane.

static from_back_plane(plane: Plane3d) Frame3d

Construct a plane from its back plane.

static from_right_plane(plane: Plane3d) Frame3d

Construct a plane from its right plane.

static from_left_plane(plane: Plane3d) Frame3d

Construct a plane from its left plane.

static from_top_plane(plane: Plane3d) Frame3d

Construct a plane from its top plane.

static from_bottom_plane(plane: Plane3d) Frame3d

Construct a plane from its bottom plane.

static align(frame: Frame3d, reference_frame: Frame3d) Frame3d

Compute the relative orientation of two parent frames in order to align two child frames.

Imagine you have one object defined in coordinate system A (“local”), with a particular frame X defined in coordinate system A. Similarly, you have another object defined in coordinate system B (“global”), with a particular frame Y defined in coordinate system B. This function lets you determine the necessary relative alignment between A and B such that the two frames X and Y are aligned with each other. Given the two frames X and Y, this function returns a new frame that defines the necessary orientation of A (“local”) relative to B (“global”).

static mate(frame: Frame3d, reference_frame: Frame3d) Frame3d

Compute the relative orientation of two parent frames in order to “mate” two child frames.

This is the same as ‘align’ except that the two child frames will end up facing towards each other (with reversed forward directions, but the same upward directions) instead of being aligned with each other.

property origin_point: Point3d

Get the origin point of a frame.

property forward_direction: Direction3d

Get the local forward direction of a frame.

property backward_direction: Direction3d

Get the local backward direction of a frame.

property rightward_direction: Direction3d

Get the local rightward direction of a frame.

property leftward_direction: Direction3d

Get the local leftward direction of a frame.

property upward_direction: Direction3d

Get the local upward direction of a frame.

property downward_direction: Direction3d

Get the local downward direction of a frame.

property forward_axis: Axis3d

Get the forward axis of a frame.

property backward_axis: Axis3d

Get the backward axis of a frame.

property rightward_axis: Axis3d

Get the rightward axis of a frame.

property leftward_axis: Axis3d

Get the leftward axis of a frame.

property upward_axis: Axis3d

Get the upward axis of a frame.

property downward_axis: Axis3d

Get the downward axis of a frame.

property front_plane: Plane3d

Construct a locally forward-facing plane from a frame.

The returned plane will have the same origin point as the frame, its normal direction will be the frame’s forward direction, its X direction will be the frame’s leftward direction and its Y direction will be frame’s upward direction.

property back_plane: Plane3d

Construct a locally backward-facing plane from a frame.

The returned plane will have the same origin point as the frame, its normal direction will be the frame’s backward direction, its X direction will be the frame’s rightward direction and its Y direction will be frame’s upward direction.

property right_plane: Plane3d

Construct a locally rightward-facing plane from a frame.

The returned plane will have the same origin point as the frame, its normal direction will be the frame’s rightward direction, its X direction will be the frame’s forward direction and its Y direction will be frame’s upward direction.

property left_plane: Plane3d

Construct a locally leftward-facing plane from a frame.

The returned plane will have the same origin point as the frame, its normal direction will be the frame’s leftward direction, its X direction will be the frame’s backward direction and its Y direction will be frame’s upward direction.

property top_plane: Plane3d

Construct a locally upward-facing plane from a frame.

The returned plane will have the same origin point as the frame, its normal direction will be the frame’s upward direction, its X direction will be the frame’s rightward direction and its Y direction will be frame’s forward direction.

property bottom_plane: Plane3d

Construct a locally downward-facing plane from a frame.

The returned plane will have the same origin point as the frame, its normal direction will be the frame’s downward direction, its X direction will be the frame’s leftward direction and its Y direction will be frame’s forward direction.

property backward_frame: Frame3d

Construct a backward-facing frame relative to a parent/reference frame.

The forward direction of the frame will point backward, the upward direction of the frame will point upward, and the rightward direction of the frame will point leftward (all relative to the parent frame).

property leftward_frame: Frame3d

Construct a leftward-facing frame relative to a parent/reference frame.

The forward direction of the frame will point leftward, the upward direction of the frame will point upward, and the rightward direction of the frame will point forward (all relative to the parent frame).

property rightward_frame: Frame3d

Construct a rightward-facing frame relative to a parent/reference frame.

The forward direction of the frame will point rightward, the upward direction of the frame will point upward, and the rightward direction of the frame will point backward (all relative to the parent frame).

property upward_frame: Frame3d

Construct an upward-facing frame relative to a parent/reference frame.

The forward direction of the frame will point upward, the upward direction of the frame will point forward, and the rightward direction of the frame will point leftward (all relative to the parent frame).

property downward_frame: Frame3d

Construct a downward-facing frame relative to a parent/reference frame.

The forward direction of the frame will point downward, the upward direction of the frame will point upward, and the rightward direction of the frame will point rightward (all relative to the parent frame).

place_in(other_frame: Frame3d) Frame3d

Convert a frame defined in local coordinates to one defined in global coordinates.

relative_to(other_frame: Frame3d) Frame3d

Convert a frame defined in global coordinates to one defined in local coordinates.

inverse() Frame3d

Compute the “inverse” of a given frame.

This is a frame that defines the current global coordinate system in terms of the frame’s local coordinate system, instead of the other way around.

move_to(point: Point3d) Frame3d

Move a frame to a new origin point.

offset_forward_by(distance: Length) Frame3d

Move a frame in its own forward direction by the given distance.

offset_backward_by(distance: Length) Frame3d

Move a frame in its own backward direction by the given distance.

offset_rightward_by(distance: Length) Frame3d

Move a frame in its own rightward direction by the given distance.

offset_leftward_by(distance: Length) Frame3d

Move a frame in its own leftward direction by the given distance.

offset_upward_by(distance: Length) Frame3d

Move a frame in its own upward direction by the given distance.

offset_downward_by(distance: Length) Frame3d

Move a frame in its own downward direction by the given distance.

turn_right_by(angle: Angle) Frame3d

Rotate a frame clockwise around its own upward axis by the given angle.

This rotates the frame’s forward direction toward its rightward direction.

turn_left_by(angle: Angle) Frame3d

Rotate a frame counterclockwise around its own upward axis by the given angle.

This rotates the frame’s forward direction toward its leftward direction.

roll_right_by(angle: Angle) Frame3d

Rotate a frame counterclockwise around its own forward axis by the given angle.

This rotates the frame’s upward direction toward its rightward direction.

roll_left_by(angle: Angle) Frame3d

Rotate a frame clockwise around its own forward axis by the given angle.

This rotates the frame’s upward direction toward its leftward direction.

tilt_up_by(angle: Angle) Frame3d

Rotate a frame counterclockwise around its own rightward axis by the given angle.

This rotates the frame’s forward direction toward its upward direction.

tilt_down_by(angle: Angle) Frame3d

Rotate a frame clockwise around its own rightward axis by the given angle.

This rotates the frame’s forward direction toward its downward direction.

turn_right() Frame3d

Turn a frame right by 90 degrees.

The forward direction of the returned frame will be equal to the rightward direction of the original frame.

turn_left() Frame3d

Turn a frame left by 90 degrees.

The forward direction of the returned frame will be equal to the leftward direction of the original frame.

roll_right() Frame3d

Roll a frame right by 90 degrees.

The upward direction of the returned frame will be equal to the rightward direction of the original frame.

roll_left() Frame3d

Roll a frame left by 90 degrees.

The upward direction of the returned frame will be equal to the leftward direction of the original frame.

tilt_up() Frame3d

Tilt a frame up by 90 degrees.

The forward direction of the returned frame will be equal to the upward direction of the original frame.

tilt_down() Frame3d

Tilt a frame down by 90 degrees.

The forward direction of the returned frame will be equal to the downward direction of the original frame.

translate_by(displacement: Displacement3d) Frame3d

Translate by the given displacement.

translate_in(direction: Direction3d, distance: Length) Frame3d

Translate in the given direction by the given distance.

translate_along(axis: Axis3d, distance: Length) Frame3d

Translate along the given axis by the given distance.

rotate_around(axis: Axis3d, angle: Angle) Frame3d

Rotate around the given axis by the given angle.

class opensolid.Gltf

A glTF model that can be written out to a file.

write_binary(path: str, resolution: Resolution) None

Write a model to a binary glTF file with the given resolution.

class opensolid.Length

A length in millimeters, meters, inches etc.

Represented internally as a value in meters.

zero: Length = Length.meters(0.0)

The zero value.

static interpolate(start: Length, end: Length, parameter_value: float) Length

Interpolate from one value to another, based on a parameter that ranges from 0 to 1.

static steps(start: Length, end: Length, n: int) list[Length]

Interpolate between two values by subdividing into the given number of steps.

The result is an empty list if the given number of steps is zero (or negative). Otherwise, the number of values in the resulting list will be equal to one plus the number of steps. For example, for one step the returned values will just be the given start and end values; for two steps the returned values will be the start value, the midpoint and then the end value.

static leading(start: Length, end: Length, n: int) list[Length]

Interpolate between two values like ‘steps’, but skip the first value.

static trailing(start: Length, end: Length, n: int) list[Length]

Interpolate between two values like ‘steps’, but skip the last value.

static in_between(start: Length, end: Length, n: int) list[Length]

Interpolate between two values like ‘steps’, but skip the first and last values.

static midpoints(start: Length, end: Length, n: int) list[Length]

Subdivide a given range into the given number of steps, and return the midpoint of each step.

This can be useful if you want to sample a curve or other function at the midpoint of several intervals.

static meters(value: float) Length

Construct a length from a number of meters.

static centimeters(value: float) Length

Construct a length from a number of centimeters.

static cm(value: float) Length

Construct a length from a number of centimeters.

Short form alias for ‘centimeters’.

static millimeters(value: float) Length

Construct a length value from a number of millimeters.

static mm(value: float) Length

Construct a length value from a number of millimeters.

Short form alias for ‘millimeters’.

static micrometers(value: float) Length

Construct a length from a number of micrometers.

static nanometers(value: float) Length

Construct a length from a number of nanometers.

static inches(value: float) Length

Construct a length from a number of inches.

static pixels(value: float) Length

Construct a length from a number of CSS pixels.

in_meters() float

Convert a length to a number of meters.

in_centimeters() float

Convert a length to a number of centimeters.

in_millimeters() float

Convert a length to a number of millimeters.

in_micrometers() float

Convert a length to a number of micrometers.

in_nanometers() float

Convert a length to a number of nanometers.

in_inches() float

Convert a length to a number of inches.

in_pixels() float

Convert a length into a number of CSS pixels.

is_zero() bool

Check if a length is zero, within the current tolerance.

__eq__(other: object) bool

Return self == other.

Note that this is an exact comparison; for a tolerant comparison (one which will return true if two values are almost equal) you’ll likely want to use an is_zero() method instead.

__lt__(other: Length) bool

Return self < other.

__le__(other: Length) bool

Return self <= other.

__ge__(other: Length) bool

Return self >= other.

__gt__(other: Length) bool

Return self > other.

__add__(rhs: Length) Length
__add__(rhs: LengthBounds) LengthBounds
__add__(rhs: LengthCurve) LengthCurve

Return self <> rhs.

__sub__(rhs: Length) Length
__sub__(rhs: LengthBounds) LengthBounds
__sub__(rhs: LengthCurve) LengthCurve

Return self - rhs.

__mul__(rhs: float) Length
__mul__(rhs: Length) Area
__mul__(rhs: Bounds) LengthBounds
__mul__(rhs: LengthBounds) AreaBounds
__mul__(rhs: Curve) LengthCurve
__mul__(rhs: LengthCurve) AreaCurve
__mul__(rhs: Direction2d) Displacement2d
__mul__(rhs: Vector2d) Displacement2d
__mul__(rhs: Displacement2d) AreaVector2d

Return self * rhs.

__truediv__(rhs: float) Length
__truediv__(rhs: Length) float
__truediv__(rhs: Bounds) LengthBounds
__truediv__(rhs: LengthBounds) Bounds
__truediv__(rhs: Curve) LengthCurve
__truediv__(rhs: LengthCurve) Curve

Return self / rhs.

__floordiv__(rhs: Length) int

Return self // rhs.

__mod__(rhs: Length) Length

Return self % rhs.

__rmul__(lhs: float) Length

Return lhs * self.

class opensolid.LengthBounds

A range of length values, with a lower bound and upper bound.

static constant(value: Length) LengthBounds

Construct a zero-width bounding range containing a single value.

static zero_to(value: Length) LengthBounds

Create a bounding range with zero as one of its endpoints and the given value as the other.

static symmetric(*, width: Length) LengthBounds

Create a bounding range symmetric about zero, with the given width.

The lower bound of the range will be -w/2 and the upper bound will be w/2.

static hull(values: list[Length]) LengthBounds

Build a bounding range containing all values in the given non-empty list.

static aggregate(bounds: list[LengthBounds]) LengthBounds

Build a bounding range containing all ranges in the given non-empty list.

property endpoints: tuple[Length, Length]

Get the lower and upper bounds of a range.

property lower: Length

Get the lower bound of a range.

property upper: Length

Get the upper bound of a range.

intersection(other: LengthBounds) LengthBounds | None

Attempt to find the intersection of two bounding ranges.

includes(value: Length) bool

Check if a given value is included in a bounding range.

Note that this does not use a tolerance, so use with care - for example, a value just outside the range (due to numerical roundoff) will be reported as not included.

contains(other: LengthBounds) bool

Check if one bounding range contains another.

Note that this does not use a tolerance, so use with care - for example, a range that extends just outside another range (due to numerical roundoff) will be reported as not contained by that range.

__add__(rhs: LengthBounds) LengthBounds
__add__(rhs: Length) LengthBounds

Return self <> rhs.

__sub__(rhs: LengthBounds) LengthBounds
__sub__(rhs: Length) LengthBounds

Return self - rhs.

__mul__(rhs: float) LengthBounds
__mul__(rhs: LengthBounds) AreaBounds
__mul__(rhs: Length) AreaBounds
__mul__(rhs: Bounds) LengthBounds

Return self * rhs.

__truediv__(rhs: float) LengthBounds
__truediv__(rhs: LengthBounds) Bounds
__truediv__(rhs: Length) Bounds
__truediv__(rhs: Bounds) LengthBounds

Return self / rhs.

__rmul__(lhs: float) LengthBounds

Return lhs * self.

class opensolid.LengthCurve

A parametric curve definining a length in terms of a parameter value.

zero: LengthCurve = <opensolid.LengthCurve object>

A curve equal to zero everywhere.

static constant(value: Length) LengthCurve

Create a curve with the given constant value.

static line(start: Length, end: Length) LengthCurve

Create a curve that linearly interpolates from the first value to the second.

squared() AreaCurve

Compute the square of a curve.

evaluate(parameter_value: float) Length

Evaluate a curve at a given parameter value.

The parameter value should be between 0 and 1.

zeros() list[Zero]

Find all points at which the given curve is zero.

This includes not only points where the curve crosses zero, but also where it is tangent to zero. For example, y=x-3 crosses zero at x=3, while y=(x-3)^2 is tangent to zero at x=3.

We define y=x-3 as having a zero of order 0 at x=3, since only the “derivative of order zero” (the curve itself) is zero at that point. Similarly, y=(x-3)^2 has a zero of order 1 at x=3, since the first derivative (but not the second derivative) is zero at that point.

Currently, this function up to third-order zeros (e.g. y=x^4 has a third-order zero at x=0, since everything up to the third derivative is zero at x=0).

The current tolerance is used to determine whether a given point should be considered a zero, and of what order. For example, the curve y=x^2-0.0001 is exactly zero at x=0.01 and x=-0.01. However, note that the curve is also very close to zero at x=0, and at that point the first derivative is also zero. In many cases, it is reasonable to assume that the 0.0001 is an artifact of numerical roundoff, and the curve actually has a single zero of order 1 at x=0. The current tolerance is used to choose which case to report. In this example, a tolerance of 0.000001 would mean that we consider 0.0001 a meaningful value (not just roundoff), so we would end up reporting two order-0 zeros at x=0.01 and x=-0.01. On the other hand, a tolerance of 0.01 would mean that we consider 0.0001 as just roundoff error, so we would end up reporting a single order-1 zero at x=0 (the point at which the first derivative is zero).

is_zero() bool

Check if a curve is zero everywhere, within the current tolerance.

__add__(rhs: LengthCurve) LengthCurve
__add__(rhs: Length) LengthCurve

Return self <> rhs.

__sub__(rhs: LengthCurve) LengthCurve
__sub__(rhs: Length) LengthCurve

Return self - rhs.

__mul__(rhs: float) LengthCurve
__mul__(rhs: LengthCurve) AreaCurve
__mul__(rhs: Length) AreaCurve
__mul__(rhs: Curve) LengthCurve

Return self * rhs.

__truediv__(rhs: float) LengthCurve
__truediv__(rhs: LengthCurve) Curve
__truediv__(rhs: Length) Curve
__truediv__(rhs: Curve) LengthCurve

Return self / rhs.

__rmul__(lhs: float) LengthCurve

Return lhs * self.

class opensolid.Mitsuba

A Mitsuba scene that can be written out to a file.

static environment_map(frame: Frame3d, image: str) Lighting

Specify an environment map to be used as lighting.

You should pass a frame that defines the orientation of the environment map (which can often just be ‘Frame3d.world’) and the path to the environment map image itself.

The environment map image will typically be in OpenEXR format; https://polyhaven.com is a good source for free ones.

write_files(path: str, resolution: Resolution) None

Write a Mitsuba scene out to an XML scene description and a file containing binary mesh data.

The scene description file will be the given path with “.xml” appended, and the binary mesh data file with be the given path with “.serialized” appended. The given resolution will be used when meshing all objects in the scene.

Note that calling this function does not actually render the given scene, it just generates the necessary input files for the Mitsuba renderer. To actually render the generated scene, you’ll need to use the Mitsuba Python package (https://mitsuba.readthedocs.io/en/stable/), calling ‘mitsuba.load_file’ with the path to the generated XML file.

The generated scene will by default use 16 samples per pixel, and render an image with resolution 800x600. However, these can be configured by setting the ‘spp’, ‘width’ and ‘height’ parameters when loading the scene, for example with ‘mitsuba.load_file(path_to_xml_file, spp=256, width=1920, height=1080)’.

class Lighting

The lighting to use for a Mitsuba scene.

class opensolid.Model3d

A generic hierarchical 3D model for visualization/archival purposes.

A model is composed of bodies (parts) and groups of models (assemblies), each with optional attributes such as name or material.

nothing: Model3d = <opensolid.Model3d object>

An empty model.

static body(body: Body3d) Model3d

Create a model from a single solid body (a part).

static body_with(attributes: list[Attribute], body: Body3d) Model3d

Create a model from a single solid body (a part), with the given attributes.

static group(children: list[Model3d]) Model3d

Create a model formed from a group of sub-models (an assembly).

static group_with(attributes: list[Attribute], children: list[Model3d]) Model3d

Create a model formed from a group of sub-models (an assembly), with the given attributes.

static name(name: str) Attribute

Create a name attribute.

static pbr_material(material: PbrMaterial) Attribute

Create a PBR material attribute for rendering.

static opacity(opacity: float) Attribute

Create an opacity attribute, where 0 is fully transparent and 1 is fully opaque.

with_name(name: str) Model3d

Set the name of a model.

with_pbr_material(material: PbrMaterial) Model3d

Set the PBR material used by a model.

with_opacity(opacity: float) Model3d

Set the opacity of a model, where 0 is fully transparent and 1 is fully opaque.

with_attributes(attributes: list[Attribute]) Model3d

Add the given attributes to the given model.

place_in(frame: Frame3d) Model3d

Convert a model defined in local coordinates to one defined in global coordinates.

relative_to(frame: Frame3d) Model3d

Convert a model defined in global coordinates to one defined in local coordinates.

translate_by(displacement: Displacement3d) Model3d

Translate by the given displacement.

translate_in(direction: Direction3d, distance: Length) Model3d

Translate in the given direction by the given distance.

translate_along(axis: Axis3d, distance: Length) Model3d

Translate along the given axis by the given distance.

rotate_around(axis: Axis3d, angle: Angle) Model3d

Rotate around the given axis by the given angle.

class Attribute

An attribute that can be applied to a model.

class opensolid.Orientation3d

A set of cardinal directions (forward, upward etc.) defining a 3D orientation.

world: Orientation3d = <opensolid.Orientation3d object>

The global orientation of the current coordinate space.

That is, the forward direction of this orientation is the global forward direction, the upward direction of this orientation is the global upward direction, etc.

property forward_direction: Direction3d

Get the forward direction of a orientation.

property backward_direction: Direction3d

Get the backward direction of a orientation.

property leftward_direction: Direction3d

Get the leftward direction of a orientation.

property rightward_direction: Direction3d

Get the rightward direction of a orientation.

property upward_direction: Direction3d

Get the upward direction of a orientation.

property downward_direction: Direction3d

Get the downward direction of a orientation.

property front_plane_orientation: PlaneOrientation3d

Construct a forward-facing plane orientation from a parent orientation.

Relative to the parent orientation, the normal direction of the plane orientation will point forward, the X direction of the plane orientation will point leftward, and the Y direction of the plane orientation will point upward.

property back_plane_orientation: PlaneOrientation3d

Construct a backward-facing plane orientation from a parent orientation.

Relative to the parent orientation, the normal direction of the plane orientation will point backward, the X direction of the plane orientation will point rightward, and the Y direction of the plane orientation will point upward.

property right_plane_orientation: PlaneOrientation3d

Construct a rightward-facing plane orientation from a parent orientation.

Relative to the parent orientation, the normal direction of the plane orientation will point rightward, the X direction of the plane orientation will point forward, and the Y direction of the plane orientation will point upward.

property left_plane_orientation: PlaneOrientation3d

Construct a leftward-facing plane orientation from a parent orientation.

Relative to the parent orientation, the normal direction of the plane orientation will point leftward, the X direction of the plane orientation will point backward, and the Y direction of the plane orientation will point upward.

property bottom_plane_orientation: PlaneOrientation3d

Construct a downward-facing plane orientation from a parent orientation.

Relative to the parent orientation, the normal direction of the plane orientation will point downward, the X direction of the plane orientation will point leftward, and the Y direction of the plane orientation will point forward.

property top_plane_orientation: PlaneOrientation3d

Construct a upward-facing plane orientation from a parent orientation.

Relative to the parent orientation, the normal direction of the plane orientation will point upward, the X direction of the plane orientation will point rightward, and the Y direction of the plane orientation will point forward.

property backward_orientation: Orientation3d

Construct a backward facing orientation relative to a parent/reference orientation.

Relative to the parent orientation, the forward direction of the orientation will point backward, the rightward direction of the orientation will point leftward, and the upward direction of the orientation will point upward.

property rightward_orientation: Orientation3d

Construct a rightward facing orientation relative to a parent/reference orientation.

Relative to the parent orientation, the forward direction of the orientation will point rightward, the rightward direction of the orientation will point backward, and the upward direction of the orientation will point upward.

property leftward_orientation: Orientation3d

Construct a leftward facing orientation relative to a parent/reference orientation.

Relative to the parent orientation, the forward direction of the orientation will point leftward, the rightward direction of the orientation will point forward, and the upward direction of the orientation will point upward.

property upward_orientation: Orientation3d

Construct an upward facing orientation relative to a parent/reference orientation.

Relative to the parent orientation, the forward direction of the orientation will point upward, the rightward direction of the orientation will point leftward, and the upward direction of the orientation will point forward.

property downward_orientation: Orientation3d

Construct a downward facing orientation relative to a parent/reference orientation.

Relative to the parent orientation, the forward direction of the orientation will point downward, the rightward direction of the orientation will point rightward, and the upward direction of the orientation will point forward.

place_in(frame: Frame3d) Orientation3d

Convert a orientation defined in local coordinates to one defined in global coordinates.

relative_to(frame: Frame3d) Orientation3d

Convert a orientation defined in global coordinates to one defined in local coordinates.

class opensolid.PbrMaterial

A metallic-roughness material used for physically-based rendering.

static metal(base_color: Color, *, roughness: float) PbrMaterial

Create a metallic material with the given color and roughness.

static aluminum(*, roughness: float) PbrMaterial

Create an aluminum material with the given roughness.

static brass(*, roughness: float) PbrMaterial

Create a brass material with the given roughness.

static chromium(*, roughness: float) PbrMaterial

Create a chromium material with the given roughness.

static copper(*, roughness: float) PbrMaterial

Create a copper material with the given roughness.

static gold(*, roughness: float) PbrMaterial

Create a gold material with the given roughness.

static iron(*, roughness: float) PbrMaterial

Create an iron material with the given roughness.

static nickel(*, roughness: float) PbrMaterial

Create a nickel material with the given roughness.

static silver(*, roughness: float) PbrMaterial

Create a silver material with the given roughness.

static titanium(*, roughness: float) PbrMaterial

Create a titanium material with the given roughness.

static nonmetal(base_color: Color, *, roughness: float) PbrMaterial

Create a non-metallic material with the given color and roughness.

static custom(base_color: Color, *, metallic: float, roughness: float) PbrMaterial

Create a material with the given base color, metallic factor and roughness.

class opensolid.Plane3d

A plane in 3D, defined by an origin point and two perpendicular X and Y directions.

The normal direction of the plane is then defined as the cross product of its X and Y directions.

static from_point_and_normal(origin_point: Point3d, normal_direction: Direction3d) Plane3d

Construct a plane with the given origin point and normal direction.

Both the X and Y directions of the returned plane will be perpendicular to the given direction (and, of course, they will be perpendicular to each other), but otherwise they will be chosen arbitrarily.

static from_x_axis(axis: Axis3d) Plane3d

Construct a plane having the given X axis, with an arbitrarily-chosen Y direction.

static from_y_axis(axis: Axis3d) Plane3d

Construct a plane having the given Y axis, with an arbitrarily-chosen X direction.

property origin_point: Point3d

Get the origin point of a plane.

This is the 3D point corresponding to (0,0) in the plane’s local coordinates.

property x_direction: Direction3d

Get the X direction of a plane.

property y_direction: Direction3d

Get the Y direction of a plane.

property normal_direction: Direction3d

Get the normal direction of a plane.

property x_axis: Axis3d

Get the X axis of a plane.

This is an axis formed from the plane’s origin point and X direction.

property y_axis: Axis3d

Get the Y axis of a plane.

This is an axis formed from the plane’s origin point and Y direction.

property normal_axis: Axis3d

Construct an axis normal (perpendicular) to a plane.

The origin point of the axis will be the origin point of the plane, and the direction of the axis will be the normal direction of the plane.

move_to(point: Point3d) Plane3d

Move a plane so that its origin point is the given point.

The orientation of the plane will remain unchanged.

flip() Plane3d

Flip a plane such that its normal and X directions are reversed.

The Y direction will remain constant.

offset_by(distance: Length) Plane3d

Offset a plane in its normal direction by the given distance.

place_in(frame: Frame3d) Plane3d

Convert a plane defined in local coordinates to one defined in global coordinates.

relative_to(frame: Frame3d) Plane3d

Convert a plane defined in global coordinates to one defined in local coordinates.

translate_by(displacement: Displacement3d) Plane3d

Translate by the given displacement.

translate_in(direction: Direction3d, distance: Length) Plane3d

Translate in the given direction by the given distance.

translate_along(axis: Axis3d, distance: Length) Plane3d

Translate along the given axis by the given distance.

rotate_around(axis: Axis3d, angle: Angle) Plane3d

Rotate around the given axis by the given angle.

class opensolid.PlaneOrientation3d

A pair of perpendicular X and Y directions defining the orientation of a plane in 3D.

static from_normal_direction(direction: Direction3d) PlaneOrientation3d

Construct a plane orientation normal to the given direction.

Both the X and Y directions of the returned orientation will be perpendicular to the given direction (and, of course, they will be perpendicular to each other), but otherwise they will be chosen arbitrarily.

static from_x_direction(direction: Direction3d) PlaneOrientation3d

Construct a plane orientation from its X direction.

The Y direction of the returned basis will be perpendicular to the given X direction, but otherwise will be chosen arbitrarily.

static from_y_direction(direction: Direction3d) PlaneOrientation3d

Construct a plane orientation from its Y direction.

The X direction of the returned basis will be perpendicular to the given Y direction, but otherwise will be chosen arbitrarily.

property x_direction: Direction3d

Get the X direction of a plane orientation.

property y_direction: Direction3d

Get the Y direction of a plane orientation.

property normal_direction: Direction3d

Get the normal (outward) direction of a plane orientation.

place_in(frame: Frame3d) PlaneOrientation3d

Convert a orientation defined in local coordinates to one defined in global coordinates.

relative_to(frame: Frame3d) PlaneOrientation3d

Convert a orientation defined in global coordinates to one defined in local coordinates.

class opensolid.Point2d

A point in 2D, defined by its X and Y coordinates.

origin: Point2d = Point2d(Length.meters(0.0),Length.meters(0.0))

The point with coordinates (0,0).

static x(x_coordinate: Length) Point2d

Construct a point along the X axis, with the given X coordinate.

static y(y_coordinate: Length) Point2d

Construct a point along the Y axis, with the given Y coordinate.

static polar(radius: Length, angle: Angle) Point2d

Construct a point from polar coordinates (radius and angle).

The angle is measured counterclockwise from the positive X axis.

static meters(x_coordinate: float, y_coordinate: float) Point2d

Construct a point from its X and Y coordinates given in meters.

static centimeters(x_coordinate: float, y_coordinate: float) Point2d

Construct a point from its X and Y coordinates given in centimeters.

static cm(x_coordinate: float, y_coordinate: float) Point2d

Construct a point from its X and Y coordinates given in centimeters.

Short form alias for ‘centimeters’.

static millimeters(x_coordinate: float, y_coordinate: float) Point2d

Construct a point from its X and Y coordinates given in millimeters.

static mm(x_coordinate: float, y_coordinate: float) Point2d

Construct a point from its X and Y coordinates given in millimeters.

Short form alias for ‘millimeters’.

static inches(x_coordinate: float, y_coordinate: float) Point2d

Construct a point from its X and Y coordinates given in inches.

property coordinates: tuple[Length, Length]

Get the X and Y coordinates of a point.

property x_coordinate: Length

Get the X coordinate of a point.

property y_coordinate: Length

Get the Y coordinate of a point.

distance_to(other: Point2d) Length

Compute the distance from one point to another.

midpoint(other: Point2d) Point2d

Find the midpoint between two points.

on(plane: Plane3d) Point3d

Convert a 2D point to 3D point by placing it on a plane.

Given a 2D point defined within a plane’s coordinate system, this returns the corresponding 3D point.

scale_along(axis: Axis2d, scale: float) Point2d

Scale (stretch) along the given axis by the given scaling factor.

scale_about(point: Point2d, scale: float) Point2d

Scale uniformly about the given point by the given scaling factor.

mirror_across(axis: Axis2d) Point2d

Mirror across the given axis.

translate_by(displacement: Displacement2d) Point2d

Translate by the given displacement.

translate_in(direction: Direction2d, distance: Length) Point2d

Translate in the given direction by the given distance.

translate_along(axis: Axis2d, distance: Length) Point2d

Translate along the given axis by the given distance.

rotate_around(point: Point2d, angle: Angle) Point2d

Rotate around the given point by the given angle.

__sub__(rhs: Point2d) Displacement2d
__sub__(rhs: Displacement2d) Point2d
__sub__(rhs: Curve2d) DisplacementCurve2d

Return self - rhs.

__add__(rhs: Displacement2d) Point2d

Return self <> rhs.

class opensolid.Point3d

A point in 3D.

static along(axis: Axis3d, distance: Length) Point3d

Construct a point the given distance along the given axis.

static on(plane: Plane3d, position: Point2d) Point3d

Construct a point on the given plane, at the given position within the plane.

static xyz(convention: Convention3d, coordinates: tuple[Length, Length, Length]) Point3d

Construct a point from its XYZ coordinates, given the coordinate convention to use.

static z_up(x_coordinate: Length, y_coordinate: Length, z_coordinate: Length) Point3d

Construct a point from its XYZ coordinates, using a Z-up convention.

This is a convention where positive X is rightward, positive Y is forward and positive Z is upward.

static y_up(x_coordinate: Length, y_coordinate: Length, z_coordinate: Length) Point3d

Construct a point from its XYZ coordinates, using a Y-up convention.

This is a convention where positive X is leftward, positive Y is upward, and positive Z is forward.

coordinates(convention: Convention3d) tuple[Length, Length, Length]

Get the XYZ coordinates of a point, given an XYZ coordinate convention to use.

z_up_coordinates() tuple[Length, Length, Length]

Get the XYZ coordinates of a point using a Z-up coordinate convention.

This is a convention where positive X is rightward, positive Y is forward and positive Z is upward.

y_up_coordinates() tuple[Length, Length, Length]

Get the XYZ coordinates of a point using a Y-up coordinate convention.

This is a convention where positive X is leftward, positive Y is upward, and positive Z is forward.

distance_to(other: Point3d) Length

Compute the distance from one point to another.

midpoint(other: Point3d) Point3d

Find the midpoint between two points.

project_onto(plane: Plane3d) Point3d

Project a point onto a plane.

project_into(plane: Plane3d) Point2d

Project a point into a plane.

Conceptualy, this projects the point onto the plane in 3D, then expresses the projected point in 2D planar XY coordinates.

place_in(frame: Frame3d) Point3d

Convert a point defined in local coordinates to one defined in global coordinates.

relative_to(frame: Frame3d) Point3d

Convert a point defined in global coordinates to one defined in local coordinates.

scale_along(axis: Axis3d, scale: float) Point3d

Scale (stretch) along the given axis by the given scaling factor.

scale_about(point: Point3d, scale: float) Point3d

Scale uniformly about the given point by the given scaling factor.

mirror_across(plane: Plane3d) Point3d

Mirror across the given plane.

translate_by(displacement: Displacement3d) Point3d

Translate by the given displacement.

translate_in(direction: Direction3d, distance: Length) Point3d

Translate in the given direction by the given distance.

translate_along(axis: Axis3d, distance: Length) Point3d

Translate along the given axis by the given distance.

rotate_around(axis: Axis3d, angle: Angle) Point3d

Rotate around the given axis by the given angle.

__sub__(rhs: Point3d) Displacement3d
__sub__(rhs: Displacement3d) Point3d

Return self - rhs.

__add__(rhs: Displacement3d) Point3d

Return self <> rhs.

class opensolid.Region2d

A closed 2D region (possibly with holes), defined by a set of boundary curves.

static bounded_by(curves: list[Curve2d]) Region2d

Create a region bounded by the given curves.

The curves may be given in any order, do not need to have consistent directions and can form multiple separate loops if the region has holes. However, the curves must not overlap or intersect (other than at endpoints) and there must not be any gaps between them.

static rectangle(bounding_box: Bounds2d) Region2d

Create a rectangular region.

Fails if the given bounds are empty (zero area, i.e. zero width in either direction).

static circle(*, center_point: Point2d, diameter: Length) Region2d

Create a circular region.

Fails if the given dimeter is zero.

static polygon(points: list[Point2d]) Region2d

Create a polygonal region from the given vertices.

The last vertex will be connected back to the first vertex automatically if needed (you do not have to close the polygon manually, although it will still work if you do).

static hexagon(*, center_point: Point2d, height: Length) Region2d

Create a hexagon with the given center point and height.

The hexagon will be oriented such that its top and bottom edges are horizontal.

static inscribed_polygon(num_sides: int, *, center_point: Point2d, diameter: Length) Region2d

Create a regular polygon with the given number of sides.

The polygon will be sized to fit within a circle with the given center point and diameter (each polygon vertex will lie on the circle). The polygon will be oriented such that its bottom-most edge is horizontal.

static circumscribed_polygon(num_sides: int, *, center_point: Point2d, diameter: Length) Region2d

Create a regular polygon with the given number of sides.

The polygon will be sized so that a circle with the given center point and diameter will just fit within the polygon (each polygon edge will touch the circle at the edge’s midpoint). For a polygon with an even number of sides (square, hexagon, octagon etc.), this means that the “width across flats” will be equal to the given circle diameter. The polygon will be oriented such that its bottom-most edge is horizontal.

property outer_loop: list[Curve2d]

The list of curves forming the outer boundary of the region.

The curves will be in counterclockwise order around the region, and will each be in the counterclockwise direction.

property inner_loops: list[list[Curve2d]]

The lists of curves (if any) forming the holes within the region.

The curves will be in clockwise order around each hole, and each curve will be in the clockwise direction.

property boundary_curves: list[Curve2d]

The list of all (outer and inner) boundary curves of a region.

fillet(points: list[Point2d], *, radius: Length) Region2d

Fillet a region at the given corner points, with the given radius.

Fails if any of the given points are not actually corner points of the region (within the given tolerance), or if it is not possible to solve for a given fillet (e.g. if either of the adjacent edges is not long enough).

scale_along(axis: Axis2d, scale: float) Region2d

Scale (stretch) along the given axis by the given scaling factor.

scale_about(point: Point2d, scale: float) Region2d

Scale uniformly about the given point by the given scaling factor.

mirror_across(axis: Axis2d) Region2d

Mirror across the given axis.

translate_by(displacement: Displacement2d) Region2d

Translate by the given displacement.

translate_in(direction: Direction2d, distance: Length) Region2d

Translate in the given direction by the given distance.

translate_along(axis: Axis2d, distance: Length) Region2d

Translate along the given axis by the given distance.

rotate_around(point: Point2d, angle: Angle) Region2d

Rotate around the given point by the given angle.

class opensolid.Resolution

Specify the desired accuracy of a linear approximation such as a polyline or triangle mesh.

static max_error(error: Length) Resolution

Specify the maximum error/deviation of the approximation from the actual shape.

static max_size(size: Length) Resolution

Specify the maximum size of any element (line segment, triangle) in the approximation.

class opensolid.SpurGear

A metric spur gear.

static metric(*, num_teeth: int, module: Length) SpurGear

Create a metric spur gear with the given number of teeth and module.

property num_teeth: int

The number of teeth of a gear.

property module: Length

The module of a gear.

property pitch_diameter: Length

The pitch diameter of a gear.

property outer_diameter: Length

The outer diameter of a gear.

profile() list[Curve2d]

Get the outer profile of a gear as a list of curves, centered at the origin.

This is just the profile of the gear teeth themselves, and does not include a bore hole or anything else (lightening holes etc.). It is expected that you will combine this with any additional curves you want (likely at least one circle for a bore hole) and then construct a profile region from the combined set of curves that you can then extrude to form a gear body.

class opensolid.Tolerance

Manages a tolerance context value.

Many functions in OpenSolid require a tolerance to be set. You should generally choose a value that is much smaller than any meaningful size/dimension in the geometry you’re modelling, but significantly larger than any expected numerical roundoff that might occur. A good default choice is roughly one-billionth of the overall size of your geometry; for ‘human-scale’ things (say, from an earring up to a house) that means that one nanometer is a reasonable value to use.

Passing a tolerance into every function that needed one would get very verbose, and it’s very common to choose a single tolerance value and use it throughout a project. However, it’s also occasionally necessary to set a different tolerance for some code. This class allows managing tolerances using Python’s with statement, e.g.:

with Tolerance(Length.nanometer):
    do_something()
    do_something_else()
    with Tolerance(Angle.degrees(0.001)):
        compare_two_angles()
    do_more_things()

In the above code, the Length.nanometer tolerance value will be used for do_something() and do_something_else() (and any functions they call). The Angle.degrees(0.001)) tolerance value will then be used for compare_two_angles(), and then the Length.nanometer tolerance value will be restored and used for do_more_things().

static current() Value

Get the current tolerance value.

class opensolid.UvAxis

An axis in 2D, defined by an origin point and direction.

u: Axis2d = <opensolid.Axis2d object>

The U axis.

v: Axis2d = <opensolid.Axis2d object>

The V axis.

property origin_point: UvPoint

Get the origin point of an axis.

property direction: Direction2d

Get the direction of an axis.

class opensolid.UvBounds

A bounding box in UV parameter space.

static constant(point: UvPoint) UvBounds

Construct a zero-size bounding box containing a single point.

static from_corners(first_point: UvPoint, second_point: UvPoint) UvBounds

Construct a bounding box from two corner points.

static hull(points: list[UvPoint]) UvBounds

Construct a bounding box containing all vertices in the given non-empty list.

static aggregate(bounds: list[UvBounds]) UvBounds

Construct a bounding box containing all bounding boxes in the given non-empty list.

property coordinates: tuple[Bounds, Bounds]

Get the X and Y coordinate bounds of a bounding box.

property u_coordinate: Bounds

Get the U coordinate bounds of a bounding box.

property v_coordinate: Bounds

Get the V coordinate bounds of a bounding box.

scale_along(axis: UvAxis, scale: float) UvBounds

Scale (stretch) along the given axis by the given scaling factor.

scale_about(point: UvPoint, scale: float) UvBounds

Scale uniformly about the given point by the given scaling factor.

mirror_across(axis: UvAxis) UvBounds

Mirror across the given axis.

translate_by(displacement: Vector2d) UvBounds

Translate by the given displacement.

translate_in(direction: Direction2d, distance: float) UvBounds

Translate in the given direction by the given distance.

translate_along(axis: UvAxis, distance: float) UvBounds

Translate along the given axis by the given distance.

rotate_around(point: UvPoint, angle: Angle) UvBounds

Rotate around the given point by the given angle.

__add__(rhs: Vector2d) UvBounds

Return self <> rhs.

__sub__(rhs: Vector2d) UvBounds

Return self - rhs.

class opensolid.UvCurve

A curve in UV parameter space.

static constant(point: UvPoint) UvCurve

Create a degenerate curve that is actually just a single point.

static uv(u_coordinate: Curve, v_coordinate: Curve) UvCurve

Create a curve from its X and Y coordinate curves.

static line(start_point: UvPoint, end_point: UvPoint) UvCurve

Create a line between two points.

static arc(start_point: UvPoint, end_point: UvPoint, swept_angle: Angle) UvCurve

Create an arc with the given start point, end point and swept angle.

A positive swept angle means the arc turns counterclockwise (turns to the left), and a negative swept angle means it turns clockwise (turns to the right). For example, an arc with a swept angle of positive 90 degrees is quarter circle that turns to the left.

static polar_arc(*, center_point: UvPoint, radius: float, start_angle: Angle, end_angle: Angle) UvCurve

Create an arc with the given center point, radius, start angle and end angle.

static circle(*, center_point: UvPoint, diameter: float) UvCurve

Create a circle with the given center point and diameter.

static swept_arc(center_point: UvPoint, start_point: UvPoint, swept_angle: Angle) UvCurve

Create an arc with the given center point, start point and swept angle.

The start point will be swept around the center point by the given angle.

static corner_arc(corner_point: UvPoint, *, incoming: Direction2d, outgoing: Direction2d, radius: float) UvCurve

Create an arc for rounding off the corner between two straight lines.

static bezier(control_points: list[UvPoint]) UvCurve

Construct a Bezier curve from its control points.

For example,

> Curve2d.bezier (NonEmpty.four p1 p2 p3 p4))

will return a cubic Bezier curve with the given four control points.

static hermite(start_point: UvPoint, start_derivatives: list[Vector2d], end_point: UvPoint, end_derivatives: list[Vector2d]) UvCurve

Construct a Bezier curve with the given endpoints and derivatives at those endpoints.

For example,

> Curve2d.hermite p1 [v1] p2 [v2]

will result in a cubic spline from @p1@ to @p2@ with first derivative equal to @v1@ at @p1@ and first derivative equal to @v2@ at @p2@.

The numbers of derivatives at each endpoint do not have to be equal; for example,

> Curve2d.hermite p1 [v1] p2 []

will result in a quadratic spline from @p1@ to @p2@ with first derivative at @p1@ equal to @v1@.

In general, the degree of the resulting spline will be equal to 1 plus the total number of derivatives given.

property start_point: UvPoint

The start point of the curve.

property end_point: UvPoint

The end point of the curve.

property derivative: VectorCurve2d

The derivative of the curve.

property u_coordinate: Curve

Get the U coordinate of a UV curve as a scalar curve.

property v_coordinate: Curve

Get the V coordinate of a UV curve as a scalar curve.

evaluate(parameter_value: float) UvPoint

Evaluate a curve at a given parameter value.

The parameter value should be between 0 and 1.

reverse() UvCurve

Reverse a curve, so that the start point is the end point and vice versa.

scale_along(axis: UvAxis, scale: float) UvCurve

Scale (stretch) along the given axis by the given scaling factor.

scale_about(point: UvPoint, scale: float) UvCurve

Scale uniformly about the given point by the given scaling factor.

mirror_across(axis: UvAxis) UvCurve

Mirror across the given axis.

translate_by(displacement: Vector2d) UvCurve

Translate by the given displacement.

translate_in(direction: Direction2d, distance: float) UvCurve

Translate in the given direction by the given distance.

translate_along(axis: UvAxis, distance: float) UvCurve

Translate along the given axis by the given distance.

rotate_around(point: UvPoint, angle: Angle) UvCurve

Rotate around the given point by the given angle.

__add__(rhs: VectorCurve2d) UvCurve

Return self <> rhs.

__sub__(rhs: VectorCurve2d) UvCurve
__sub__(rhs: UvCurve) VectorCurve2d
__sub__(rhs: UvPoint) VectorCurve2d

Return self - rhs.

class opensolid.UvPoint

A point in UV parameter space.

origin: UvPoint = UvPoint(0.0,0.0)

The point with coordinates (0,0).

property coordinates: tuple[float, float]

Get the U and V coordinates of a point.

property u_coordinate: float

Get the U coordinate of a point.

property v_coordinate: float

Get the V coordinate of a point.

distance_to(other: UvPoint) float

Compute the distance from one point to another.

midpoint(other: UvPoint) UvPoint

Find the midpoint between two points.

scale_along(axis: UvAxis, scale: float) UvPoint

Scale (stretch) along the given axis by the given scaling factor.

scale_about(point: UvPoint, scale: float) UvPoint

Scale uniformly about the given point by the given scaling factor.

mirror_across(axis: UvAxis) UvPoint

Mirror across the given axis.

translate_by(displacement: Vector2d) UvPoint

Translate by the given displacement.

translate_in(direction: Direction2d, distance: float) UvPoint

Translate in the given direction by the given distance.

translate_along(axis: UvAxis, distance: float) UvPoint

Translate along the given axis by the given distance.

rotate_around(point: UvPoint, angle: Angle) UvPoint

Rotate around the given point by the given angle.

__sub__(rhs: UvPoint) Vector2d
__sub__(rhs: Vector2d) UvPoint

Return self - rhs.

__add__(rhs: Vector2d) UvPoint

Return self <> rhs.

class opensolid.UvRegion

A region in UV parameter space.

unit_square: UvRegion = <opensolid.UvRegion object>

The unit square in UV space.

static bounded_by(curves: list[UvCurve]) UvRegion

Create a region bounded by the given curves.

The curves may be given in any order, do not need to have consistent directions and can form multiple separate loops if the region has holes. However, the curves must not overlap or intersect (other than at endpoints) and there must not be any gaps between them.

static rectangle(bounding_box: UvBounds) UvRegion

Create a rectangular region.

Fails if the given bounds are empty (zero area, i.e. zero width in either direction).

static circle(*, center_point: UvPoint, diameter: float) UvRegion

Create a circular region.

Fails if the given dimeter is zero.

property outer_loop: list[UvCurve]

The list of curves forming the outer boundary of the region.

The curves will be in counterclockwise order around the region, and will each be in the counterclockwise direction.

property inner_loops: list[list[UvCurve]]

The lists of curves (if any) forming the holes within the region.

The curves will be in clockwise order around each hole, and each curve will be in the clockwise direction.

property boundary_curves: list[UvCurve]

The list of all (outer and inner) boundary curves of a region.

scale_along(axis: UvAxis, scale: float) UvRegion

Scale (stretch) along the given axis by the given scaling factor.

scale_about(point: UvPoint, scale: float) UvRegion

Scale uniformly about the given point by the given scaling factor.

mirror_across(axis: UvAxis) UvRegion

Mirror across the given axis.

translate_by(displacement: Vector2d) UvRegion

Translate by the given displacement.

translate_in(direction: Direction2d, distance: float) UvRegion

Translate in the given direction by the given distance.

translate_along(axis: UvAxis, distance: float) UvRegion

Translate along the given axis by the given distance.

rotate_around(point: UvPoint, angle: Angle) UvRegion

Rotate around the given point by the given angle.

class opensolid.Vector2d

A unitless vector in 2D.

zero: Vector2d = Vector2d(0.0,0.0)

The zero vector.

static unit(direction: Direction2d) Vector2d

Construct a unit vector in the given direction.

static y(y_component: float) Vector2d

Construct a vector from just a Y component.

The X component will be set to zero.

static x(x_component: float) Vector2d

Construct a vector from just an X component.

The Y component will be set to zero.

static polar(magnitude: float, angle: Angle) Vector2d

Construct a vector from its magnitude (length) and angle.

property components: tuple[float, float]

Get the X and Y components of a vector as a tuple.

property x_component: float

Get the X component of a vector.

property y_component: float

Get the Y component of a vector.

property angle: Angle

Get the angle of a vector.

The angle is measured counterclockwise from the positive X axis, so:

  • A vector in the positive X direction has an angle of zero.

  • A vector in the positive Y direction has an angle of 90 degrees.

  • A vector in the negative Y direction has an angle of -90 degrees.

  • It is not defined whether a vector exactly in the negative X direction has an angle of -180 or +180 degrees. (Currently it is reported as having an angle of +180 degrees, but this should not be relied upon.)

The returned angle will be between -180 and +180 degrees.

direction() Direction2d

Attempt to get the direction of a vector.

The current tolerance will be used to check if the vector is zero (and therefore does not have a direction).

normalize() Vector2d

Normalize a vector.

If the original vector is exactly zero, then the result will be zero as well. Otherwise, the result will be a unit vector.

angle_to(other: Vector2d) Angle

Measure the signed angle from one vector to another.

The angle will be measured counterclockwise from the first vector to the second, and will always be between -180 and +180 degrees.

is_zero() bool

Check if a vector is zero, within the current tolerance.

__add__(rhs: Vector2d) Vector2d

Return self <> rhs.

__sub__(rhs: Vector2d) Vector2d

Return self - rhs.

__mul__(rhs: float) Vector2d
__mul__(rhs: Length) Displacement2d
__mul__(rhs: Area) AreaVector2d

Return self * rhs.

__truediv__(rhs: float) Vector2d

Return self / rhs.

dot(rhs: Vector2d) float
dot(rhs: Displacement2d) Length
dot(rhs: AreaVector2d) Area

Compute the dot product of two vector-like values.

cross(rhs: Vector2d) float
cross(rhs: Displacement2d) Length
cross(rhs: AreaVector2d) Area

Compute the cross product of two vector-like values.

__rmul__(lhs: float) Vector2d

Return lhs * self.

class opensolid.Vector3d

A unitless vector in 3D.

zero: Vector3d = <opensolid.Vector3d object>

The zero vector.

static unit(direction: Direction3d) Vector3d

Construct a unit vector in the given direction.

static xyz(convention: Convention3d, components: tuple[float, float, float]) Vector3d

Construct a vector from its XYZ components, given the coordinate convention to use.

static z_up(x_component: float, y_component: float, z_component: float) Vector3d

Construct a vector from its XYZ components, using a Z-up convention.

This is a convention where positive X is rightward, positive Y is forward and positive Z is upward.

static y_up(x_component: float, y_component: float, z_component: float) Vector3d

Construct a vector from its XYZ components, using a Y-up convention.

This is a convention where positive X is leftward, positive Y is upward, and positive Z is forward.

components(convention: Convention3d) tuple[float, float, float]

Get the XYZ components of a vector, given an XYZ coordinate convention to use.

z_up_components() tuple[float, float, float]

Get the XYZ components of a vector using a Z-up coordinate convention.

This is a convention where positive X is rightward, positive Y is forward and positive Z is upward.

y_up_components() tuple[float, float, float]

Get the XYZ components of a vector using a Y-up coordinate convention.

This is a convention where positive X is leftward, positive Y is upward, and positive Z is forward.

direction() Direction3d

Attempt to get the direction of a vector.

The current tolerance will be used to check if the vector is zero (and therefore does not have a direction).

is_zero() bool

Check if a vector is zero, within the current tolerance.

rotate_in(direction: Direction3d, angle: Angle) Vector3d

Rotate a vector in a given direction.

This is equivalent to rotating around an axis with the given direction.

rotate_around(axis: Axis3d, angle: Angle) Vector3d

Rotate around the given axis by the given angle.

mirror_in(direction: Direction3d) Vector3d

Mirror in a particular direction.

This is equivalent to mirroring across a plane with the given normal direction.

mirror_across(plane: Plane3d) Vector3d

Mirror across the given plane.

scale_in(direction: Direction3d, scale: float) Vector3d

Scale (stretch) in the given direction by the given scaling factor.

This is equivalent to scaling along an axis with the given direction.

scale_along(axis: Axis3d, scale: float) Vector3d

Scale (stretch) along the given axis by the given scaling factor.

place_in(frame: Frame3d) Vector3d

Convert a vectr defined in local coordinates to one defined in global coordinates.

relative_to(frame: Frame3d) Vector3d

Convert a vector defined in global coordinates to one defined in local coordinates.

__add__(rhs: Vector3d) Vector3d

Return self <> rhs.

__sub__(rhs: Vector3d) Vector3d

Return self - rhs.

__mul__(rhs: float) Vector3d
__mul__(rhs: Length) Displacement3d
__mul__(rhs: Area) AreaVector3d

Return self * rhs.

__truediv__(rhs: float) Vector3d

Return self / rhs.

dot(rhs: Vector3d) float
dot(rhs: Displacement3d) Length
dot(rhs: AreaVector3d) Area

Compute the dot product of two vector-like values.

cross(rhs: Vector3d) Vector3d
cross(rhs: Displacement3d) Displacement3d
cross(rhs: AreaVector3d) AreaVector3d

Compute the cross product of two vector-like values.

__rmul__(lhs: float) Vector3d

Return lhs * self.

class opensolid.VectorCurve2d

A parametric curve defining a 2D unitless vector in terms of a parameter value.

zero: VectorCurve2d = <opensolid.VectorCurve2d object>

The constant zero vector.

static constant(value: Vector2d) VectorCurve2d

Create a curve with a constant value.

static xy(x_component: Curve, y_component: Curve) VectorCurve2d

Create a curve from its X and Y component curves.

evaluate(parameter_value: float) Vector2d

Evaluate a curve at a given parameter value.

The parameter value should be between 0 and 1.