note: I know my issue is more of a mathematical problem than a threejs problem, but I would appreciate the help.
I have this sphere, the blue pins were placed by rotation only (the center is at 0,0,0 and I just rotate along the Y-axis and the Z-axis), the pin (p1) starts at rotation (y=0, z=0), the angles between them are 45 degree. The red spheres are placed using location (XYZ ) the issue is here.
As you can see the sphere of p4 is misplaced, I’m using this method for converting rotation to coordinates:
const rad = Math.PI / 180;
const lat = 45 * rad; // here I change the angle from 45 to what ever I want
const lon = 45 * rad; // same here
// 5 is the radius
const x_ = 5 * Math.cos(lat) * Math.cos(lon);
const y_ = 5 * Math.cos(lat) * Math.sin(lon);
const z_ = 5 * Math.sin(lat);
p4.position.set(x_,y_,z_);
//is this method correct?
@prisoner849 ok, so Spherical uses the Spherical coordinate system. to be honest, I have no idea how this can help me … I went through the documentation and I didn’t see anything useful! Am I missing something? can it returns XYZ coordinate?
I managed to resolve the manual calculation of coordinates (with sin and cos). However, the exact formula set for conversion from spherical to Cartesian coordinates depends on how axes are chosen. So, @Asfan, could draw how your X, Y and Z axes are, as well as what are your lat and lon angles (where is their 0 and what is their positive direction).
@PavelBoytchev I’ve seen your first replay and it might have something to do with it as I’m trying to align the wrong orientation order with the formal or set that I’ve used!
Vector3 is a set of coords for x, y and z. .setFromSphericalCoords(radius, phi, theta); does all the job for you for casting the spherical coordinates into a vector of x, y, z
I tried to use your orientation of axes. In order to fix the positions, I had to replace Y and Z coordinates of the points. See lines 91-92. This is because in Three.js (by default) the Y axis points up.
ooo oo I get it now, I thought the Spherical has a method that calculates xyz and I was missing it somehow! thank you. I’ll try it instead of using manual calculation and see if that can fix my issue.
Though as @PavelBoytchev said, I might have a problem with the rotation order!