Primitives
Abstract
Meshes.Primitive
— TypePrimitive{Dim,T}
We say that a geometry is a primitive when it can be expressed as a single entity with no parts (a.k.a. atomic). For example, a sphere is a primitive described in terms of a mathematical expression involving a metric and a radius. See https://en.wikipedia.org/wiki/Geometric_primitive.
Concrete
Point
Meshes.Point
— TypePoint(x₁, x₂, ..., xₙ)
Point((x₁, x₂, ..., xₙ))
Point{Dim,T}(x₁, x₂, ..., xₙ)
Point{Dim,T}((x₁, x₂, ..., xₙ))
A point in Dim
-dimensional space with coordinates of type T
.
The coordinates of the point are given with respect to the canonical Euclidean basis, and Integer
coordinates are converted to Float64
.
Examples
# 2D points
A = Point(0.0, 1.0) # double precision as expected
B = Point(0f0, 1f0) # single precision as expected
C = Point(0, 0) # Integer is converted to Float64 by design
D = Point2(0, 1) # explicitly ask for double precision
E = Point2f(0, 1) # explicitly ask for single precision
# 3D points
F = Point(1.0, 2.0, 3.0) # double precision as expected
G = Point(1f0, 2f0, 3f0) # single precision as expected
H = Point(1, 2, 3) # Integer is converted to Float64 by design
I = Point3(1, 2, 3) # explicitly ask for double precision
J = Point3f(1, 2, 3) # explicitly ask for single precision
Notes
- Type aliases are
Point1
,Point2
,Point3
,Point1f
,Point2f
,Point3f
Integer
coordinates are not supported because most geometric processing algorithms assume a continuous space. The conversion toFloat64
avoidsInexactError
and other unexpected results.
rand(Point3, 100) |> viz
Meshes.coordinates
— Methodcoordinates(point)
Return the coordinates of the point
with respect to the canonical Euclidean basis.
Base.:-
— Method-(A::Point, B::Point)
Return the Vec
associated with the direction from point B
to point A
.
Base.:+
— Method+(A::Point, v::Vec)
+(v::Vec, A::Point)
Return the point at the end of the vector v
placed at a reference (or start) point A
.
Base.:-
— Method-(A::Point, v::Vec)
-(v::Vec, A::Point)
Return the point at the end of the vector -v
placed at a reference (or start) point A
.
Ray
Meshes.Ray
— TypeRay(p, v)
A ray originating at point p
, pointed in direction v
. It can be called as r(t)
with t > 0
to cast it at p + t * v
.
Line
Meshes.Line
— TypeBezierCurve
Meshes.BezierCurve
— TypeBezierCurve(points)
A recursive Bézier curve with control points points
. See https://en.wikipedia.org/wiki/Bézier_curve. A point on the curve b
can be evaluated by calling b(t)
with t
between 0
and 1
. The evaluation method defaults to DeCasteljau's algorithm for accurate evaluation. Horner's method, faster with a large number of points but less precise, can be used via b(t, Horner())
.
Examples
BezierCurve(Point2[(0.,0.),(1.,-1.)])
BezierCurve((0.,0.), (1.,0.), (1.,1.)) |> viz
Plane
Meshes.Plane
— TypePlane(p, u, v)
A plane embedded in R³ passing through point p
, defined by non-parallel vectors u
and v
.
Plane(p, n)
Alternatively specify point p
and a given normal vector n
to the plane.
Box
Meshes.Box
— TypeBox(min, max)
An axis-aligned box with min
and max
corners. See https://en.wikipedia.org/wiki/Hyperrectangle.
Examples
Box(Point(0, 0, 0), Point(1, 1, 1))
Box((0, 0), (1, 1))
Box((0.,0.,0.), (1.,1.,1.)) |> viz
Ball/Sphere
Meshes.Ball
— TypeMeshes.Sphere
— TypeBall((0.,0.,0.), 1.) |> viz
Ellipsoid
Meshes.Ellipsoid
— TypeEllipsoid(radii, center=(0, 0, 0), rotation=I)
A 3D ellipsoid with given radii
, center
and rotation
.
Ellipsoid((3., 2., 1.)) |> viz
Disk/Circle
Meshes.Disk
— TypeDisk(plane, radius)
A disk embedded in 3-dimensional space on a given plane
with given radius
.
See also Circle
.
Meshes.Circle
— TypeCircle(plane, radius)
A circle embedded in 3-dimensional space on a given plane
with given radius
.
See also Disk
.
Cylinder/CylinderSurface
Meshes.Cylinder
— TypeCylinder(bottom, top, radius)
A solid circular cylinder embedded in R³ with given radius
, delimited by bottom
and top
planes.
Cylinder(start, finish, radius)
Alternatively, construct a right circular cylinder with given radius
along the segment with start
and finish
end points.
Cylinder(start, finish)
Or construct a right circular cylinder with unit radius along the segment with start
and finish
end points.
Cylinder(radius)
Finally, construct a right vertical circular cylinder with given radius
.
Meshes.CylinderSurface
— TypeCylinderSurface(bottom, top, radius)
A circular cylinder surface embedded in R³ with given radius
, delimited by bottom
and top
planes.
CylinderSurface(start, finish, radius)
Alternatively, construct a right circular cylinder surface with given radius
along the segment with start
and finish
end points.
CylinderSurface(start, finish)
Or construct a right circular cylinder surface with unit radius along the segment with start
and finish
end points.
CylinderSurface(radius)
Finally, construct a right vertical circular cylinder surface with given radius
.
Cylinder(1.0) |> viz
Cone/ConeSurface
Meshes.Cone
— TypeCone(base, apex)
A cone with base
disk and apex
. See https://en.wikipedia.org/wiki/Cone.
See also ConeSurface
.
Meshes.ConeSurface
— TypeConeSurface(base, apex)
A cone surface with base
disk and apex
. See https://en.wikipedia.org/wiki/Cone.
See also Cone
.
Cone(Disk(Plane((0,0,0), (0,0,1)), 1), (0,0,1)) |> viz
Frustum/FrustumSurface
Meshes.Frustum
— TypeFrustum(bot, top)
A frustum (truncated cone) with bot
and top
disks. See https://en.wikipedia.org/wiki/Frustum.
See also FrustumSurface
.
Meshes.FrustumSurface
— TypeFrustumSurface(bot, top)
A frustum (truncated cone) surface with bot
and top
disks. See https://en.wikipedia.org/wiki/Frustum.
See also Frustum
.
Frustum(
Disk(Plane((0,0,0), (0,0,1)), 2),
Disk(Plane((0,0,10), (0,0,1)), 1)
) |> viz
Torus
Meshes.Torus
— TypeTorus(center, normal, major, minor)
A torus centered at center
with axis of revolution directed by normal
and with radii major
and minor
.
Torus((0.,0.,0.), (1.,0.,0.), (0.,1.,0.), 0.2) |> viz
ParaboloidSurface
Meshes.ParaboloidSurface
— TypeParaboloidSurface(apex, radius, focallength)
A paraboloid surface embedded in R³ and extending up to a distance radius
from its focal axis, which is aligned along the z direction and passes through apex
(the apex of the paraboloid). The equation of the paraboloid is the following:
\[f(x, y) = \frac{(x - x_0)^2 + (y - y_0)^2}{4f} + z_0\qquad\text{for } x^2 + y^2 < r^2,\]
where $(x_0, y_0, z_0)$ is the apex of the parabola, $f$ is the focal length, and $r$ is the clip radius.
ParaboloidSurface(apex, radius)
This creates a paraboloid surface with focal length equal to 1.
ParaboloidSurface(apex)
This creates a paraboloid surface with focal length equal to 1 and a rim with unit radius.
ParaboloidSurface()
Same as above, but here the apex is at Apex(0, 0, 0)
.
See also https://en.wikipedia.org/wiki/Paraboloid.
ParaboloidSurface((5., 2., 4.), 1.0, 0.25) |> viz