Some doc and Sphere geometry #11 #18
@ -4,8 +4,8 @@
|
|||||||
|
|
||||||
This repository contains [DataForge](http://npm.mipt.ru/dataforge/)
|
This repository contains [DataForge](http://npm.mipt.ru/dataforge/)
|
||||||
(also [here](https://github.com/mipt-npm/dataforge-core)) components useful for visualization in
|
(also [here](https://github.com/mipt-npm/dataforge-core)) components useful for visualization in
|
||||||
various scientific applications. Currently, the main application is 3D visualization for particle
|
various scientific applications. The main application for now is 3D visualization for particle
|
||||||
physics experiments.
|
physics experiments. Other applications including 2D plots are planned for future.
|
||||||
|
|
||||||
The project is developed as a Kotlin multiplatform application, currently
|
The project is developed as a Kotlin multiplatform application, currently
|
||||||
targeting browser JavaScript and JVM.
|
targeting browser JavaScript and JVM.
|
||||||
|
@ -8,6 +8,8 @@ import hep.dataforge.vis.common.AbstractVisualObject
|
|||||||
import kotlinx.serialization.Serializable
|
import kotlinx.serialization.Serializable
|
||||||
import kotlinx.serialization.UseSerializers
|
import kotlinx.serialization.UseSerializers
|
||||||
import kotlin.math.PI
|
import kotlin.math.PI
|
||||||
|
import kotlin.math.cos
|
||||||
|
import kotlin.math.sin
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
class Sphere(
|
class Sphere(
|
||||||
@ -26,16 +28,31 @@ class Sphere(
|
|||||||
override var scale: Point3D? = null
|
override var scale: Point3D? = null
|
||||||
|
|
||||||
override fun <T : Any> toGeometry(geometryBuilder: GeometryBuilder<T>) {
|
override fun <T : Any> toGeometry(geometryBuilder: GeometryBuilder<T>) {
|
||||||
TODO("not implemented")
|
fun point3DfromSphCoord(r: Float, theta: Float, phi: Float): Point3D {
|
||||||
// val segments = this.detail ?: 8
|
val z = r * cos(theta)
|
||||||
// require(segments >= 4) { "The detail for sphere must be >= 4" }
|
val x = r * sin(theta) * cos(phi)
|
||||||
// val phiStep = phi / segments
|
val y = r * sin(theta) * sin(phi)
|
||||||
// val thetaStep = theta / segments
|
return Point3D(x, y, z)
|
||||||
// for (i in 1 until segments - 1) {
|
}
|
||||||
// for (j in 0 until segments - 1) {
|
val segments = this.detail ?: 8
|
||||||
// val point1 = Point3D()
|
require(segments >= 4) { "The detail for sphere must be >= 4" }
|
||||||
// }
|
val phiStep = phi / segments
|
||||||
// }
|
val thetaStep = theta / segments
|
||||||
|
for (i in 0 until segments) { // theta iteration
|
||||||
|
val theta1 = thetaStart + i * thetaStep
|
||||||
|
val theta2 = theta1 + thetaStep
|
||||||
|
for (j in 0 until segments) { // phi iteration
|
||||||
|
val phi1 = phiStart + j * phiStep
|
||||||
|
val phi2 = phi1 + phiStep
|
||||||
|
val point1 = point3DfromSphCoord(radius, theta1, phi1)
|
||||||
|
val point2 = point3DfromSphCoord(radius, theta1, phi2)
|
||||||
|
val point3 = point3DfromSphCoord(radius, theta2, phi2)
|
||||||
|
val point4 = point3DfromSphCoord(radius, theta2, phi1)
|
||||||
|
geometryBuilder.apply {
|
||||||
|
face4(point1, point2, point3, point4)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user