11# Meshes
22
3+ A mesh consists of a sequence of [ ` Polytope ` ] ( @ref ) s. For example, in a 3D dimensional space, a mesh would be a sequence of triangles (2-simplexes).
4+
35## Types
46
57* [ ` AbstractMesh ` ] ( @ref )
68* [ ` Mesh ` ] ( @ref )
79
810## How to create a mesh
911
12+ To create a mesh one can provide one the following.
13+ * A list of points and faces.
14+ * A list of polytopes.
15+
16+ First, let's create four points and four faces. Each face is an integer connecting the points according to their array index.
17+
18+ ``` jldoctest
19+ julia> mypoints = [
20+ Point3f(0,0,0),
21+ Point3f(0,0,1),
22+ Point3f(0,1,0),
23+ Point3f(1,0,0)
24+ ]
25+ 4-element Vector{Point{3, Float32}}:
26+ [0.0, 0.0, 0.0]
27+ [0.0, 0.0, 1.0]
28+ [0.0, 1.0, 0.0]
29+ [1.0, 0.0, 0.0]
30+
31+ julia> myfaces = [
32+ TriangleFace(1,2,3),
33+ TriangleFace(1,2,4),
34+ TriangleFace(1,3,4),
35+ TriangleFace(2,3,4)
36+ ]
37+ 4-element Vector{TriangleFace{Int64}}:
38+ TriangleFace(1, 2, 3)
39+ TriangleFace(1, 2, 4)
40+ TriangleFace(1, 3, 4)
41+ TriangleFace(2, 3, 4)
42+
43+
44+ julia> mymesh = Mesh(mypoints, myfaces)
45+ Mesh{3, Float32, Triangle}:
46+ Triangle(Float32[0.0, 0.0, 0.0], Float32[0.0, 0.0, 1.0], Float32[0.0, 1.0, 0.0])
47+ Triangle(Float32[0.0, 0.0, 0.0], Float32[0.0, 0.0, 1.0], Float32[1.0, 0.0, 0.0])
48+ Triangle(Float32[0.0, 0.0, 0.0], Float32[0.0, 1.0, 0.0], Float32[1.0, 0.0, 0.0])
49+ Triangle(Float32[0.0, 0.0, 1.0], Float32[0.0, 1.0, 0.0], Float32[1.0, 0.0, 0.0])
50+ ```
51+
52+ As seen above, the mesh is just a sequence of triangles. Next, let's create a similar ` Mesh ` by providing the triangles directly.
53+
54+ ``` jldoctest
55+ julia> mytriangles = [
56+ Triangle(pts[[1,2,3]]...),
57+ Triangle(pts[[1,2,4]]...),
58+ Triangle(pts[[1,3,4]]...),
59+ Triangle(pts[[2,3,4]]...)
60+ ]
61+ 4-element Vector{GeometryBasics.Ngon{3, Float32, 3, Point{3, Float32}}}:
62+ Triangle(Float32[0.0, 0.0, 0.0], Float32[0.0, 0.0, 1.0], Float32[0.0, 1.0, 0.0])
63+ Triangle(Float32[0.0, 0.0, 0.0], Float32[0.0, 0.0, 1.0], Float32[1.0, 0.0, 0.0])
64+ Triangle(Float32[0.0, 0.0, 0.0], Float32[0.0, 1.0, 0.0], Float32[1.0, 0.0, 0.0])
65+ Triangle(Float32[0.0, 0.0, 1.0], Float32[0.0, 1.0, 0.0], Float32[1.0, 0.0, 0.0])
66+
67+ julia> mymesh2 = Mesh(mytriangles)
68+ Mesh{3, Float32, Triangle}:
69+ Triangle(Float32[0.0, 0.0, 0.0], Float32[0.0, 0.0, 1.0], Float32[0.0, 1.0, 0.0])
70+ Triangle(Float32[0.0, 0.0, 0.0], Float32[0.0, 0.0, 1.0], Float32[1.0, 0.0, 0.0])
71+ Triangle(Float32[0.0, 0.0, 0.0], Float32[0.0, 1.0, 0.0], Float32[1.0, 0.0, 0.0])
72+ Triangle(Float32[0.0, 0.0, 1.0], Float32[0.0, 1.0, 0.0], Float32[1.0, 0.0, 0.0])
73+ ```
74+
75+
1076### Meshing.jl
1177
1278### MeshIO.jl
@@ -22,3 +88,27 @@ The following functions can be called on an [`AbstractMesh`](@ref) to access its
2288* [ ` texturecoordinates ` ] ( @ref )
2389* [ ` normals ` ] ( @ref )
2490
91+
92+ ``` jldoctest
93+ julia> GeometryBasics.faces(mymesh)
94+ 4-element Vector{TriangleFace{Int64}}:
95+ TriangleFace(1, 2, 3)
96+ TriangleFace(1, 2, 4)
97+ TriangleFace(1, 3, 4)
98+ TriangleFace(2, 3, 4)
99+
100+ julia> GeometryBasics.coordinates(mymesh)
101+ 4-element Vector{Point{3, Float32}}:
102+ [0.0, 0.0, 0.0]
103+ [0.0, 0.0, 1.0]
104+ [0.0, 1.0, 0.0]
105+ [1.0, 0.0, 0.0]
106+ ```
107+
108+ Note that these functions may not apply to all meshes. For example, ` mymesh2 `
109+ above was not created with ` Faces ` so ` faces ` will return ` nothing ` .
110+
111+ ``` jldoctest
112+ julia> GeometryBasics.faces(mymesh2)
113+
114+ ```
0 commit comments