From 0800bd51a825a744d24207b03a57cbda23973197 Mon Sep 17 00:00:00 2001 From: Mark Kittisopikul Date: Tue, 21 Nov 2023 16:47:30 -0500 Subject: [PATCH 1/2] Add initial mesh documentation --- docs/src/meshes.md | 90 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) diff --git a/docs/src/meshes.md b/docs/src/meshes.md index bdd74b88..0374ad12 100644 --- a/docs/src/meshes.md +++ b/docs/src/meshes.md @@ -1,5 +1,7 @@ # Meshes +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). + ## Types * [`AbstractMesh`](@ref) @@ -7,6 +9,70 @@ ## How to create a mesh +To create a mesh one can provide one the following. +* A list of points and faces. +* A list of polytopes. + +First, let's create four points and four faces. Each face is an integer connecting the points according to their array index. + +```jldoctest +julia> mypoints = [ + Point3f(0,0,0), + Point3f(0,0,1), + Point3f(0,1,0), + Point3f(1,0,0) + ] +4-element Vector{Point{3, Float32}}: + [0.0, 0.0, 0.0] + [0.0, 0.0, 1.0] + [0.0, 1.0, 0.0] + [1.0, 0.0, 0.0] + +julia> myfaces = [ + TriangleFace(1,2,3), + TriangleFace(1,2,4), + TriangleFace(1,3,4), + TriangleFace(2,3,4) + ] +4-element Vector{TriangleFace{Int64}}: + TriangleFace(1, 2, 3) + TriangleFace(1, 2, 4) + TriangleFace(1, 3, 4) + TriangleFace(2, 3, 4) + + +julia> mymesh = Mesh(mypoints, myfaces) +Mesh{3, Float32, Triangle}: + Triangle(Float32[0.0, 0.0, 0.0], Float32[0.0, 0.0, 1.0], Float32[0.0, 1.0, 0.0]) + Triangle(Float32[0.0, 0.0, 0.0], Float32[0.0, 0.0, 1.0], Float32[1.0, 0.0, 0.0]) + Triangle(Float32[0.0, 0.0, 0.0], Float32[0.0, 1.0, 0.0], Float32[1.0, 0.0, 0.0]) + Triangle(Float32[0.0, 0.0, 1.0], Float32[0.0, 1.0, 0.0], Float32[1.0, 0.0, 0.0]) +``` + +As seen above, the mesh is just a sequence of triangles. Next, let's create a similar `Mesh` by providing the triangles directly. + +```jldoctest +julia> mytriangles = [ + Triangle(pts[[1,2,3]]...), + Triangle(pts[[1,2,4]]...), + Triangle(pts[[1,3,4]]...), + Triangle(pts[[2,3,4]]...) + ] +4-element Vector{GeometryBasics.Ngon{3, Float32, 3, Point{3, Float32}}}: + Triangle(Float32[0.0, 0.0, 0.0], Float32[0.0, 0.0, 1.0], Float32[0.0, 1.0, 0.0]) + Triangle(Float32[0.0, 0.0, 0.0], Float32[0.0, 0.0, 1.0], Float32[1.0, 0.0, 0.0]) + Triangle(Float32[0.0, 0.0, 0.0], Float32[0.0, 1.0, 0.0], Float32[1.0, 0.0, 0.0]) + Triangle(Float32[0.0, 0.0, 1.0], Float32[0.0, 1.0, 0.0], Float32[1.0, 0.0, 0.0]) + +julia> mymesh2 = Mesh(mytriangles) +Mesh{3, Float32, Triangle}: + Triangle(Float32[0.0, 0.0, 0.0], Float32[0.0, 0.0, 1.0], Float32[0.0, 1.0, 0.0]) + Triangle(Float32[0.0, 0.0, 0.0], Float32[0.0, 0.0, 1.0], Float32[1.0, 0.0, 0.0]) + Triangle(Float32[0.0, 0.0, 0.0], Float32[0.0, 1.0, 0.0], Float32[1.0, 0.0, 0.0]) + Triangle(Float32[0.0, 0.0, 1.0], Float32[0.0, 1.0, 0.0], Float32[1.0, 0.0, 0.0]) +``` + + ### Meshing.jl ### MeshIO.jl @@ -22,3 +88,27 @@ The following functions can be called on an [`AbstractMesh`](@ref) to access its * [`texturecoordinates`](@ref) * [`normals`](@ref) + +```jldoctest +julia> GeometryBasics.faces(mymesh) +4-element Vector{TriangleFace{Int64}}: + TriangleFace(1, 2, 3) + TriangleFace(1, 2, 4) + TriangleFace(1, 3, 4) + TriangleFace(2, 3, 4) + +julia> GeometryBasics.coordinates(mymesh) +4-element Vector{Point{3, Float32}}: + [0.0, 0.0, 0.0] + [0.0, 0.0, 1.0] + [0.0, 1.0, 0.0] + [1.0, 0.0, 0.0] +``` + +Note that these functions may not apply to all meshes. For example, `mymesh2` +above was not created with `Faces` so `faces` will return `nothing`. + +```jldoctest +julia> GeometryBasics.faces(mymesh2) + +``` \ No newline at end of file From a3c9ae0750cd69bc5abca078285997923c474e94 Mon Sep 17 00:00:00 2001 From: Simon Date: Thu, 17 Oct 2024 19:00:14 +0200 Subject: [PATCH 2/2] Update meshes.md --- docs/src/meshes.md | 36 +++++------------------------------- 1 file changed, 5 insertions(+), 31 deletions(-) diff --git a/docs/src/meshes.md b/docs/src/meshes.md index c5bd97bf..7c2f2b61 100644 --- a/docs/src/meshes.md +++ b/docs/src/meshes.md @@ -69,7 +69,8 @@ To create a mesh one can provide one the following. First, let's create four points and four faces. Each face is an integer connecting the points according to their array index. ```@example -mypoints = [ +using GeometryBasics, GLMakie +points = [ Point3f(0,0,0), Point3f(0,0,1), Point3f(0,1,0), @@ -83,42 +84,15 @@ myfaces = [ TriangleFace(2,3,4) ] -mymesh = Mesh(mypoints, myfaces) -``` - -As seen above, the mesh is just a sequence of triangles. Next, let's create a similar `Mesh` by providing the triangles directly. - -```@example -mytriangles = [ - Triangle(pts[[1,2,3]]...), - Triangle(pts[[1,2,4]]...), - Triangle(pts[[1,3,4]]...), - Triangle(pts[[2,3,4]]...) - ] - -mymesh2 = Mesh(mytriangles) -GeometryBasics.faces(mymesh) +mymesh = Mesh(points, myfaces) +GLMakie.mesh(mymesh) ``` +As seen above, the mesh is just a sequence of points connected by triangle faces. ```@example GeometryBasics.coordinates(mymesh) ``` -Note that these functions may not apply to all meshes. For example, `mymesh2` -above was not created with `Faces` so `faces` will return `nothing`. - -```@example -GeometryBasics.faces(mymesh2) -``` - -With [Makie.jl](https://docs.makie.org) and it's backend GLMakie, one can visualize the mesh: - -```@example -using GLMakie - -GLMakie.mesh(mymesh) -``` - ### Meshing.jl