We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I have a sphere covered with a number of small cubes and I want the cubes to be orientated so their z axis points to the center of the sphere... how do I go about doing this ? I'm not having much luck with forum search, but somebody must have asked this before. Can anyone point to an example here or elsewhere ?
Thanks in advance, mala
Answers
It will be great if you can post what you have. The key words for your task are:
rotate()
pushMatrix()
popMatrix()
Using rectMode(CENTER) should make things a bit easier.
The last part is figuring out the rotation angles to be used for each cube (I assume you know where the center of each cube is on the sphere). You need spherical coordinate system: https://forum.processing.org/two/search?Search=spherical
Kf
sorry for the misleading description, there is no actual sphere, the cubes are arranged _as if _they are on the surface of a sphere, the XYZ positions are set from a CSV file read into a Table, so I do know their positions. The cubes themselves are a custom PShape. The relevant section of code I have so far... it's figuring the angles that I'm lost with:
I know nothing about the Spherical coordinate system yet, so looks like i have a bit of reading and learning to do!
this is as close as I've got so far, something still a bit funky going on with some of the cubes for some reason
This is a start: http://mathworld.wolfram.com/SphericalCoordinates.html
Would this solve your problem?
Kf
thank Kf, tbh I'm getting pretty lost with that ,I do have a lot to learn. This is what I've managed to muddle through with so far:
the 'funky' cubes were the ones in a -Z position, kinda fixed that, but still have some that are pretty much bang on the XY plane that are not behaving. kinda feel like I need to remap either the
this.pos.Z
or theangleX
itself...but not sure what to.Check the following post: https://forum.processing.org/two/discussion/20688/plotting-points-on-a-sphere#latest
If you run either jeremydouglass or Chrisir's code at the beginning of the chain, you will see how to do the x-y-z to theta-phi-r transformation. You can click and drag the mouse on the x or y direction and you will see changes in the number of points being plotted along theta or phi
anglesprojections.Kf
Hi Kf, I'm obviously missing something there, as I can only see that the code in that thread is positioning the spheres not rotating them to align an axis to look at center of sphere.
Here is a simplified cut down version of my code which I hope shows the problem, needs peasycam and the csv file:
To make it easier to see the problem cubes, the cubes are elongated and there is a large sphere at the center, cubes should all point to center of sphere.
cubePositions.csv : (can't see how I would upload file here so copy to a new file)
That was fun ;)
Cheers, mala
Replace lines 38 and 39 with:
So the trick is this. You know the center position of each box on top of the surface. Based on the previous website explaining conversion of Cartesian to spherical coordinates, you need to get theta and phi angles. I apply angle theta first on the Z axis and angle phi on the Y axis and in that specific order (very important).
Why those angles? Well, if you trace an imaginary line from the center of any cube to the center of the arrangement, you'll get a line of length
L = sqrt(x^2+Y^2+Z^)
and defined by two angles theta and phi.Kf
P.S. Note to myself: An alternative to peasyCam, use this:
camera(map(mouseX,0,width,-width,width),map(mouseY,0,height,-height,height),zc,width>>1,height>>1,0,0,1,0);
Notice sketch needs to be translated to its center position.ha... just solved it myself by trial and error, this was it:
yours is a much neater solution Thanks for sticking with me on this ;)
Cheers, mala