From 0c69c1cdbca193cb6a1cb76f04653f9baf7f5899 Mon Sep 17 00:00:00 2001 From: Peter Klimai Date: Wed, 5 Feb 2020 12:34:08 +0300 Subject: [PATCH] Update Sphere to match three.js axis --- .../kotlin/hep/dataforge/vis/spatial/Sphere.kt | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/Sphere.kt b/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/Sphere.kt index a016747c..58e2c8b6 100644 --- a/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/Sphere.kt +++ b/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/Sphere.kt @@ -29,9 +29,10 @@ class Sphere( override fun toGeometry(geometryBuilder: GeometryBuilder) { 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) + // This transformation matches three.js sphere implementation + val y = r * cos(theta) + val z = r * sin(theta) * sin(phi) + val x = - r * sin(theta) * cos(phi) return Point3D(x, y, z) } val segments = this.detail ?: 8 @@ -49,7 +50,8 @@ class Sphere( val point3 = point3DfromSphCoord(radius, theta2, phi2) val point4 = point3DfromSphCoord(radius, theta2, phi1) geometryBuilder.apply { - face4(point1, point2, point3, point4) + // 1-2-3-4 gives the same face but with opposite orientation + face4(point1, point4, point3, point2) } } }