Skip to content

Commit

Permalink
Added polygone with a hole to Root converter
Browse files Browse the repository at this point in the history
  • Loading branch information
altavir committed Oct 7, 2023
1 parent c7640a6 commit 52d3464
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ private fun SolidGroup.addShape(
}

"TGeoPgon" -> {
//TODO add a inner polygone layer

val fDphi by shape.meta.double(0.0)
val fNz by shape.meta.int(2)
val fPhi1 by shape.meta.double(360.0)
Expand All @@ -201,19 +201,26 @@ private fun SolidGroup.addShape(
val startphi = degToRad(fPhi1)
val deltaphi = degToRad(fDphi)

extruded(name) {
fun Shape2DBuilder.pGon(radius: Double){
(0..<fNedges).forEach {
val phi = deltaphi / fNedges * it + startphi
point(radius * cos(phi), radius * sin(phi))
}
}

surface(name) {
//getting the radius of first
require(fNz > 1) { "The polyhedron geometry requires at least two planes" }
val baseRadius = fRmax[0]
shape {
(0..<fNedges).forEach {
val phi = deltaphi / fNedges * it + startphi
point(baseRadius * cos(phi), baseRadius * sin(phi))
}
}
(0 until fNz).forEach { index ->
//scaling all radii relative to first layer radius
layer(fZ[index], scale = fRmax[index] / baseRadius)
for (index in 0 until fNz){
layer(
fZ[index],
innerBuilder = {
pGon(fRmin[index])
},
outerBuilder = {
pGon(fRmax[index])
}
)
}
}.apply(block)
}
Expand Down
1 change: 1 addition & 0 deletions demo/playground/src/jvmMain/kotlin/extruded.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ fun main() = makeVisionFile {
polygon(8, 100)
}
layer(-30)
layer(0, x = 10, y = 10)
layer(30)
}
}
Expand Down
6 changes: 3 additions & 3 deletions demo/playground/src/jvmMain/kotlin/surface.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ fun main() = makeVisionFile {
solid {
ambientLight()
surface("surface") {
layer(0, {polygon(8,10)}, {polygon(8,20)})
layer(10, {polygon(8,10)}, {polygon(8,30)})

layer(0, { polygon(8, 10) }, { polygon(8, 20) })
layer(10, { polygon(8, 20) }, { polygon(8, 30) })
layer(20, { polygon(8, 10) }, { polygon(8, 20) })
}
}
}
Expand Down

0 comments on commit 52d3464

Please sign in to comment.