June 2, 2015, 6:44pm
I turn in rounds for hours now and i think need some help from math gourous ;).
I have an object with a velocity vector. This object always moves in this direction each frame with
How can i modify this velocity vector to make this object orbits around a point (0, 0, 0) on a constant circle path?
I have this :
Vector3f tangent = position.cross(Vector3f.UNIT_Y).normalizeLocal();
(force is the speed of rotation)
It works but i want to avoid velocity.set(…) method cause i have some other things that alterate velocity and this overrides all of them each frame.
Moreover, var force defines speed AND radius in this case which is not desired :s
another try :
Vector3f tangent = p.position.cross(Vector3f.UNIT_Y).normalizeLocal();
velocity.addLocal(position.negate().addLocal(tangent).normalizeLocal().multLocal(this.force * tpf));
It’s more like what i want but the radius increase a bit each frame…
Right now it becomes more like tamper with vector operations than a real solution…
I have not found the right terms in english to find something similar on google.
June 2, 2015, 6:54pm
Diclaimer : I’m not a math guru, so I tend to not use math when I can avoid it.
So…first thing that comes to my mind is why are you using math?
The engine does math for you.
If you want soemthing to orbit around (0,0,0) put a node in (0,0,0), put the geometry in that node, offset it by the radius of your circle and then instead of moving the geom, rotate the node.
Even if you want to modify the velocity you can find a way to to have a rotation velocity instead.
Does it sound reasonable?
June 2, 2015, 6:59pm
Hum yes, i have already done this kind of things many times…math…math u_u.
But i can’t use this in that case :’(. To be more precise, it’s for some kind of particles…so i can’t have one geometry for each particle that orbits ^^. I only have math data in hands…
Anyway thanks ;).
June 2, 2015, 7:07pm
Oh ok… well then math it is.
Maybe you need to look into the basics of this.
You want to “draw” a circle, look at how a circle equation looks like : (x-a)² + (y-b)² = r²
Not sure it’s applicable in your case (with an acceleration) but i figured I’d mention it.
You could use a quaternion to rotate the particles around a point.
Else, let your velocity move the particle and then take a vector representing the line from the object to the center of the circle… then move the position (not velocity) to the center so that the vector has a fixed length.
But you will end up doing length() which does sqrts and stuff.
Way easier to just do quaternion.mult(pos) instead of messing with velocity. Then your velocity just becomes how fast you rotate the quaternion.
What you are looking for is the
parametric form of Circle in 3D:
Look for this equation in the link  below.
P(t) = r * cos(t) + r * sin(t) n cross u + Center
With this equation the parameter t is pretty much your time, or tpf. Your circle is then represented by Center, in your case (0,0,0) and azimuth and elevation angles.