Meshes
The two-dimensional embedded delta sets (EmbeddedDeltaSet2D
) in CombinatorialSpaces can be converted to and from mesh objects (Mesh
) in Meshes.jl. This is useful for interoperation with packages in the JuliaGeometry ecosystem.
Visualizing embedded delta sets
The following example shows how to import a mesh from an OBJ file, convert it into an embedded delta set, and render it as a 3D mesh using CairoMakie.
using FileIO, CairoMakie, CombinatorialSpaces
set_theme!(resolution=(800, 400))
catmesh = FileIO.load(File{format"OBJ"}(download(
"https://github.com/JuliaPlots/Makie.jl/raw/master/assets/cat.obj")))
catmesh_dset = EmbeddedDeltaSet2D(catmesh)
mesh(catmesh_dset, shading=false)

Alternatively, the embedded delta set can be visualized as a wireframe:
wireframe(catmesh_dset)

We can also construct and plot the dual complex for this mesh:
dual = EmbeddedDeltaDualComplex2D{Bool, Float32, Point{3,Float32}}(catmesh_dset)
subdivide_duals!(dual, Barycenter())
wireframe(dual)

API docs
CombinatorialSpaces.Meshes.loadmesh
— Methodloadmesh(s::Icosphere)
Load in a icosphere mesh.
CombinatorialSpaces.Meshes.loadmesh
— Methodloadmesh(s::Point_Map)
Load in a point map describing the connectivity of the toroidal mesh.
CombinatorialSpaces.Meshes.loadmesh
— Methodloadmesh(s::Rectangle_30x10)
Load in a rectangular mesh.
CombinatorialSpaces.Meshes.loadmesh
— Methodloadmesh(s::Torus_30x10)
Load in a toroidal mesh.
CombinatorialSpaces.Meshes.makeSphere
— MethodmakeSphere(minLat, maxLat, dLat, minLong, maxLong, dLong, radius)
Construct a spherical mesh (inclusively) bounded by the given latitudes and longitudes, discretized at dLat and dLong intervals, at the given radius from Earth's center.
Note that this construction returns a UV-sphere. DEC simulations are more accurate on meshes with (near) equilateral triangles, such as the icospheres available through loadmesh
.
We say that:
- 90°N is 0
- 90°S is 180
- Prime Meridian is 0
- 10°W is 355
We say that:
- (x=0,y=0,z=0) is at the center of the sphere
- the x-axis points toward 0°,0°
- the y-axis points toward 90°E,0°
- the z-axis points toward the North Pole
References:
List of common coordinate transformations
Examples
# Regular octahedron.
julia> s, npi, spi = makeSphere(0, 180, 90, 0, 360, 90, 1)
# 72 points along the unit circle on the x-y plane.
julia> s, npi, spi = makeSphere(90, 90, 0, 0, 360, 5, 1)
# 72 points along the equator at 0km from Earth's surface.
julia> s, npi, spi = makeSphere(90, 90, 1, 0, 360, 5, 6371)
# TIE-GCM grid at 90km altitude (with no poles, i.e. a bulbous cylinder).
julia> s, npi, spi = makeSphere(5, 175, 5, 0, 360, 5, 6371+90)
# TIE-GCM grid at 90km altitude (with South pole, i.e. a bowl).
julia> s, npi, spi = makeSphere(5, 180, 5, 0, 360, 5, 6371+90)
# TIE-GCM grid at 90km altitude (with poles, i.e. a sphere).
julia> s, npi, spi = makeSphere(0, 180, 5, 0, 360, 5, 6371+90)
# The Northern hemisphere of the TIE-GCM grid at 90km altitude.
julia> s, npi, spi = makeSphere(0, 180, 5, 0, 360, 5, 6371+90)
CombinatorialSpaces.Meshes.mirrored_mesh
— Methodfunction mirrored_mesh()
Return a mesh with triangles mirrored around a central axis.
CombinatorialSpaces.Meshes.triangulated_grid
— Functionfunction triangulated_grid(max_x, max_y, dx, dy, point_type, compress=true)
Triangulate the rectangle [0,maxx] x [0,maxy] by approximately equilateral triangles of width dx
and height dy
.
If compress
is true (default), then enforce that all rows of points are less than max_x
, otherwise, keep dx
as is.
CombinatorialSpaces.MeshInterop
— ModuleInteroperation with mesh files.
This module enables delta sets to be imported from mesh files supported by MeshIO.jl and for delta sets to be converted to meshes, mainly for the purposes of plotting. Meshes are represented by the GeometryBasics.Mesh
type.
CombinatorialSpaces.MeshOptimization.SimulatedAnnealing
— Typestruct SimulatedAnnealing
The simulated annealing algorithm's parameters for mesh optimization.
Keyword arguments:
ϵ
: Multiply the randomly-sampled j ~ N(0,1) by this number. (Defaults to 1e-3
)
epochs
: The number of times to iterate over each point in the mesh. (Defaults to 100
)
debug_epochs
: When debugging is active, print cost
every debug_epochs
epochs. (Defaults to 10
)
hold_boundaries
: Whether to hold the boundaries of the mesh fixed. (Defaults to true
)
anneal
: Whether to accept jitters than increase the cost function. (Defaults to true
)
jitter3D
: Whether to jitter in the z-dimension, too. (Defaults to false
)
spherical
: Whether to constrain the new jittered point to lie on the sphere. (Defaults to false
)
radius
: If spherical
is true
, the radius of the sphere. (Defaults to 1.0
)
cost
: The cost function to use when annealing. (Defaults to equilaterality
.)
cooling_schedule
: The cooling schedule to be used when annealing. (Defaults to linear_cooling_schedule
.)
See also: optimize_mesh!
.
CombinatorialSpaces.MeshOptimization.equilaterality
— Methodfunction equilaterality(e0, e1, e2)
Given three edge lengths, compute the failure to be equilateral, using:
\[(E_0 - ar{E})^2 + (E_1 - ar{E})^2 + (E_1 - ar{E})^2,\]
where $E_0, E_1, E_2 = |e_0, e_1, e_2|_1$, and $ar{E}$ is their average.
0 implies all edge lengths are equal and the triangle is equilateral.
CombinatorialSpaces.MeshOptimization.equilaterality
— Methodfunction equilaterality(s::HasDeltaSet2D)
Compute the sum of squared equilaterality of each triangle over a mesh.
0 implies all triangles are equilateral.
CombinatorialSpaces.MeshOptimization.optimize_mesh!
— Methodfunction optimize_mesh!(s::HasDeltaSet2D, alg::SimulatedAnnealing, noise_generator::Function)
Optimize the given mesh using a simulated annealing algorithm.
Note that the selection probability is directly calculated (without exp), and does not depend on the magnitude of error improvement.
See also: SimulatedAnnealing
.