surf: curves and surfaces¶
To use this module, require it in a generator script (see Geometry modules):
require surf
Curves and surfaces: B-spline curves, lofts, sweeps, patches and shells. solid and thicken
make a csg Solid of them, which a model can use.
Constants¶
- v0 = 0¶
The side v = 0 of a sheet, for blend.
- u1 = 1¶
The side u = 1 of a sheet, for blend.
- v1 = 2¶
The side v = 1 of a sheet, for blend.
- u0 = 3¶
The side u = 0 of a sheet, for blend.
- xy = 4¶
The xy plane, for 2D points and mirrors.
- xz = 5¶
The xz plane, for 2D points and mirrors.
- yz = 6¶
The yz plane, for 2D points and mirrors.
- local = 7¶
The fit of loft: a local cubic through the sections.
- interp = 8¶
The fit of loft: an interpolation through the sections.
- approx = 9¶
The fit of loft: an approximation within approxTol.
- point = 10¶
The end of loft: the end sections as they are.
- round = 11¶
The end of loft: rounded ends.
- normal = 12¶
The side of thicken: toward the normal.
- reverse = 13¶
The side of thicken: away from the normal.
- center = 14¶
The side of thicken: half to each side.
Structures¶
- Curve¶
A curve: a handle of a lazy expression.
- Fields:
id : int - The index of the expression in the model
- Sheet¶
A sheet: one surface patch, open or closed.
- Fields:
id : int - The index of the expression in the model
- Shell¶
A shell: sheets stitched along their edges.
- Fields:
id : int - The index of the expression in the model
Curves¶
arc (center: float2; r: float; a0: float; a1: float; plane: int = xy) : Curve
arch (yw: float; yt: float; w: float; p: float = 1f) : Curve
curve (points: array<float2>; plane: int = xy; closed: bool = false) : Curve
nurbs (ctrl: array<float3>; degree: int; weights: array<float>) : Curve
polyline (points: array<float2>; plane: int = xy; radius: float = 0f; closed: bool = false) : Curve
polyline (points: array<float3>; radius: float = 0f; closed: bool = false) : Curve
section (yb: float; yw: float; yt: float; w: float; pb: float; pt: float) : Curve
- arc(center: float2; r: float; a0: float; a1: float; plane: int = xy): Curve¶
A circle arc in a plane.
- Arguments:
center : float2 - the center in the plane, in meters
r : float - the radius in meters
a0 : float - the start angle in degrees
a1 : float - the end angle in degrees
plane : int -
xy,xzoryz
- arc3(p0: float3; p1: float3; p2: float3): Curve¶
The circle arc from p0 through p1 to p2.
- Arguments:
p0 : float3
p1 : float3
p2 : float3
- arch(yw: float; yt: float; w: float; p: float = 1f): Curve¶
An arch section: a superellipse arc from the widest point up to the top, with its mirror image.
- Arguments:
yw : float - the y of the widest point in meters
yt : float - the top y in meters
w : float - the half width in meters
p : float - the exponent of the arc
- bspline(ctrl: array<float3>; degree: int = 3): Curve¶
A B-spline curve of control points in model space.
- Arguments:
ctrl : array<float3> - the control points in meters
degree : int - the degree of the curve
- composite(curves: array<Curve>): Curve¶
One curve made of curves that meet end to start.
- Arguments:
curves : array< Curve>
- curve(points: array<float2>; plane: int = xy; closed: bool = false): Curve¶
A smooth curve, up to cubic, through 2D points in a plane.
- Arguments:
points : array<float2> - the points in meters
plane : int -
xy,xzoryz, the plane of the pointsclosed : bool - true joins the last point to the first
- curve(points: array<float3>; closed: bool = false): Curve
A smooth curve, up to cubic, through points in model space.
- Arguments:
points : array<float3> - the points in meters
closed : bool - true joins the last point to the first
- iso_u(s: Sheet; u: float): Curve¶
The curve of the sheet at a fixed parameter u.
- Arguments:
s : Sheet
u : float
- iso_v(s: Sheet; v: float): Curve¶
The curve of the sheet at a fixed parameter v.
- Arguments:
s : Sheet
v : float
- mirror_section(c: Curve; plane: int = xy): Curve¶
The section joined with its mirror image across a plane: closed when both ends of the half lie on the plane, open when only its end does; a half whose end is off the plane is an error.
- Arguments:
c : Curve - the half section
plane : int -
xy,xzoryz, the mirror plane
- nurbs(ctrl: array<float3>; degree: int; weights: array<float>): Curve¶
A NURBS curve: control points in model space, each with a weight.
- Arguments:
ctrl : array<float3> - the control points in meters
degree : int - the degree of the curve
weights : array<float> - a weight for each control point
- polyline(points: array<float2>; plane: int = xy; radius: float = 0f; closed: bool = false): Curve¶
A polyline through 2D points in a plane; radius rounds its corners.
- Arguments:
points : array<float2> - the points in meters
plane : int -
xy,xzoryz, the plane of the pointsradius : float - the radius of the corner arcs in meters, 0 for sharp corners
closed : bool - true joins the last point to the first
- polyline(points: array<float3>; radius: float = 0f; closed: bool = false): Curve
A polyline through points in model space; radius rounds its corners.
- Arguments:
points : array<float3> - the points in meters
radius : float - the radius of the corner arcs in meters, 0 for sharp corners
closed : bool - true joins the last point to the first
- reversed(c: Curve): Curve¶
The curve run backward.
- Arguments:
c : Curve
- seam(c: Curve; t: float): Curve¶
The closed curve restarted at the parameter t.
- Arguments:
c : Curve
t : float
- section(yb: float; yw: float; yt: float; w: float; pb: float; pt: float): Curve¶
Half a cross section in the yz plane made of two superellipse arcs, for a hull or a fuselage.
- Arguments:
yb : float - the bottom y in meters
yw : float - the y of the widest point in meters
yt : float - the top y in meters
w : float - the half width in meters
pb : float - the exponent of the lower arc
pt : float - the exponent of the upper arc
Sheets¶
blend (a: Sheet; side_a: int; b: Sheet; side_b: int; bulge: float = 1f) : Sheet
card (w: float; h: float; fold: float = 0f; bend: float = 0f) : Sheet
patch (net: array<array<float3>>; du: int = 3; dv: int = 3) : Sheet
revolve (c: Curve; axis: float3; angle: float = 360f) : Sheet
revolve (c: Curve; origin: float3; axis: float3; angle: float = 360f) : Sheet
sweep (profile: Curve; path: Curve; scale: float = 1f; twist: float = 0f) : Sheet
- blend(a: Sheet; side_a: int; b: Sheet; side_b: int; bulge: float = 1f): Sheet¶
A smooth strip across the gap between a side of a and a side of b.
- Arguments:
- card(w: float; h: float; fold: float = 0f; bend: float = 0f): Sheet¶
An open card in the xy plane: x from -w / 2 to w / 2, y from 0 to h, normal +z, UV 0 to 1.
- Arguments:
w : float - the width in meters
h : float - the height in meters
fold : float - turns the two halves about y, above -90 and below 90 degrees
bend : float - curls the tip toward +z, above -120 and below 120 degrees
- coons(c0: Curve; c1: Curve; c2: Curve; c3: Curve): Sheet¶
The Coons patch of four boundary curves: the sides v0, u1, v1, u0; c2 and c3 run backward.
- extrude(c: Curve; dir: float3; length: float): Sheet¶
The sheet that the curve sweeps when it moves along dir for length meters.
- Arguments:
c : Curve
dir : float3
length : float
- loft(sections: array<Curve>; degree: int = 3; closed: bool = false; fit: int = local; approxTol: float = 0f; startTangent: float3 = float3(0f, 0f, 0f); endTangent: float3 = float3(0f, 0f, 0f); end: int = point): Sheet¶
A sheet through 2 or more section curves, all open or all closed.
- Arguments:
sections : array< Curve> - the section curves; curves made by
curve()with equal point counts pair point by pointdegree : int - the degree across the sections, 1 to 7
closed : bool - true joins the last section to the first (3 or more sections, degree 3, fit local or interp, no end tangents and no round end)
fit : int -
local(a local cubic),interp(through the sections) orapprox(near the sections)approxTol : float - the tolerance of
approxin meters, above 0startTangent : float3 - the tangent at the first section, 0 for a free end
endTangent : float3 - the tangent at the last section, 0 for a free end
end : int -
pointorround, the shape of the open ends
- patch(net: array<array<float3>>; du: int = 3; dv: int = 3): Sheet¶
A B-spline patch of a control net; net[i][j] with i along u and j along v.
- Arguments:
net : array<array<float3>> - the control points in meters
du : int - the degree along u
dv : int - the degree along v
- quad(sx: float; sz: float): Sheet¶
An open rectangle in the xz plane, centered at the origin, normal +y.
- Arguments:
sx : float - the size along x in meters
sz : float - the size along z in meters
- revolve(c: Curve; axis: float3; angle: float = 360f): Sheet¶
The sheet that the curve sweeps around an axis through the origin, by the right-hand rule.
- Arguments:
c : Curve - the curve
axis : float3 - the direction of the axis
angle : float - the sweep in degrees
- revolve(c: Curve; origin: float3; axis: float3; angle: float = 360f): Sheet
The sheet that the curve sweeps around an axis through origin, by the right-hand rule.
- Arguments:
c : Curve - the curve
origin : float3 - a point of the axis
axis : float3 - the direction of the axis
angle : float - the sweep in degrees
- sweep(profile: Curve; path: Curve; scale: float = 1f; twist: float = 0f): Sheet¶
The profile swept along the path: profile x runs along the normal of the path, y along its binormal (up at the start).
Shells and solids¶
- cap(s: Sheet): Shell¶
Closes the free edge loops of the sheet with caps: a loop must be planar or have four corners.
- Arguments:
s : Sheet
- cap(s: Shell): Shell
Closes the free edge loops of the shell with caps: a loop must be planar or have four corners.
- Arguments:
s : Shell
- shell(s: Sheet): Shell¶
A shell of one sheet, with no caps.
- Arguments:
s : Sheet
- solid(s: Sheet): Solid¶
The closed sheet as a csg Solid; an open one fails the build.
- Arguments:
s : Sheet
- solid(s: Shell): Solid
The closed shell as a csg Solid; an open one fails the build.
- Arguments:
s : Shell
- stitch(sheets: array<Sheet>; stitch: float = 0f): Shell¶
Joins sheets along their common edges into one shell.
- Arguments:
sheets : array< Sheet> - the sheets
stitch : float - the edge tolerance in meters, 0 picks it
- stitch(shells: array<Shell>; stitch: float = 0f): Shell
Joins shells along their common edges into one shell.
- Arguments:
shells : array< Shell> - the shells
stitch : float - the edge tolerance in meters, 0 picks it
- thicken(s: Sheet; t: float; side: int = normal): Solid¶
A csg Solid: the sheet thickened by t meters to one side or both.
- Arguments:
s : Sheet - the surface
t : float - the thickness in meters, below the curvature radius on that side
side : int -
normal,reverseorcenter
- thicken(s: Shell; t: float; side: int = normal): Solid
A csg Solid: the shell thickened by t meters to one side or both.
- Arguments:
s : Shell - the surface
t : float - the thickness in meters, below the curvature radius on that side
side : int -
normal,reverseorcenter
Attributes¶
- mat(s: Sheet; id: int): Sheet¶
Sets the material id of all faces of the sheet, 0 to 65535.
- Arguments:
s : Sheet
id : int
- mat(s: Shell; id: int): Shell
Sets the material id of all faces of the shell, 0 to 65535.
- Arguments:
s : Shell
id : int
- paint(s: Sheet; polygon: array<float2>; color: float3; plane: int = xy; mat: int = -1): Sheet¶
Colors the faces of the sheet inside a polygon seen in a plane, and cuts the faces along its outline.
- Arguments:
s : Sheet - the surface
polygon : array<float2> - the outline in the plane, in meters
color : float3 - linear RGB from 0 to 1
plane : int -
xy,xzoryzmat : int - the material id of the faces, -1 keeps it
- paint(s: Shell; polygon: array<float2>; color: float3; plane: int = xy; mat: int = -1): Shell
Colors the faces of the shell inside a polygon seen in a plane, and cuts the faces along its outline.
- Arguments:
s : Shell - the surface
polygon : array<float2> - the outline in the plane, in meters
color : float3 - linear RGB from 0 to 1
plane : int -
xy,xzoryzmat : int - the material id of the faces, -1 keeps it
- rgb(s: Sheet; r: float; g: float; b: float): Sheet¶
Sets the color of all faces of the sheet, linear RGB from 0 to 1.
- Arguments:
s : Sheet
r : float
g : float
b : float
- rgb(s: Shell; r: float; g: float; b: float): Shell
Sets the color of all faces of the shell, linear RGB from 0 to 1.
- Arguments:
s : Shell
r : float
g : float
b : float
- uv_offset(s: Sheet; du: float; dv: float): Sheet¶
Adds (du, dv) to the UV of the sheet.
- Arguments:
s : Sheet
du : float
dv : float
- uv_offset(s: Shell; du: float; dv: float): Shell
Adds (du, dv) to the UV of the shell.
- Arguments:
s : Shell
du : float
dv : float
- uv_rotate(s: Sheet; deg: float): Sheet¶
Rotates the UV of the sheet about (0, 0) by deg degrees, from u toward v.
- Arguments:
s : Sheet
deg : float
- uv_rotate(s: Shell; deg: float): Shell
Rotates the UV of the shell about (0, 0) by deg degrees, from u toward v.
- Arguments:
s : Shell
deg : float
- uv_scale(s: Sheet; su: float; sv: float): Sheet¶
Multiplies the UV of the sheet: u by su, v by sv.
- Arguments:
s : Sheet
su : float
sv : float
- uv_scale(s: Shell; su: float; sv: float): Shell
Multiplies the UV of the shell: u by su, v by sv.
- Arguments:
s : Shell
su : float
sv : float
Transforms¶
- at(a: Curve; p: float3): Curve¶
Moves the curve by p meters.
- Arguments:
a : Curve
p : float3
- at(a: Curve; x: float; y: float; z: float): Curve
Moves the curve by (x, y, z) meters.
- Arguments:
a : Curve
x : float
y : float
z : float
- at(a: Sheet; p: float3): Sheet
Moves the sheet by p meters.
- Arguments:
a : Sheet
p : float3
- at(a: Sheet; x: float; y: float; z: float): Sheet
Moves the sheet by (x, y, z) meters.
- Arguments:
a : Sheet
x : float
y : float
z : float
- at(a: Shell; p: float3): Shell
Moves the shell by p meters.
- Arguments:
a : Shell
p : float3
- at(a: Shell; x: float; y: float; z: float): Shell
Moves the shell by (x, y, z) meters.
- Arguments:
a : Shell
x : float
y : float
z : float
- mirror_x(a: Curve): Curve¶
The mirror image of the curve across the plane x = 0.
- Arguments:
a : Curve
- mirror_x(a: Sheet): Sheet
The mirror image of the sheet across the plane x = 0.
- Arguments:
a : Sheet
- mirror_x(a: Shell): Shell
The mirror image of the shell across the plane x = 0.
- Arguments:
a : Shell
- mirror_y(a: Curve): Curve¶
The mirror image of the curve across the plane y = 0.
- Arguments:
a : Curve
- mirror_y(a: Sheet): Sheet
The mirror image of the sheet across the plane y = 0.
- Arguments:
a : Sheet
- mirror_y(a: Shell): Shell
The mirror image of the shell across the plane y = 0.
- Arguments:
a : Shell
- mirror_z(a: Curve): Curve¶
The mirror image of the curve across the plane z = 0.
- Arguments:
a : Curve
- mirror_z(a: Sheet): Sheet
The mirror image of the sheet across the plane z = 0.
- Arguments:
a : Sheet
- mirror_z(a: Shell): Shell
The mirror image of the shell across the plane z = 0.
- Arguments:
a : Shell
- rot(a: Curve; axis: float3; deg: float): Curve¶
Rotates the curve about an axis through the origin by deg degrees, by the right-hand rule.
- Arguments:
a : Curve
axis : float3
deg : float
- rot(a: Sheet; axis: float3; deg: float): Sheet
Rotates the sheet about an axis through the origin by deg degrees, by the right-hand rule.
- Arguments:
a : Sheet
axis : float3
deg : float
- rot(a: Shell; axis: float3; deg: float): Shell
Rotates the shell about an axis through the origin by deg degrees, by the right-hand rule.
- Arguments:
a : Shell
axis : float3
deg : float
- rot_x(a: Curve; deg: float): Curve¶
Rotates the curve about the X axis by deg degrees: rot_x(90.0) turns +Y to +Z.
- Arguments:
a : Curve
deg : float
- rot_x(a: Sheet; deg: float): Sheet
Rotates the sheet about the X axis by deg degrees: rot_x(90.0) turns +Y to +Z.
- Arguments:
a : Sheet
deg : float
- rot_x(a: Shell; deg: float): Shell
Rotates the shell about the X axis by deg degrees: rot_x(90.0) turns +Y to +Z.
- Arguments:
a : Shell
deg : float
- rot_y(a: Curve; deg: float): Curve¶
Rotates the curve about the Y axis by deg degrees: rot_y(90.0) turns +Z to +X.
- Arguments:
a : Curve
deg : float
- rot_y(a: Sheet; deg: float): Sheet
Rotates the sheet about the Y axis by deg degrees: rot_y(90.0) turns +Z to +X.
- Arguments:
a : Sheet
deg : float
- rot_y(a: Shell; deg: float): Shell
Rotates the shell about the Y axis by deg degrees: rot_y(90.0) turns +Z to +X.
- Arguments:
a : Shell
deg : float
- rot_z(a: Curve; deg: float): Curve¶
Rotates the curve about the Z axis by deg degrees: rot_z(90.0) turns +X to +Y.
- Arguments:
a : Curve
deg : float
- rot_z(a: Sheet; deg: float): Sheet
Rotates the sheet about the Z axis by deg degrees: rot_z(90.0) turns +X to +Y.
- Arguments:
a : Sheet
deg : float
- rot_z(a: Shell; deg: float): Shell
Rotates the shell about the Z axis by deg degrees: rot_z(90.0) turns +X to +Y.
- Arguments:
a : Shell
deg : float
- scale(a: Curve; s: float): Curve¶
Scales the curve about the origin by s.
- Arguments:
a : Curve
s : float
- scale(a: Curve; sx: float; sy: float; sz: float): Curve
Scales the curve about the origin, a factor per axis; a negative factor mirrors.
- Arguments:
a : Curve
sx : float
sy : float
sz : float
- scale(a: Sheet; s: float): Sheet
Scales the sheet about the origin by s.
- Arguments:
a : Sheet
s : float
- scale(a: Sheet; sx: float; sy: float; sz: float): Sheet
Scales the sheet about the origin, a factor per axis; a negative factor mirrors.
- Arguments:
a : Sheet
sx : float
sy : float
sz : float
- scale(a: Shell; s: float): Shell
Scales the shell about the origin by s.
- Arguments:
a : Shell
s : float
- scale(a: Shell; sx: float; sy: float; sz: float): Shell
Scales the shell about the origin, a factor per axis; a negative factor mirrors.
- Arguments:
a : Shell
sx : float
sy : float
sz : float
- sym_x(a: Sheet): Shell¶
A shell of the sheet and its mirror image across the plane x = 0, stitched along the plane.
- Arguments:
a : Sheet
- sym_x(a: Shell): Shell
A shell of the shell and its mirror image across the plane x = 0, stitched along the plane.
- Arguments:
a : Shell
- sym_y(a: Sheet): Shell¶
A shell of the sheet and its mirror image across the plane y = 0, stitched along the plane.
- Arguments:
a : Sheet
- sym_y(a: Shell): Shell
A shell of the shell and its mirror image across the plane y = 0, stitched along the plane.
- Arguments:
a : Shell
- sym_z(a: Sheet): Shell¶
A shell of the sheet and its mirror image across the plane z = 0, stitched along the plane.
- Arguments:
a : Sheet
- sym_z(a: Shell): Shell
A shell of the shell and its mirror image across the plane z = 0, stitched along the plane.
- Arguments:
a : Shell
Sampling¶
- sample(c: Curve; n: int): array<float3>¶
n points along the curve in model space, computed at once.
- Arguments:
c : Curve
n : int
- sample(s: Sheet; nu: int; nv: int): array<float3>
nu by nv points on the sheet in model space, computed at once; point (i, j) is at index j * nu + i.
- Arguments:
s : Sheet
nu : int
nv : int