Skip to content

Commit

Permalink
fix(app): add sphericalToCartesian method
Browse files Browse the repository at this point in the history
This shouldn't really be necessary ... follow up should be to try to understand why we can't use native threejs methods.

Prettifier
  • Loading branch information
EdwardMoyse committed Apr 1, 2021
1 parent 8e6ffcb commit bbea6b0
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 10 deletions.
15 changes: 15 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -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}"
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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';
Expand Down

0 comments on commit bbea6b0

Please sign in to comment.