Skip to content

Commit 6a9e94d

Browse files
committed
Define function coordinates(::ConicalFrustum, ...)
1 parent 8a32b7c commit 6a9e94d

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

src/primitives/ConicalFrustum.jl

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,3 +182,56 @@ end # function
182182
Computes the centroid of a frustum: the mean between the base and top centers.
183183
"""
184184
centroid(x::ConicalFrustum) = (baseCenter(x) + topCenter(x)) / 2
185+
186+
"""
187+
Computes the coordinates required for the discretization
188+
of a frustum. The logic is the same as that for a cylinder,
189+
where the top and bottom circles are approximated using
190+
a polygon.
191+
"""
192+
function coordinates(c::ConicalFrustum{T}, nvertices=30) where {T}
193+
194+
nvertices += isodd(nvertices)
195+
196+
nhalf = div(nvertices, 2)
197+
198+
R = rotation(c)
199+
200+
step = 2pi / nhalf
201+
202+
ps = Vector{Point3{T}}(undef, nvertices + 2)
203+
204+
baseRadiusVal = baseRadius(c)
205+
206+
baseCenterVal = baseCenter(c)
207+
208+
topRadiusVal = topRadius(c)
209+
210+
topCenterVal = topCenter(c)
211+
212+
# First discretize the base...
213+
214+
for i in 1:nhalf
215+
216+
phi = (i-1) * step
217+
218+
ps[i] = R * Point3{T}(baseRadius * cos(phi), baseRadius * sin(phi), 0) + baseCenterVal
219+
220+
end
221+
222+
# ... and then the top circle.
223+
224+
for i in 1:nhalf
225+
226+
phi = (i-1) * step
227+
228+
ps[i + nhalf] = R * Point3{T}(topRadiusVal * cos(phi), topRadiusVal * sin(phi), 0) + topCenterVal
229+
end
230+
231+
ps[end-1] = baseCenterVal
232+
233+
ps[end] = topCenterVal
234+
235+
return ps
236+
237+
end # function

0 commit comments

Comments
 (0)