GeometryBasics.jl
Basic geometry types.
This package aims to offer a standard set of geometry types that easily work with metadata, query frameworks on geometries and different memory layouts. The aim is to create a solid basis for graphics/plotting, finite element analysis, geo applications, and general geometry manipulations - while offering a Julian API that still allows performant C-interop.
This package is a replacement for the discontinued GeometryTypes.
Quick start
Create some points:
julia> using GeometryBasics
julia> p1 = Point(3, 1)
2-element Point{2, Int64} with indices SOneTo(2): 3 1
julia> p2 = Point(1, 3);
julia> p3 = Point(4, 4);
Connect pairs of points as line segments:
julia> l1 = Line(p1, p2)
Line([3, 1] => [1, 3])
julia> l2 = Line(p2, p3);
Or connect multiple points as a linestring:
julia> LineString([p1, p2, p3])
LineString{2, Int64}(Point{2, Int64}[[3, 1], [1, 3], [4, 4]])
You can also create polygons from points:
julia> Polygon(Point{2, Int}[(3, 1), (4, 4), (2, 4), (1, 2), (3, 1)])
Polygon{2, Int64}(Point{2, Int64}[[3, 1], [4, 4], [2, 4], [1, 2], [3, 1]], Vector{Point{2, Int64}}[])
Create a rectangle placed at the origin with unit width and height:
julia> rect = Rect(Vec(0.0, 0.0), Vec(1.0, 1.0))
HyperRectangle{2, Float64}([0.0, 0.0], [1.0, 1.0])
Decompose the rectangle into two triangular faces:
julia> rect_faces = decompose(TriangleFace{Int}, rect)
2-element Vector{TriangleFace{Int64}}: TriangleFace{Int64}(1, 2, 3) TriangleFace{Int64}(1, 3, 4)
Decompose the rectangle into four positions:
julia> rect_positions = decompose(Point{2, Float64}, rect)
4-element Vector{Point{2, Float64}}: [0.0, 0.0] [1.0, 0.0] [1.0, 1.0] [0.0, 1.0]
Combine the vertices and faces into a triangle mesh:
julia> mesh = Mesh(rect_positions, rect_faces)
Mesh{2, Float64, TriangleFace{Int64}} faces: 2 vertex position: 4
Use GeometryBasics.mesh
to get a mesh directly from a geometry:
julia> mesh = GeometryBasics.mesh(rect)
Mesh{2, Float64, NgonFace{3, OffsetInteger{-1, UInt32}}} faces: 2 vertex position: 4