Documentation
¶
Overview ¶
Package toolbox3d provides a collection of parts for building practical 3D models for 3D prints.
Index ¶
- Constants
- func HeightMapToSolid(hm *HeightMap) model3d.Solid
- func HeightMapToSolidBidir(hm *HeightMap) model3d.Solid
- func Teardrop3D(p1, p2 model3d.Coord3D, radius float64) model3d.Solid
- type Axis
- type AxisPinch
- type AxisSqueeze
- type Equirect
- type GearProfile
- type HeightMap
- func (h *HeightMap) AddHeightMap(h1 *HeightMap) bool
- func (h *HeightMap) AddSphere(center model2d.Coord, radius float64) bool
- func (h *HeightMap) Copy() *HeightMap
- func (h *HeightMap) HeightSquaredAt(c model2d.Coord) float64
- func (h *HeightMap) HigherAt(c model2d.Coord, height float64) bool
- func (h *HeightMap) MaxHeight() float64
- type HelicalGear
- type Ramp
- type ScrewSolid
- type SmartSqueeze
- type SpurGear
- type Teardrop2D
Constants ¶
const ( AxisX = 0 AxisY = 1 AxisZ = 2 )
Variables ¶
This section is empty.
Functions ¶
func HeightMapToSolid ¶ added in v0.2.8
HeightMapToSolid creates a 3D solid representing the volume under a height map and above the Z plane.
func HeightMapToSolidBidir ¶ added in v0.2.8
HeightMapToSolidBidir is like HeightMapToSolid, but it mirrors the solid across the Z plane to make it symmetric.
Types ¶
type AxisPinch ¶ added in v0.2.4
type AxisPinch struct { // The axis to pinch along. Axis Axis // Bounds on the axis to pinch. Min float64 Max float64 // Power controls how much pinching is performed. // A Power of 1 means no pinching. // Higher powers perform spatial pinching. // Lower powers un-pinch a region, moving coordinates // further from the center. // Reciprocal powers undo each other. Power float64 }
AxisPinch is similar to AxisSqueeze, except that it does not affect space outside of the pinched region.
Coordinates within the pinched region are pulled to the center of the region by following some polynomial.
AxisPinch can be used to prevent jagged edges on the tops and bottoms of marching cubes solids, by pinching the uneven edges into a much flatter surface.
func (*AxisPinch) ApplyBounds ¶ added in v0.2.4
ApplyBounds pinches the bounds.
type AxisSqueeze ¶
type AxisSqueeze struct { // The axis to compress. Axis Axis // Bounds on the axis to compress. Min float64 Max float64 // This is (new length / old length). // For example, if we use a squeeze ratio of 0.1, // then squeezing 2 inches will bring it down to // 0.2 inches. Ratio float64 }
AxisSqueeze is a coordinate transformation which squeezes some section of space into a much smaller amount of space along some axis.
AxisSqueeze can be used to efficiently produce meshes which are mostly uniform along some axis, for example a tall cylinder.
func (*AxisSqueeze) Apply ¶
func (a *AxisSqueeze) Apply(c model3d.Coord3D) model3d.Coord3D
Apply squeezes the coordinate.
func (*AxisSqueeze) ApplyBounds ¶
func (a *AxisSqueeze) ApplyBounds(min, max model3d.Coord3D) (newMin, newMax model3d.Coord3D)
ApplyBounds squeezes the bounds.
func (*AxisSqueeze) Inverse ¶
func (a *AxisSqueeze) Inverse() model3d.Transform
Inverse creates an AxisSqueeze that undoes the squeeze performed by a.
type Equirect ¶
type Equirect struct {
// contains filtered or unexported fields
}
An Equirect is an equirectangular bitmap representing colors on a sphere.
It can be used, for example, to aid in implementing a 3D polar function.
func NewEquirect ¶
NewEquirect creates an Equirect from an image. It is assumed that the top of the image is north (positive latitude), the bottom of the image is south, the left is west (negative longitude), the right is east (positive longitude).
type GearProfile ¶
func InvoluteGearProfile ¶
func InvoluteGearProfile(pressureAngle, module, clearance float64, numTeeth int) GearProfile
InvoluteGearProfile creates a GearProfile for a standard involute gear with the given specs.
func InvoluteGearProfileSizes ¶
func InvoluteGearProfileSizes(pressureAngle, module, addendum, dedendum float64, numTeeth int) GearProfile
InvoluteGearProfileSizes creates an involute gear profile using different parameters than InvoluteGearProfile.
type HeightMap ¶ added in v0.2.8
type HeightMap struct { // 2D boundaries of the grid. Min model2d.Coord Max model2d.Coord // Spacing of the grid elements. Delta float64 // Row-major data storing the squared heights at every // grid element. Rows int Cols int Data []float64 }
A HeightMap maps a 2D grid of points to non-negative Z values.
The HeightMap can be updated by adding hemispheres and other HeightMaps. These operations are union operators, in that they never reduce the height at any given grid point.
The HeightMap automatically performs interpolation for reads to provide the appearance of a continuous curve.
func NewHeightMap ¶ added in v0.2.8
NewHeightMap fills a rectangular 2D region with a height map that starts out at zero height.
The maxSize argument limits the number of rows and columns, and will be the greater of the two dimensions in the data grid.
func (*HeightMap) AddHeightMap ¶ added in v0.2.8
AddHeightMap writes the union of h and h1 to h.
This is optimized for the case when h and h1 are laid out exactly the same, with the same grid spacing and boundaries.
One use case for this API is to combine multiple height maps that were generated on different Goroutines.
Returns true if h1 modified h, or false otherwise.
func (*HeightMap) AddSphere ¶ added in v0.2.8
AddSphere adds a hemisphere to the height map, updating any cells that were lower than the corresponding point on the hemisphere.
Returns true if the sphere changed the height map in any way, or false if the sphere was already covered.
func (*HeightMap) HeightSquaredAt ¶ added in v0.2.8
HeightSquaredAt gets the interpolated square of the height at any coordinate.
The coordinate may be out of bounds.
type HelicalGear ¶
func (*HelicalGear) Max ¶
func (h *HelicalGear) Max() model3d.Coord3D
func (*HelicalGear) Min ¶
func (h *HelicalGear) Min() model3d.Coord3D
type Ramp ¶
type Ramp struct { model3d.Solid // P1 is the tip of the ramp, where the scale is 0. // Any point further in the direction of P1 will have // a scale of zero. P1 model3d.Coord3D // P2 is the base of the ramp, where the scale is 1. // Any point further in the direction of P2 will have // a scale of one. P2 model3d.Coord3D }
A Ramp wraps an existing solid and gradually increases the scale of the solid from 0% to 100% along a given axis.
This makes it easier to make shapes like upside-down pyramids and cones for use in FDM printing without supports.
type ScrewSolid ¶
type ScrewSolid struct { // P1 is the center of the start of the screw. P1 model3d.Coord3D // P2 is the center of the end of the screw. P2 model3d.Coord3D // Radius is the maximum radius of the screw, // including grooves. Radius float64 // GrooveSize is the size of the grooves. // This may not exceed Radius. GrooveSize float64 // Pointed can be set to true to indicate that the tip // at the P2 end should be cut off at a 45 degree // angle (in the shape of a cone). // Can be used for internal screw holes to avoid // support. Pointed bool }
A ScrewSolid is a model3d.Solid implementation of screws. It can also be used for screw holes, by combining it with model3d.SubtractedSolid.
Screws are similar to cylinders, so many of the fields are analogous to model3d.CylinderSolid.
func (*ScrewSolid) Max ¶
func (s *ScrewSolid) Max() model3d.Coord3D
func (*ScrewSolid) Min ¶
func (s *ScrewSolid) Min() model3d.Coord3D
type SmartSqueeze ¶ added in v0.2.7
type SmartSqueeze struct { // Axis is the axis to squeeze along. Axis Axis // SqueezeRatio is the axis squeeze ratio to use. SqueezeRatio float64 // PinchRange specifies how much space should be added // before and after a pinch to avoid singularities. // Should be small, but larger than the marching cubes // epsilon. PinchRange float64 // PinchPower is the power for pinches. PinchPower float64 // Ranges along the axis that cannot be squeezed. // Typically ranges should be added via AddUnsqueezable(). Unsqueezable [][2]float64 // Values of the axis at which a pinch should be used // to flatten plateaus. // Typically pinches will be added via AddPinch(). Pinches []float64 }
SmartSqueeze creates a transformation to squeeze a model along a certain axis without affecting certain regions that don't lend themselves to squeezing.
func (*SmartSqueeze) AddPinch ¶ added in v0.2.7
func (s *SmartSqueeze) AddPinch(val float64)
AddPinch adds an axis value at which the coordinates should be squeezed to flatten plateaus.
func (*SmartSqueeze) AddUnsqueezable ¶ added in v0.2.7
func (s *SmartSqueeze) AddUnsqueezable(min, max float64)
AddUnsqueezable adds a range of axis values in which no squeezing should be performed.
func (*SmartSqueeze) MarchingCubesSearch ¶ added in v0.2.7
func (s *SmartSqueeze) MarchingCubesSearch(solid model3d.Solid, delta float64, iters int) *model3d.Mesh
MachingCubesSearch uses the smart squeeze to convert a solid into a mesh efficiently.
In particular, the model is transformed, meshified, and then the inverse transformation is applied.
For usage information, see model3d.MarchingCubesSearch.
type Teardrop2D ¶ added in v0.2.8
type Teardrop2D struct { // Center is the center of the circle. Center model2d.Coord // Radius is the radius of the circle. Radius float64 // Direction is the direction in which the tip of the // tangent triangle is pointing. // If this is the zero vector, then a unit vector in // the Y direction is used. Direction model2d.Coord }
Teardrop2D is a 2D solid in a "teardrop" shape, i.e. a circle with a tangent triangle pointing off in one direction.
This can be used to cut circles out of shapes while avoiding support structures in FDM printing.
The shape, rendered in ASCII, looks like so:
--(&)-- @@@@/ (@@@@ @@@ @@@ /@@ @@. @@ @@ @@ @@ &@ @ @% @@ @@ @@ @@# @@@ @@@ @@@ &@@ @@* @@& @@@ @@@ @@# @@@ ^
func (*Teardrop2D) Max ¶ added in v0.2.8
func (t *Teardrop2D) Max() model2d.Coord
func (*Teardrop2D) Min ¶ added in v0.2.8
func (t *Teardrop2D) Min() model2d.Coord