We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hello All,
This question may seem very basic, but after a few years of coding, and a few days of searching on the web, I have to admit that I failed to properly move an object on a sphere :'-( After developping a fairly cool 2D flocking system, I wanted to push it to the next dimension, having my boids move on a sphere.
Before interacting with each other, my boids should be able to move along a 'straight' axis on the sphere, which does not necessarily go through the pole(s). I guess that implies some kind of constant speed (radial or not) and that's where I get stuck. I found very few topics on the web about that, mentionning quaternions, spherical coordinates and such, but I couldn't figure it out anyway.
Please share your thoughts about this, any comment is welcome :-)
Answers
draw us a picture, show us what you mean.
i'd be tempted to extend the 2d to 3d and then just map the 3d to a sphere by normalising the distances from the origin. won't be totally accurate, will probably look ok.
Your projection idea is worth a try, I'll let you know when I implement it. About your question, imagine a satellite rotating around the earth. It could look like something like this:
Or, as I tried to explain in my previous post, the trajectory could be even simpler, and remain similar throughout time, along the equator for instance (a sphere has an infinite number of "equators", that's what I tried to express above).
ok, so all those circles are centred on the origin, got it.
oh, and this is before interacting? i think i missed that bit before. don't they always interact?
orbits are easy enough - have a particle moving along the equator and then rotate the equator (in two directions). will post code (when i've written it)
Your code is realy nice'n easy koogs, thx for sharing I'll use it some day for sure. However, that said I wouldn't know how to have my boids interact with each other now; Except if, as you mentionned, I dealt with them as if in a 3D environment, then mapping them onto a sphere again. Before reading your code, that's what I tried to do and here's what it looks like:
yeah, i'm not sure that my code was ever going to butt* with your code at all but if it's useful in any way...
the "Before interacting with each other" thing is puzzling because i thought that boids were always interacting with each other... (ah, it's a distance thing)
your sketch looks a bit odd but i can't put my finger on why. something about the movement? might be the projection... i see what you mean about the unaffected birds, those flying around on their own - erratic.
the big spike in the main sphere is a known problem. i think the solution is to use a unit sphere that's scaled rather than a sphere with a given radius. (ok, fixed in processing2 by the looks. or maybe i just can't see it as the sphere is now opaque)
ellipse in line 172 is notoriously slow as well, maybe use a triangle?
you are also checking all the boids against all the other boids including the ones you've already updated. might cause problems.
(* "to place end to end or side to side without overlapping" *2)
(*2 "Butt is currently in the top 30% of lookups on Merriam-Webster.com." - slow dictionary day!)
What I meant by "Before interacting with each other", is that boids should have kinda 'regular' speed (which in your code is the 'angle' variable), a speed that could be modified by the other boids. In your case, other boids should have an impact on 'angle', as well as 'ay' and 'az' I believe.
Otherwise, you're totally right about "you are also checking all the boids against all the other boids including the ones you've already updated. might cause problems." When rectified, things seem to go a bit better, thanks again :)>-
After wandering on other sketches, here is the final result, quite close to what I expected <):) http://www.openprocessing.org/sketch/147633