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:
from openscad import *
c = cross([1, 0, 0], [0, 1, 0]) # [0, 0, 1]
c = cross([0, 1, 0], [1, 0, 0]) # [0, 0, -1]
OpenSCAD reference: cross