Some doc and Sphere geometry #11 #18

Merged
pklimai merged 4 commits from doc into dev 2020-02-05 12:48:49 +03:00
2 changed files with 29 additions and 12 deletions
Showing only changes of commit 8206a636b5 - Show all commits

View File

@ -4,8 +4,8 @@
This repository contains [DataForge](http://npm.mipt.ru/dataforge/)
(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
physics experiments.
various scientific applications. The main application for now is 3D visualization for particle
physics experiments. Other applications including 2D plots are planned for future.
The project is developed as a Kotlin multiplatform application, currently
targeting browser JavaScript and JVM.

View File

@ -8,6 +8,8 @@ import hep.dataforge.vis.common.AbstractVisualObject
import kotlinx.serialization.Serializable
import kotlinx.serialization.UseSerializers
import kotlin.math.PI
import kotlin.math.cos
import kotlin.math.sin
@Serializable
class Sphere(
@ -26,16 +28,31 @@ class Sphere(
override var scale: Point3D? = null
override fun <T : Any> toGeometry(geometryBuilder: GeometryBuilder<T>) {
TODO("not implemented")
// val segments = this.detail ?: 8
// require(segments >= 4) { "The detail for sphere must be >= 4" }
// val phiStep = phi / segments
// val thetaStep = theta / segments
// for (i in 1 until segments - 1) {
// for (j in 0 until segments - 1) {
// val point1 = Point3D()
// }
// }
fun point3DfromSphCoord(r: Float, theta: Float, phi: Float): Point3D {
val z = r * cos(theta)
val x = r * sin(theta) * cos(phi)
val y = r * sin(theta) * sin(phi)
return Point3D(x, y, z)
}
val segments = this.detail ?: 8
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)
}
}
}
}
}