Math Functions
PythonSCAD provides trigonometric and vector math functions that mirror OpenSCAD's built-in math functions. The trigonometric functions use degrees (not radians), matching OpenSCAD convention.
For standard Python math (radians), use Python's built-in math module instead.
Trigonometry
Sin
Calculate the sine of an angle in degrees.
Cos
Calculate the cosine of an angle in degrees.
Tan
Calculate the tangent of an angle in degrees.
Asin
Calculate the arc sine, returning degrees.
Acos
Calculate the arc cosine, returning degrees.
Atan
Calculate the arc tangent, returning degrees.
OpenSCAD reference: Mathematical Functions
norm
Calculate the Euclidean length (magnitude) of a vector.
Syntax:
Parameters:
| Parameter | Type | Description |
|---|---|---|
vec |
list of numbers | Input vector |
Examples:
OpenSCAD reference: norm
dot
Calculate the dot product of two vectors.
Syntax:
Parameters:
| Parameter | Type | Description |
|---|---|---|
vec1 |
list of numbers | First vector |
vec2 |
list of numbers | Second vector |
Examples:
cross
Calculate the cross product of two 3D vectors.
Syntax:
Parameters:
| Parameter | Type | Description |
|---|---|---|
vec1 |
[x, y, z] |
First vector |
vec2 |
[x, y, z] |
Second vector |
Returns: A 3D vector perpendicular to both inputs.
Examples:
Vector functions
There are many places, where PythonSCAD accepts vectors which are supplied as Python lists with 2 or 3 numbers. Alernatively, PythonSCAD also accepts PythonSCAD Vector objects with calculating capabilities
Vector addition
Vector subtraction
Vector scaling
Cross Product
Dot Product
Values access
OpenSCAD reference: cross