From bbea6b03023cc56b5572684ec3cfaeb8cf3f0e7f Mon Sep 17 00:00:00 2001 From: Edward Moyse Date: Wed, 31 Mar 2021 17:40:42 +0200 Subject: [PATCH] fix(app): add sphericalToCartesian method This shouldn't really be necessary ... follow up should be to try to understand why we can't use native threejs methods. Prettifier --- .vscode/launch.json | 15 ++++++++ .../src/loaders/objects/phoenix-objects.ts | 38 ++++++++++++++----- 2 files changed, 43 insertions(+), 10 deletions(-) create mode 100644 .vscode/launch.json diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 000000000..a6a8238d6 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,15 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "type": "pwa-chrome", + "request": "launch", + "name": "Launch Chrome against localhost", + "url": "http://localhost:4200", + "webRoot": "${workspaceFolder}" + } + ] +} \ No newline at end of file diff --git a/packages/phoenix-event-display/src/loaders/objects/phoenix-objects.ts b/packages/phoenix-event-display/src/loaders/objects/phoenix-objects.ts index 534c360bc..ef7be1237 100644 --- a/packages/phoenix-event-display/src/loaders/objects/phoenix-objects.ts +++ b/packages/phoenix-event-display/src/loaders/objects/phoenix-objects.ts @@ -26,11 +26,23 @@ import { RKHelper } from '../../helpers/rk-helper'; * Physics objects that make up an event in Phoenix. */ export class PhoenixObjects { - public static etaToTheta(eta: number): number { return 2 * Math.atan(Math.pow(Math.E, eta)); } + /** This should NOT be necessary - should use native threejs methods such as Vector3.setFromSpherical */ + public static sphericalToCartesian( + radius: number, + theta: number, + phi: number + ): Vector3 { + return new Vector3( + radius * Math.cos(phi) * Math.sin(theta), + radius * Math.sin(phi) * Math.sin(theta), + radius * Math.cos(theta) + ); + } + /** * Process the Track from the given parameters (and positions) * and get it as a geometry. @@ -134,7 +146,9 @@ export class PhoenixObjects { const eta = jetParams.eta; const phi = jetParams.phi; // If theta is given then use that else calculate from eta - const theta = jetParams.theta ? jetParams.theta : PhoenixObjects.etaToTheta(eta); + const theta = jetParams.theta + ? jetParams.theta + : PhoenixObjects.etaToTheta(eta); // Jet energy parameter can either be 'energy' or 'et' let length = (jetParams.energy ? jetParams.energy : jetParams.et) * 0.2; // Ugh - We don't want the Jets to go out of the event display @@ -252,18 +266,22 @@ export class PhoenixObjects { }); // object const cube = new Mesh(geometry, material); + console.log('EJWM cluster eta=' + clusterParams.eta); const theta = PhoenixObjects.etaToTheta(clusterParams.eta); - const pos = new Vector3(4000.0 * Math.cos(clusterParams.phi) * Math.sin(theta), + const pos = new Vector3( + 4000.0 * Math.cos(clusterParams.phi) * Math.sin(theta), 4000.0 * Math.sin(clusterParams.phi) * Math.sin(theta), 4000.0 * Math.cos(theta) ); - cube.position.x = pos.x; - cube.position.y = pos.y; - if (pos.x * pos.x + pos.y * pos.y > maxR * maxR) { - cube.position.x = maxR * Math.cos(clusterParams.phi); - cube.position.y = maxR * Math.sin(clusterParams.phi); - } - cube.position.z = Math.max(Math.min(pos.z, maxZ), -maxZ); // keep in maxZ range. + cube.position.copy( + PhoenixObjects.sphericalToCartesian(4000, theta, clusterParams.phi) + ); + + // if (cube.position.x * cube.position.x + cube.position.y * cube.position.y > maxR * maxR) { + // cube.position.x = maxR * Math.cos(clusterParams.phi); + // cube.position.y = maxR * Math.sin(clusterParams.phi); + // } + // cube.position.z = Math.max(Math.min(pos.z, maxZ), -maxZ); // keep in maxZ range. cube.lookAt(new Vector3(0, 0, 0)); cube.userData = Object.assign({}, clusterParams); cube.name = 'Cluster';