diff --git a/src/ConstructiveSolidGeometry/SurfacePrimitives/ConeMantle.jl b/src/ConstructiveSolidGeometry/SurfacePrimitives/ConeMantle.jl index 5a44c41f1..7bc974684 100644 --- a/src/ConstructiveSolidGeometry/SurfacePrimitives/ConeMantle.jl +++ b/src/ConstructiveSolidGeometry/SurfacePrimitives/ConeMantle.jl @@ -7,7 +7,7 @@ Surface primitive describing the mantle of a [`Cone`](@ref). * `T`: Precision type. * `TR`: Type of the radius `r`. * `TR == T`: CylinderMantle (constant radius `r` at all `z`). - * `TR == Tuple{T, T}`: VaryingCylinderMantle (inner radius at `r[1]`, outer radius at `r[2]`). + * `TR == Tuple{T, T}`: VaryingCylinderMantle (bottom radius at `r[1]`, top radius at `r[2]`). * `TP`: Type of the angular range `φ`. * `TP == Nothing`: Full 2π Cone. * `TP == Tuple{T, T}`: Partial Cone ranging from `φ[1]` to `φ[2]`. @@ -34,6 +34,9 @@ radius_at_z(hZ::T, rBot::T, rTop::T, z::T) where {T} = iszero(hZ) ? rBot : rBot radius_at_z(cm::ConeMantle{T,T}, z::T) where {T} = cm.r radius_at_z(cm::ConeMantle{T,Tuple{T,T}}, z::T) where {T} = radius_at_z(cm.hZ, cm.r[1], cm.r[2], z) +get_φ_limits(cm::ConeMantle{T,<:Any,Tuple{T,T}}) where {T} = cm.φ[1], cm.φ[2] +get_φ_limits(cm::ConeMantle{T,<:Any,Nothing}) where {T} = T(0), T(2π) + function normal(cm::ConeMantle{T,T}, pt::CartesianPoint{T}) where {T} pto = _transform_into_object_coordinate_system(pt, cm) cyl = CylindricalPoint(pto) @@ -57,6 +60,22 @@ function normal(cm::ConeMantle{T,Tuple{T,T},<:Any,:outwards}, pt::CartesianPoint CartesianPoint(CylindricalPoint{T}( one(T), cyl.φ, -Δr / Δz)), cm)) end +function vertices(cm::ConeMantle{T}, n_arc::Int64)::Vector{CartesianPoint{T}} where {T} + φMin, φMax = get_φ_limits(cm) + n_arc = _get_n_points_in_arc_φ(cm, n_arc) + φ = range(φMin, φMax, length = n_arc+1) + rbot = radius_at_z(cm,-cm.hZ) + rtop = radius_at_z(cm,cm.hZ) + botcircle = [_transform_into_global_coordinate_system(CartesianPoint{T}(rbot*cos(φ), rbot*sin(φ), -cm.hZ), cm) for φ in φ] + topcircle = [_transform_into_global_coordinate_system(CartesianPoint{T}(rtop*cos(φ), rtop*sin(φ), cm.hZ), cm) for φ in φ] + append!(botcircle, topcircle) +end + +function connections(cm::ConeMantle, n_arc::Int64)::Vector{Vector{Int64}} + n_arc = _get_n_points_in_arc_φ(cm, n_arc) + [[i,i+1,i+n_arc+2,i+n_arc+1] for i in 1:n_arc] +end + const FullConeMantle{T,D} = ConeMantle{T,Tuple{T,T},Nothing,D} # ugly name but works for now, should just be `ConeMantle`... const PartialConeMantle{T,D} = ConeMantle{T,Tuple{T,T},Tuple{T,T},D} diff --git a/src/ConstructiveSolidGeometry/SurfacePrimitives/EllipsoidMantle.jl b/src/ConstructiveSolidGeometry/SurfacePrimitives/EllipsoidMantle.jl index 39ada4a4e..9385b0e42 100644 --- a/src/ConstructiveSolidGeometry/SurfacePrimitives/EllipsoidMantle.jl +++ b/src/ConstructiveSolidGeometry/SurfacePrimitives/EllipsoidMantle.jl @@ -35,6 +35,15 @@ flip(em::EllipsoidMantle{T,TR,TP,TT,:inwards}) where {T,TR,TP,TT} = const FullSphereMantle{T,D} = EllipsoidMantle{T,T,Nothing,Nothing,D} const FullEllipsoidMantle{T,D} = EllipsoidMantle{T,NTuple{3,T},Nothing,Nothing,D} +get_φ_limits(em::EllipsoidMantle{T,<:Any,Tuple{T,T}}) where {T} = em.φ[1], em.φ[2] +get_φ_limits(em::EllipsoidMantle{T,<:Any,Nothing}) where {T} = T(0), T(2π) + +get_θ_limits(em::EllipsoidMantle{T,<:Any,<:Any,Tuple{T,T}}) where {T} = em.θ[1], em.θ[2] +get_θ_limits(em::EllipsoidMantle{T,<:Any,<:Any,Nothing}) where {T} = T(-π/2), T(π/2) + +get_radii(em::EllipsoidMantle{T,T}) where {T} = (em.r, em.r, em.r) +get_radii(em::EllipsoidMantle{T,NTuple{3,T}}) where {T} = em.r + function lines(em::FullSphereMantle{T}) where {T} ellipse_xy = Ellipse{T,T,Nothing}(r = em.r[1], φ = em.φ, origin = em.origin, rotation = em.rotation) ellipse_xz = Ellipse{T,T,Nothing}(r = em.r[1], φ = em.φ, origin = em.origin, rotation = em.rotation * RotX(T(π)/2)) @@ -67,6 +76,25 @@ function normal(em::EllipsoidMantle{T,T,TP,TT,:outwards}, pt::CartesianPoint{T}) end normal(em::EllipsoidMantle{T,TR,TP,TT,:inwards}, pt::CartesianPoint{T}) where {T,TR,TP,TT} = -normal(flip(em), pt) +function vertices(em::EllipsoidMantle{T}, n_arc::Int64)::Vector{CartesianPoint{T}} where {T} + rx, ry, rz = get_radii(em) + φMin, φMax = get_φ_limits(em) + θMin, θMax = get_θ_limits(em) + n_arcφ = _get_n_points_in_arc_φ(em, n_arc) + n_arcθ = _get_n_points_in_arc_θ(em, n_arc) + + θ = range(θMin, θMax, length = n_arcθ + 1) + φ = range(φMin, φMax, length = n_arcφ + 1) + + [_transform_into_global_coordinate_system(CartesianPoint{T}(rx*cos(θ)*cos(φ), ry*cos(θ)*sin(φ), rz*sin(θ)), em) for θ in θ for φ in φ] +end + +function connections(em::EllipsoidMantle, n_arc::Int64)::Vector{Vector{Int64}} + n_arcφ = _get_n_points_in_arc_φ(em, n_arc) + n_arcθ = _get_n_points_in_arc_θ(em, n_arc) + [[i+(n_arcφ+1)*j,i+1+(n_arcφ+1)*j,i+1+(n_arcφ+1)*(j+1),i+(n_arcφ+1)*(j+1)] for j in 0:n_arcθ-1 for i in 1:n_arcφ] +end + """ intersection(em::EllipsoidMantle{T}, l::Line{T}) where {T} diff --git a/src/ConstructiveSolidGeometry/SurfacePrimitives/EllipticalSurface.jl b/src/ConstructiveSolidGeometry/SurfacePrimitives/EllipticalSurface.jl index 421b1c15a..805f5d550 100644 --- a/src/ConstructiveSolidGeometry/SurfacePrimitives/EllipticalSurface.jl +++ b/src/ConstructiveSolidGeometry/SurfacePrimitives/EllipticalSurface.jl @@ -36,9 +36,37 @@ Plane(es::EllipticalSurface{T}) where {T} = Plane{T}(es.origin, es.rotation * Ca normal(es::EllipticalSurface{T}, ::CartesianPoint{T} = zero(CartesianPoint{T})) where {T} = es.rotation * CartesianVector{T}(zero(T), zero(T), one(T)) +function vertices(es::EllipticalSurface{T, T}, n_arc::Int64)::Vector{CartesianPoint{T}} where {T} + φMin, φMax = get_φ_limits(es) + n_arc = _get_n_points_in_arc_φ(es, n_arc) + φ = range(φMin, φMax, length = n_arc+1) + append!([es.origin],[_transform_into_global_coordinate_system(CartesianPoint{T}(es.r*cos(φ), es.r*sin(φ), 0), es) for φ in φ]) +end + +function vertices(es::EllipticalSurface{T, Tuple{T,T}}, n_arc::Int64)::Vector{CartesianPoint{T}} where {T} + rMin, rMax = es.r + φMin, φMax = get_φ_limits(es) + n_arc = _get_n_points_in_arc_φ(es, n_arc) + φ = range(φMin, φMax, length = n_arc+1) + [_transform_into_global_coordinate_system(CartesianPoint{T}(r*cos(φ), r*sin(φ), 0), es) for r in (rMin,rMax) for φ in φ] +end + +function connections(es::EllipticalSurface{T, T}, n_arc::Int64)::Vector{Vector{Int64}} where {T} + n_arc = _get_n_points_in_arc_φ(es, n_arc) + [[1,i,i+1] for i in 2:n_arc+1] +end + +function connections(es::EllipticalSurface{T, Tuple{T,T}}, n_arc::Int64)::Vector{Vector{Int64}} where {T} + n_arc = _get_n_points_in_arc_φ(es, n_arc) + [[i,i+1,i+n_arc+2,i+n_arc+1] for i in 1:n_arc] +end + extremum(es::EllipticalSurface{T,T}) where {T} = es.r extremum(es::EllipticalSurface{T,Tuple{T,T}}) where {T} = es.r[2] # r_out always larger r_in: es.r[2] > es.r[2] +get_φ_limits(es::EllipticalSurface{T,<:Any,Tuple{T,T}}) where {T} = es.φ[1], es.φ[2] +get_φ_limits(cm::EllipticalSurface{T,<:Any,Nothing}) where {T} = T(0), T(2π) + function lines(sp::CircularArea{T}; n = 2) where {T} circ = Circle{T}(r = sp.r, φ = sp.φ, origin = sp.origin, rotation = sp.rotation) φs = range(T(0), step = T(2π) / n, length = n) diff --git a/src/ConstructiveSolidGeometry/SurfacePrimitives/Plane.jl b/src/ConstructiveSolidGeometry/SurfacePrimitives/Plane.jl index aebdde921..8e0af87b3 100644 --- a/src/ConstructiveSolidGeometry/SurfacePrimitives/Plane.jl +++ b/src/ConstructiveSolidGeometry/SurfacePrimitives/Plane.jl @@ -19,7 +19,6 @@ origin(p::Plane) = p.origin isinfront(pt::AbstractCoordinatePoint, p::Plane) = (pt - origin(p)) ⋅ normal(p) > 0 isbehind(pt::AbstractCoordinatePoint, p::Plane) = (pt - origin(p)) ⋅ normal(p) < 0 -in(pt::AbstractCoordinatePoint, p::Plane) = (pt - origin(p)) ⋅ normal(p) == 0 _distance(pt::AbstractCoordinatePoint, p::Plane) = (pt - origin(p)) ⋅ normal(p) distance(pt::AbstractCoordinatePoint, p::Plane) = abs(_distance(pt, p)) diff --git a/src/ConstructiveSolidGeometry/SurfacePrimitives/Polygon.jl b/src/ConstructiveSolidGeometry/SurfacePrimitives/Polygon.jl index b72d3abc7..8aa5db0b8 100644 --- a/src/ConstructiveSolidGeometry/SurfacePrimitives/Polygon.jl +++ b/src/ConstructiveSolidGeometry/SurfacePrimitives/Polygon.jl @@ -19,6 +19,9 @@ const Quadrangle{T} = Polygon{4, T} normal(p::Polygon) = normalize((p.points[2] - p.points[1]) × (p.points[3] - p.points[1])) vertices(p::Polygon) = p.points +vertices(p::Polygon, n::Int64) = vertices(p) +connections(p::Polygon{N}) where {N} = [collect(1:N)] +connections(p::Polygon, n::Int64) = connections(p) extreme_points(p::Polygon) = p.points @@ -63,18 +66,13 @@ function _rotate_on_xy_plane(p::Polygon{<:Any, T}) where {T} map(pt -> rot * pt, p.points) end - -function in(pt::CartesianPoint{T}, p::Quadrangle{T}) where {T} - b::Bool = in(pt, Plane(p)) - if b +function in(pt::CartesianPoint{T}, p::Polygon{N,T}) where {N,T} + plane = Plane(p) + if (pt - origin(plane)) ⋅ normal(plane) == 0 rot = _get_rot_for_rotation_on_xy_plane(p) vs = vertices(p) - pts2d = SVector{5, SVector{2, T}}( - view(rot * vs[1], 1:2), - view(rot * vs[2], 1:2), - view(rot * vs[3], 1:2), - view(rot * vs[4], 1:2), - view(rot * vs[1], 1:2), + pts2d = SVector{N+1, SVector{2, T}}( + view(rot * vs[i%N + 1], 1:2) for i in 0:N ) # PolygonOps.inpolygon -> in = 1, on = -1, out = 0) b = PolygonOps.inpolygon(view(rot * pt, 1:2), pts2d) != 0 diff --git a/src/ConstructiveSolidGeometry/SurfacePrimitives/SurfacePrimitives.jl b/src/ConstructiveSolidGeometry/SurfacePrimitives/SurfacePrimitives.jl index c0a9e5937..eceed1fa5 100644 --- a/src/ConstructiveSolidGeometry/SurfacePrimitives/SurfacePrimitives.jl +++ b/src/ConstructiveSolidGeometry/SurfacePrimitives/SurfacePrimitives.jl @@ -11,3 +11,15 @@ include("TorusMantle.jl") # Normal vectors of planar surface primitives do not depend on the point, # but the normal method is generally called with a point. normal(p::AbstractPlanarSurfacePrimitive, ::AbstractCoordinatePoint) = normal(p) + +function _get_n_points_in_arc_φ(p::AbstractSurfacePrimitive, n_arc::Int64)::Int64 + φMin, φMax = get_φ_limits(p) + f = (φMax - φMin)/(2π) + Int(ceil(n_arc*f)) +end + +function _get_n_points_in_arc_θ(p::AbstractSurfacePrimitive, n_arc::Int64)::Int64 + θMin, θMax = get_θ_limits(p) + f = (θMax - θMin)/(2π) + Int(ceil(n_arc*f)) +end diff --git a/src/ConstructiveSolidGeometry/SurfacePrimitives/TorusMantle.jl b/src/ConstructiveSolidGeometry/SurfacePrimitives/TorusMantle.jl index 13e1c4e4f..c8e802624 100644 --- a/src/ConstructiveSolidGeometry/SurfacePrimitives/TorusMantle.jl +++ b/src/ConstructiveSolidGeometry/SurfacePrimitives/TorusMantle.jl @@ -32,6 +32,12 @@ end flip(t::TorusMantle{T,TP,TT,:inwards}) where {T,TP,TT} = TorusMantle{T,TP,TT,:outwards}(t.r_torus, t.r_tube, t.φ, t.θ, t.origin, t.rotation ) +get_φ_limits(tm::TorusMantle{T,Tuple{T,T}}) where {T} = tm.φ[1], tm.φ[2] +get_φ_limits(tm::TorusMantle{T,Nothing}) where {T} = T(0), T(2π) + +get_θ_limits(tm::TorusMantle{T,<:Any,Tuple{T,T}}) where {T} = tm.θ[1], tm.θ[2] +get_θ_limits(tm::TorusMantle{T,<:Any,Nothing}) where {T} = T(0), T(2π) + function normal(tm::TorusMantle{T,TP,TT,:outwards}, pt::CartesianPoint{T}) where {T,TP,TT} pto = _transform_into_object_coordinate_system(pt, tm) cyl = CylindricalPoint(pto) @@ -40,6 +46,24 @@ function normal(tm::TorusMantle{T,TP,TT,:outwards}, pt::CartesianPoint{T}) where end normal(tm::TorusMantle{T,TP,TT,:inwards}, pt::CartesianPoint{T}) where {T,TP,TT} = -normal(flip(tm), pt) +function vertices(tm::TorusMantle{T}, n_arc::Int64)::Vector{CartesianPoint{T}} where {T} + φMin, φMax = get_φ_limits(tm) + θMin, θMax = get_θ_limits(tm) + n_arcφ = _get_n_points_in_arc_φ(tm, n_arc) + n_arcθ = _get_n_points_in_arc_θ(tm, n_arc) + + θ = range(θMin, θMax, length = n_arcθ + 1) + φ = range(φMin, φMax, length = n_arcφ + 1) + + [_transform_into_global_coordinate_system(CartesianPoint{T}((tm.r_torus + tm.r_tube*cos(θ))*cos(φ), (tm.r_torus + tm.r_tube*cos(θ))*sin(φ), tm.r_tube*sin(θ)), tm) for θ in θ for φ in φ] +end + +function connections(tm::TorusMantle, n_arc::Int64)::Vector{Vector{Int64}} + n_arcφ = _get_n_points_in_arc_φ(tm, n_arc) + n_arcθ = _get_n_points_in_arc_θ(tm, n_arc) + [[i+(n_arcφ+1)*j,i+1+(n_arcφ+1)*j,i+1+(n_arcφ+1)*(j+1),i+(n_arcφ+1)*(j+1)] for j in 0:n_arcθ-1 for i in 1:n_arcφ] +end + const FullTorusMantle{T,D} = TorusMantle{T,Nothing,Nothing,D} function lines(tm::FullTorusMantle{T}) where {T} diff --git a/src/ConstructiveSolidGeometry/plotting/CSG/CSG.jl b/src/ConstructiveSolidGeometry/plotting/CSG/CSG.jl index e94a25e4c..afc9432ba 100644 --- a/src/ConstructiveSolidGeometry/plotting/CSG/CSG.jl +++ b/src/ConstructiveSolidGeometry/plotting/CSG/CSG.jl @@ -10,12 +10,20 @@ end ps = primitives(csg) @series begin label --> "CSG" + if !isClosedPrimitive(ps[1]) + fillcolor := :white + fillalpha --> 0.2 + end linestyle := isClosedPrimitive(ps[1]) ? :solid : :dot ps[1] end for i in 2:length(ps) @series begin label := nothing + if !isClosedPrimitive(ps[i]) + fillcolor := :white + fillalpha --> 0.2 + end linestyle := isClosedPrimitive(ps[i]) ? :solid : :dot ps[i] end diff --git a/src/ConstructiveSolidGeometry/plotting/Meshing.jl b/src/ConstructiveSolidGeometry/plotting/Meshing.jl index 9ae7ba97e..ca48d08a3 100644 --- a/src/ConstructiveSolidGeometry/plotting/Meshing.jl +++ b/src/ConstructiveSolidGeometry/plotting/Meshing.jl @@ -1,53 +1,34 @@ """ - struct Mesh{T, N} + struct Mesh{T} * `x`: X-coordinate mesh in meters * `y`: Y-coordinate mesh in meters * `z`: Z-coordinate mesh in meters +* `connections`: defines which points are connected to eah other -(X[i,j], Y[i,j], Z[i,j]) is a cartesian point """ -struct Mesh{T, N} - x::Array{T,N} - y::Array{T,N} - z::Array{T,N} - function Mesh( - x::Array{T,N}, - y::Array{T,N}, - z::Array{T,N}) where {T,N} - @assert size(x) == size(y) && size(x) == size(z) - new{T,N}(x, y, z) - end +struct Mesh{T} + x::Vector{T} + y::Vector{T} + z::Vector{T} + connections::Vector{Vector{Int64}} end -function get_cartesian_point_from_mesh(m::Mesh{T}, index::Tuple{I,I}) where {T, I<:Int} - i, j = index - CartesianPoint{T}(m.x[i,j], m.y[i,j], m.z[i,j]) +function mesh(p::AbstractSurfacePrimitive{T}; n_arc = 40)::Mesh{T} where {T} + vs = vertices(p, n_arc) + x, y, z = broadcast(i -> getindex.(vs, i), (1,2,3)) + c = connections(p, n_arc) + Mesh{T}(x,y,z,c) end -size(m::Mesh{T}) where {T} = size(m.x) - -function get_plot_meshes(v::AbstractVolumePrimitive{T}; n = 30) where {T <: AbstractFloat} - surfaces = get_decomposed_surfaces(v) - meshes = Mesh{T}[] - for surf in surfaces - push!(meshes, mesh(surf; n = n)) - end - meshes -end - -function get_plot_meshes(s::AbstractSurfacePrimitive{T}; n = 30) where {T <: AbstractFloat} - meshes = Mesh{T}[] - push!(meshes, mesh(s; n = n)) - meshes -end @recipe function f(m::Mesh{T}) where {T} - seriestype := :surface + seriestype := :mesh3d linewidth --> 0.1 linecolor --> :white - seriescolor --> :blue - colorbar := false + seriescolor --> 1 + seriesalpha --> 0.5 + connections := m.connections m.x, m.y, m.z -end +end \ No newline at end of file diff --git a/src/ConstructiveSolidGeometry/plotting/SurfacePrimitives/ConeMantle.jl b/src/ConstructiveSolidGeometry/plotting/SurfacePrimitives/ConeMantle.jl index f212f91e1..7d871da13 100644 --- a/src/ConstructiveSolidGeometry/plotting/SurfacePrimitives/ConeMantle.jl +++ b/src/ConstructiveSolidGeometry/plotting/SurfacePrimitives/ConeMantle.jl @@ -1,17 +1,25 @@ -@recipe function f(cm::ConeMantle, n = 40; subn = 10) - ls = lines(cm) - linecolor --> :black - @series begin - label --> "Cone Mantle" - ls[1] - end - for i in 2:length(ls) +@recipe function f(cm::ConeMantle; n_arc = 40, subn = 10) + seriestype --> :mesh3d + if haskey(plotattributes, :seriestype) && plotattributes[:seriestype] == :mesh3d @series begin - label := nothing - ls[i] + label --> "Cone Mantle" + mesh(cm, n_arc = n_arc) + end + else + ls = lines(cm) + linecolor --> :black + @series begin + label --> "Cone Mantle" + ls[1] + end + for i in 2:length(ls) + @series begin + label := nothing + ls[i] + end end end - if !haskey(plotattributes, :show_normal) || plotattributes[:show_normal] + if haskey(plotattributes, :show_normal) && plotattributes[:show_normal] @series begin label := nothing seriestype := :vector diff --git a/src/ConstructiveSolidGeometry/plotting/SurfacePrimitives/EllipsoidMantle.jl b/src/ConstructiveSolidGeometry/plotting/SurfacePrimitives/EllipsoidMantle.jl index 9da841c8f..14ba3a6e9 100644 --- a/src/ConstructiveSolidGeometry/plotting/SurfacePrimitives/EllipsoidMantle.jl +++ b/src/ConstructiveSolidGeometry/plotting/SurfacePrimitives/EllipsoidMantle.jl @@ -1,17 +1,25 @@ -@recipe function f(em::EllipsoidMantle, n = 40; subn = 10) - ls = lines(em) - linecolor --> :black - @series begin - label --> "Ellipsoid Mantle" - ls[1] - end - for i in 2:length(ls) +@recipe function f(em::EllipsoidMantle; n_arc = 40, subn = 10) + seriestype --> :mesh3d + if haskey(plotattributes, :seriestype) && plotattributes[:seriestype] == :mesh3d @series begin - label := nothing - ls[i] + label --> "Ellipsoid Mantle" + mesh(em, n_arc = n_arc) + end + else + ls = lines(em) + linecolor --> :black + @series begin + label --> "Ellipsoid Mantle" + ls[1] + end + for i in 2:length(ls) + @series begin + label := nothing + ls[i] + end end end - if (!haskey(plotattributes, :show_normal) || plotattributes[:show_normal]) && + if (haskey(plotattributes, :show_normal) && plotattributes[:show_normal]) && em.φ === nothing && em.θ === nothing @series begin label := nothing diff --git a/src/ConstructiveSolidGeometry/plotting/SurfacePrimitives/EllipticalSurface.jl b/src/ConstructiveSolidGeometry/plotting/SurfacePrimitives/EllipticalSurface.jl index 3ad40c722..9486472cb 100644 --- a/src/ConstructiveSolidGeometry/plotting/SurfacePrimitives/EllipticalSurface.jl +++ b/src/ConstructiveSolidGeometry/plotting/SurfacePrimitives/EllipticalSurface.jl @@ -1,27 +1,33 @@ -@recipe function f(es::EllipticalSurface; n = 40) - ls = lines(es) - linecolor --> :black - @series begin - label --> "Elliptical Surface" - n := n - ls[1] +@recipe function f(es::EllipticalSurface; n_arc = 40) + seriestype --> :mesh3d + if haskey(plotattributes, :seriestype) && plotattributes[:seriestype] == :mesh3d + @series begin + label --> "Elliptical Surface" + mesh(es, n_arc = n_arc) + end + else + ls = lines(es) + linecolor --> :black + @series begin + label --> "Elliptical Surface" + ls[1] + end + if length(ls) > 1 + for i in 2:length(ls) + @series begin + label := nothing + ls[i] + end + end + end end - if !haskey(plotattributes, :show_normal) || plotattributes[:show_normal] + if haskey(plotattributes, :show_normal) && plotattributes[:show_normal] @series begin label := nothing seriestype := :vector _plt_get_start_point_for_normal(es), normalize(Plane(es).normal) * sqrt(_plt_area(es)) / 20 end end - if length(ls) > 1 - for i in 2:length(ls) - @series begin - label := nothing - n := n - ls[i] - end - end - end end _plt_area(es::CircularArea{T}) where {T} = π*es.r^2 diff --git a/src/ConstructiveSolidGeometry/plotting/SurfacePrimitives/Polygon.jl b/src/ConstructiveSolidGeometry/plotting/SurfacePrimitives/Polygon.jl index 54d7494ad..b3a45ad7d 100644 --- a/src/ConstructiveSolidGeometry/plotting/SurfacePrimitives/Polygon.jl +++ b/src/ConstructiveSolidGeometry/plotting/SurfacePrimitives/Polygon.jl @@ -1,21 +1,25 @@ @recipe function f(p::Polygon) - linecolor --> :black - @series begin - label --> "Polygon" - x = map(p -> p[1], [p.points..., p.points[1]]) - y = map(p -> p[2], [p.points..., p.points[1]]) - z = map(p -> p[3], [p.points..., p.points[1]]) - x, y, z + seriestype --> :mesh3d + if haskey(plotattributes, :seriestype) && plotattributes[:seriestype] == :mesh3d + @series begin + label --> "Polygon" + mesh(p) + end + else + linecolor --> :black + @series begin + label --> "Polygon" + x = map(p -> p[1], [p.points..., p.points[1]]) + y = map(p -> p[2], [p.points..., p.points[1]]) + z = map(p -> p[3], [p.points..., p.points[1]]) + x, y, z + end end - if !haskey(plotattributes, :show_normal) || plotattributes[:show_normal] + if haskey(plotattributes, :show_normal) && plotattributes[:show_normal] @series begin label := nothing seriestype := :vector mean(p.points), Plane(p).normal / 5 end end -end - - - -! \ No newline at end of file +end \ No newline at end of file diff --git a/src/ConstructiveSolidGeometry/plotting/SurfacePrimitives/TorusMantle.jl b/src/ConstructiveSolidGeometry/plotting/SurfacePrimitives/TorusMantle.jl index c1ae21367..f0c0cce2f 100644 --- a/src/ConstructiveSolidGeometry/plotting/SurfacePrimitives/TorusMantle.jl +++ b/src/ConstructiveSolidGeometry/plotting/SurfacePrimitives/TorusMantle.jl @@ -1,17 +1,25 @@ -@recipe function f(tm::TorusMantle, n = 40; subn = 10) - ls = lines(tm) - linecolor --> :black - @series begin - label --> "Ellipsoid Mantle" - ls[1] - end - for i in 2:length(ls) +@recipe function f(tm::TorusMantle; n_arc = 40, subn = 10) + seriestype --> :mesh3d + if haskey(plotattributes, :seriestype) && plotattributes[:seriestype] == :mesh3d @series begin - label := nothing - ls[i] + label --> "Torus Mantle" + mesh(tm, n_arc = n_arc) + end + else + ls = lines(tm) + linecolor --> :black + @series begin + label --> "Ellipsoid Mantle" + ls[1] + end + for i in 2:length(ls) + @series begin + label := nothing + ls[i] + end end end - if (!haskey(plotattributes, :show_normal) || plotattributes[:show_normal]) && + if (haskey(plotattributes, :show_normal) && plotattributes[:show_normal]) && tm.φ === nothing && tm.θ === nothing @series begin label := nothing @@ -23,22 +31,22 @@ end end -function _plt_points_for_normals(em::TorusMantle{T}) where {T} - pts = [ CartesianPoint{T}( em.r_torus+em.r_tube, zero(T), zero(T)), - CartesianPoint{T}( em.r_torus-em.r_tube, zero(T), zero(T)), - CartesianPoint{T}( em.r_torus, zero(T), em.r_tube ), - CartesianPoint{T}( em.r_torus, zero(T),-em.r_tube ), - CartesianPoint{T}(-em.r_torus+em.r_tube, zero(T), zero(T)), - CartesianPoint{T}(-em.r_torus-em.r_tube, zero(T), zero(T)), - CartesianPoint{T}(-em.r_torus, zero(T), em.r_tube ), - CartesianPoint{T}(-em.r_torus, zero(T),-em.r_tube ), - CartesianPoint{T}( zero(T), em.r_torus+em.r_tube, zero(T)), - CartesianPoint{T}( zero(T), em.r_torus-em.r_tube, zero(T)), - CartesianPoint{T}( zero(T), em.r_torus, em.r_tube ), - CartesianPoint{T}( zero(T), em.r_torus,-em.r_tube ), - CartesianPoint{T}( zero(T),-em.r_torus+em.r_tube, zero(T)), - CartesianPoint{T}( zero(T),-em.r_torus-em.r_tube, zero(T)), - CartesianPoint{T}( zero(T),-em.r_torus, em.r_tube ), - CartesianPoint{T}( zero(T),-em.r_torus,-em.r_tube ) ] - _transform_into_global_coordinate_system(pts, em) +function _plt_points_for_normals(tm::TorusMantle{T}) where {T} + pts = [ CartesianPoint{T}( tm.r_torus+tm.r_tube, zero(T), zero(T)), + CartesianPoint{T}( tm.r_torus-tm.r_tube, zero(T), zero(T)), + CartesianPoint{T}( tm.r_torus, zero(T), tm.r_tube ), + CartesianPoint{T}( tm.r_torus, zero(T),-tm.r_tube ), + CartesianPoint{T}(-tm.r_torus+tm.r_tube, zero(T), zero(T)), + CartesianPoint{T}(-tm.r_torus-tm.r_tube, zero(T), zero(T)), + CartesianPoint{T}(-tm.r_torus, zero(T), tm.r_tube ), + CartesianPoint{T}(-tm.r_torus, zero(T),-tm.r_tube ), + CartesianPoint{T}( zero(T), tm.r_torus+tm.r_tube, zero(T)), + CartesianPoint{T}( zero(T), tm.r_torus-tm.r_tube, zero(T)), + CartesianPoint{T}( zero(T), tm.r_torus, tm.r_tube ), + CartesianPoint{T}( zero(T), tm.r_torus,-tm.r_tube ), + CartesianPoint{T}( zero(T),-tm.r_torus+tm.r_tube, zero(T)), + CartesianPoint{T}( zero(T),-tm.r_torus-tm.r_tube, zero(T)), + CartesianPoint{T}( zero(T),-tm.r_torus, tm.r_tube ), + CartesianPoint{T}( zero(T),-tm.r_torus,-tm.r_tube ) ] + _transform_into_global_coordinate_system(pts, tm) end diff --git a/src/ConstructiveSolidGeometry/plotting/plotting.jl b/src/ConstructiveSolidGeometry/plotting/plotting.jl index 949a39fef..d21139823 100644 --- a/src/ConstructiveSolidGeometry/plotting/plotting.jl +++ b/src/ConstructiveSolidGeometry/plotting/plotting.jl @@ -3,7 +3,7 @@ include("LinePrimitives/LinePrimitives.jl") include("SurfacePrimitives/SurfacePrimitives.jl") include("VolumePrimitives/VolumePrimitives.jl") -# include("Meshing.jl") +include("Meshing.jl") # include("Wireframe.jl") diff --git a/src/PlotRecipes/SolidStateDetector.jl b/src/PlotRecipes/SolidStateDetector.jl index 3b5224bc7..e0bfc4f10 100644 --- a/src/PlotRecipes/SolidStateDetector.jl +++ b/src/PlotRecipes/SolidStateDetector.jl @@ -12,6 +12,8 @@ end @recipe function f(contact::Contact) linecolor --> contact.id + fillcolor --> contact.id + fillalpha --> 0.2 l = contact.name != "" ? "$(contact.name) (id: $(contact.id))" : "Contact - id: $(contact.id)" label --> l contact.geometry