Safe Haskell | None |
---|---|
Language | Haskell2010 |
Synopsis
- type ℝ = Double
- type ℝ2 = V2 ℝ
- type ℝ3 = V3 ℝ
- data SymbolicObj2
- data SymbolicObj3
- data ExtrudeMScale
- class (Applicative f, Eq a, Eq (f a), Num a, Num (f a)) => Object obj f a | obj -> f a
- translate :: Object obj f a => f a -> obj -> obj
- scale :: Object obj f a => f a -> obj -> obj
- mirror :: Object obj f a => f a -> obj -> obj
- complement :: Object obj f a => obj -> obj
- union :: Object obj f a => [obj] -> obj
- unionR :: Object obj f a => ℝ -> [obj] -> obj
- intersect :: Object obj f a => [obj] -> obj
- intersectR :: Object obj f a => ℝ -> [obj] -> obj
- difference :: Object obj f a => obj -> [obj] -> obj
- differenceR :: Object obj f a => ℝ -> obj -> [obj] -> obj
- implicit :: Object obj f a => (f a -> a) -> (f a, f a) -> obj
- shell :: Object obj f a => ℝ -> obj -> obj
- outset :: Object obj f a => ℝ -> obj -> obj
- emptySpace :: Object obj f a => obj
- fullSpace :: Object obj f a => obj
- withRounding :: Object obj f a => ℝ -> obj -> obj
- square :: Bool -> ℝ2 -> SymbolicObj2
- rect :: ℝ2 -> ℝ2 -> SymbolicObj2
- circle :: ℝ -> SymbolicObj2
- polygon :: [ℝ2] -> SymbolicObj2
- rotate :: ℝ -> SymbolicObj2 -> SymbolicObj2
- transform :: M33 ℝ -> SymbolicObj2 -> SymbolicObj2
- pack2 :: ℝ2 -> ℝ -> [SymbolicObj2] -> Maybe SymbolicObj2
- cube :: Bool -> ℝ3 -> SymbolicObj3
- rect3 :: ℝ3 -> ℝ3 -> SymbolicObj3
- sphere :: ℝ -> SymbolicObj3
- cylinder :: ℝ -> ℝ -> SymbolicObj3
- cylinder2 :: ℝ -> ℝ -> ℝ -> SymbolicObj3
- rotate3 :: ℝ3 -> SymbolicObj3 -> SymbolicObj3
- rotate3V :: ℝ -> ℝ3 -> SymbolicObj3 -> SymbolicObj3
- pack3 :: ℝ2 -> ℝ -> [SymbolicObj3] -> Maybe SymbolicObj3
- transform3 :: M44 ℝ -> SymbolicObj3 -> SymbolicObj3
- extrude :: SymbolicObj2 -> ℝ -> SymbolicObj3
- extrudeM :: Either ℝ (ℝ -> ℝ) -> ExtrudeMScale -> Either ℝ2 (ℝ -> ℝ2) -> SymbolicObj2 -> Either ℝ (ℝ2 -> ℝ) -> SymbolicObj3
- extrudeOnEdgeOf :: SymbolicObj2 -> SymbolicObj2 -> SymbolicObj3
- rotateExtrude :: ℝ -> Either ℝ2 (ℝ -> ℝ2) -> Either ℝ (ℝ -> ℝ) -> SymbolicObj2 -> SymbolicObj3
- runOpenscad :: ScadOpts -> [String] -> String -> IO (VarLookup, [SymbolicObj2], [SymbolicObj3], [Message])
- writeSVG :: ℝ -> FilePath -> SymbolicObj2 -> IO ()
- writePNG2 :: ℝ -> FilePath -> SymbolicObj2 -> IO ()
- writeDXF2 :: ℝ -> FilePath -> SymbolicObj2 -> IO ()
- writeSCAD2 :: ℝ -> FilePath -> SymbolicObj2 -> IO ()
- writeGCodeHacklabLaser :: ℝ -> FilePath -> SymbolicObj2 -> IO ()
- writeSTL :: ℝ -> FilePath -> SymbolicObj3 -> IO ()
- writeBinSTL :: ℝ -> FilePath -> SymbolicObj3 -> IO ()
- writeOBJ :: ℝ -> FilePath -> SymbolicObj3 -> IO ()
- writeTHREEJS :: ℝ -> FilePath -> SymbolicObj3 -> IO ()
- writeSCAD3 :: ℝ -> FilePath -> SymbolicObj3 -> IO ()
- writePNG3 :: ℝ -> FilePath -> SymbolicObj3 -> IO ()
- data V2 a = V2 !a !a
- data V3 a = V3 !a !a !a
- data Quaternion a = Quaternion !a !(V3 a)
Types
A type synonym for Double
. When used in the context of positions or
sizes, measured in units of millimeters. When used as in the context of
a rotation, measured in radians.
A pair of two Double
s. When used as an area or position vector, measured
in millimeters squared.
A triple of Double
s. When used as a volume or position vector, measured
in millimeters cubed. When used as a rotation, interpreted as Euler angles
measured in radians.
data SymbolicObj2 Source #
A symbolic 2D object format. We want to have symbolic objects so that we can accelerate rendering & give ideal meshes for simple cases.
Instances
data SymbolicObj3 Source #
A symbolic 3D format!
Instances
data ExtrudeMScale Source #
Instances
Shared operations
class (Applicative f, Eq a, Eq (f a), Num a, Num (f a)) => Object obj f a | obj -> f a Source #
Operations available on both 2D and 3D objects. The obvious omission of
rotation operations from this class are a technical limitation, and are
instead provided by rotate
and rotate3
.
Library users shouldn't need to provide new instances of this class.
Instances
Object SymbolicObj3 V3 ℝ Source # | |
Defined in Graphics.Implicit.Primitives _Shared :: Prism' SymbolicObj3 (SharedObj SymbolicObj3 V3 ℝ) Source # getBox :: SymbolicObj3 -> (V3 ℝ, V3 ℝ) Source # getImplicit' :: ObjectContext -> SymbolicObj3 -> V3 ℝ -> ℝ Source # | |
Object SymbolicObj2 V2 ℝ Source # | |
Defined in Graphics.Implicit.Primitives _Shared :: Prism' SymbolicObj2 (SharedObj SymbolicObj2 V2 ℝ) Source # getBox :: SymbolicObj2 -> (V2 ℝ, V2 ℝ) Source # getImplicit' :: ObjectContext -> SymbolicObj2 -> V2 ℝ -> ℝ Source # |
:: Object obj f a | |
=> f a | Vector to translate by |
-> obj | Object to translate |
-> obj | Resulting object |
Translate an object by a vector of appropriate dimension.
:: Object obj f a | |
=> f a | Amount to scale by |
-> obj | Object to scale |
-> obj | Resulting scaled object |
Scale an object
:: Object obj f a | |
=> f a | Vector defining the hyperplane |
-> obj | Object to mirror |
-> obj | Resulting object |
Mirror an object across the hyperplane whose normal is a given vector.
Rounded union
:: Object obj f a | |
=> ℝ | The radius (in mm) of rounding |
-> [obj] | Objects to intersect |
-> obj | Resulting object |
Rounded minimum
difference :: Object obj f a => obj -> [obj] -> obj Source #
:: Object obj f a | |
=> ℝ | The radius (in mm) of rounding |
-> obj | Base object |
-> [obj] | Objects to subtract from the base |
-> obj | Resulting object |
Rounded difference
:: Object obj f a | |
=> (f a -> a) | Implicit function |
-> (f a, f a) | Bounding box |
-> obj | Resulting object |
Make a shell of an object.
Outset of an object.
emptySpace :: Object obj f a => obj Source #
The object that fills no space
withRounding :: Object obj f a => ℝ -> obj -> obj Source #
Set the current object-rounding value for the given object. The rounding value is measured in units of distance, and describes the radius of rounded corners.
This can be used to change the shape of more primitive forms, for example,
we can make a cube with rounded corners via withRounding 5 (
.cube
True
20)
applies the rounding withRounding
r objr
all primitives objects in
obj
, so long as they have the same dimensionality. That is to say,
the current object-rounding value set in 3D will not apply to extruded 2D
shapes.
2D primitive shapes
:: Bool | Centered? |
-> ℝ2 | Size |
-> SymbolicObj2 | Resulting square (bottom right = (0,0) ) |
A square
:: ℝ | radius of the circle |
-> SymbolicObj2 | resulting circle |
2D operations
rotate :: ℝ -> SymbolicObj2 -> SymbolicObj2 Source #
transform :: M33 ℝ -> SymbolicObj2 -> SymbolicObj2 Source #
Transform a 2D object using a 3x3 matrix representing affine transformation (OpenSCAD multmatrix)
:: ℝ2 | Area to pack |
-> ℝ | Separation between objects |
-> [SymbolicObj2] | Objects to pack |
-> Maybe SymbolicObj2 |
|
Attempt to pack multiple 2D objects into a fixed area.
3D primitive shapes
:: Bool | Centered? |
-> ℝ3 | Size |
-> SymbolicObj3 | Resuting cube. (0,0,0) is bottom left if |
A cube
:: ℝ3 | Bottom.. corner |
-> ℝ3 | Top right... corner |
-> SymbolicObj3 | Resuting cube |
A rectangular prism
:: ℝ | Radius of the sphere |
-> SymbolicObj3 | Resulting sphere |
:: ℝ | Radius of the cylinder |
-> ℝ | Height of the cylinder |
-> SymbolicObj3 | Resulting cylinder |
:: ℝ | Radius of the cylinder |
-> ℝ | Second radius of the cylinder |
-> ℝ | Height of the cylinder |
-> SymbolicObj3 | Resulting cylinder |
A conical frustum --- ie. a cylinder with different radii at either end.
3D operations
rotate3 :: ℝ3 -> SymbolicObj3 -> SymbolicObj3 Source #
Rotate a 3D object via an Euler angle, measured in radians, along the world axis.
:: ℝ | Angle of rotation |
-> ℝ3 | Axis of rotation |
-> SymbolicObj3 | |
-> SymbolicObj3 |
Rotate a 3D object along an arbitrary axis.
:: ℝ2 | Area to pack |
-> ℝ | Separation between objects |
-> [SymbolicObj3] | Objects to pack |
-> Maybe SymbolicObj3 |
|
Attempt to pack multiple 3D objects into a fixed area. The z
coordinate
of each object is dropped, and the resulting packed objects will all be on
the same plane.
FIXME: shouldn't this pack into a 3d area, or have a 3d equivalent?
transform3 :: M44 ℝ -> SymbolicObj3 -> SymbolicObj3 Source #
Transform a 3D object using a 4x4 matrix representing affine transformation (OpenSCAD multmatrix)
Extrusions into 3D
:: SymbolicObj2 | |
-> ℝ | Extrusion height |
-> SymbolicObj3 |
Extrude a 2d object upwards. The current object-rounding value set by
withRounding
is used to round the caps, but is not used by the 2D object.
:: Either ℝ (ℝ -> ℝ) | twist |
-> ExtrudeMScale | scale |
-> Either ℝ2 (ℝ -> ℝ2) | translate |
-> SymbolicObj2 | object to extrude |
-> Either ℝ (ℝ2 -> ℝ) | height to extrude to |
-> SymbolicObj3 |
The current object-rounding value set by withRounding
is used to round
the caps, but is not used by the 2D object.
OpenScad support
runOpenscad :: ScadOpts -> [String] -> String -> IO (VarLookup, [SymbolicObj2], [SymbolicObj3], [Message]) Source #
Small wrapper of our parser to handle parse errors, etc.
2D exporters
:: ℝ | Rendering resolution, in millimeters. Smaller values produce exports more faithful to the implicit model, at the expense of taking O(n^-2) more time. |
-> FilePath | |
-> SymbolicObj2 | |
-> IO () |
:: ℝ | Rendering resolution, in millimeters. Smaller values produce exports more faithful to the implicit model, at the expense of taking O(n^-2) more time. |
-> FilePath | |
-> SymbolicObj2 | |
-> IO () |
:: ℝ | Rendering resolution, in millimeters. Smaller values produce exports more faithful to the implicit model, at the expense of taking O(n^-2) more time. |
-> FilePath | |
-> SymbolicObj2 | |
-> IO () |
:: ℝ | Rendering resolution, in millimeters. Smaller values produce exports more faithful to the implicit model, at the expense of taking O(n^-2) more time. |
-> FilePath | |
-> SymbolicObj2 | |
-> IO () |
writeGCodeHacklabLaser Source #
:: ℝ | Rendering resolution, in millimeters. Smaller values produce exports more faithful to the implicit model, at the expense of taking O(n^-2) more time. |
-> FilePath | |
-> SymbolicObj2 | |
-> IO () |
3D exporters
:: ℝ | Rendering resolution, in millimeters. Smaller values produce exports more faithful to the implicit model, at the expense of taking O(n^-3) more time. |
-> FilePath | |
-> SymbolicObj3 | |
-> IO () |
:: ℝ | Rendering resolution, in millimeters. Smaller values produce exports more faithful to the implicit model, at the expense of taking O(n^-3) more time. |
-> FilePath | |
-> SymbolicObj3 | |
-> IO () |
:: ℝ | Rendering resolution, in millimeters. Smaller values produce exports more faithful to the implicit model, at the expense of taking O(n^-3) more time. |
-> FilePath | |
-> SymbolicObj3 | |
-> IO () |
:: ℝ | Rendering resolution, in millimeters. Smaller values produce exports more faithful to the implicit model, at the expense of taking O(n^-3) more time. |
-> FilePath | |
-> SymbolicObj3 | |
-> IO () |
:: ℝ | Rendering resolution, in millimeters. Smaller values produce exports more faithful to the implicit model, at the expense of taking O(n^-3) more time. |
-> FilePath | |
-> SymbolicObj3 | |
-> IO () |
:: ℝ | Rendering resolution, in millimeters. Smaller values produce exports more faithful to the implicit model, at the expense of taking O(n^-3) more time. |
-> FilePath | |
-> SymbolicObj3 | |
-> IO () |
Export a PNG of the SymbolicObj3
. The projection is with a front-facing
camera, so the coordinate system is (left to right, front to back, down to
up)
.
Linear re-exports
A 2-dimensional vector
>>>
pure 1 :: V2 Int
V2 1 1
>>>
V2 1 2 + V2 3 4
V2 4 6
>>>
V2 1 2 * V2 3 4
V2 3 8
>>>
sum (V2 1 2)
3
V2 !a !a |
Instances
A 3-dimensional vector
V3 !a !a !a |
Instances
data Quaternion a #
Quaternions
Quaternion !a !(V3 a) |