Kali
|
|
« on: December 09, 2012, 06:17:23 AM » |
|
Need some help with this... I'm trying to make an object rotate to match the normal surface of another near object. What I did is... being: pos = position of secondary object (the one to rotate) normal = DE normal of primary object at pos rotate object using: rotation axis = cross(normal,(0,0,1)) rotation angle = acos(dot(normal,(0,0,1))) So I'm aligning the object's z-axis with the normal. This worked when I move the object aligned to the xz or yz planes... This is a test with a simple sphere and a box: https://dl.dropbox.com/s/zrvszku9nrsifnq/normalign1.swf(In the example the thin torus is aligned with the xz plane) But when the object moves outside this planes, there is an undesired rotation around the object's z-axis: https://dl.dropbox.com/s/r3gb9np1es8upjf/normalign2.swfI had some ideas of what could be going on but now I'm stuck and my brain hurts I attached a .frag for more references, you'll see the object moves right when angle1=angle2=0, or angle1=angle2=90 (xz,yz planes) with angle1=90 and angle2=0 (xy plane) the object always rotates at a constant speed. Thanks in advance,
|
|
« Last Edit: December 09, 2012, 07:19:18 AM by Kali »
|
Logged
|
|
|
|
asimes
|
|
« Reply #1 on: December 09, 2012, 08:45:55 AM » |
|
Could it just be that when it reaches that point its target rotation goes from being PI*2 to 0 and so it spins all the way around to get to 0 before increasing again?
|
|
|
Logged
|
|
|
|
Syntopia
|
|
« Reply #2 on: December 09, 2012, 12:14:27 PM » |
|
Aligning two vectors (such as surface normals) is not enough to determine the orientation of an object. The object will be free to rotate around the aligned vectors.
If you know an orthogonal basis (such as a normal and two tangents) for each object, it should be simple to align the two objects, using a 'change of coordinate' matrix M, where the columns are simply the basis-vectors.
But if you only have the surface normal, then you do not have enough information to determine the orientation - I guess that is what you see in your second video.
|
|
|
Logged
|
|
|
|
cKleinhuis
|
|
« Reply #3 on: December 09, 2012, 12:40:28 PM » |
|
this is what tickles me all the time, when programming 3d ... seemingly simple rotations can lead to crappy animations due to indeterminism of the alignment, and basically you show an example for the holy grail problem, because this is comparable to what happens when creating a 3d rotation vector out of a 3d point ... the transform is not smooth, meaning you have one "jump" point due to the hairy ball problem ...
|
|
|
Logged
|
---
divide and conquer - iterate and rule - chaos is No random!
|
|
|
|
Kali
|
|
« Reply #5 on: December 09, 2012, 06:30:41 PM » |
|
Adding an aditional rotation around objects z axis, with angle atan(pos.x, pos.y) partially solved the problem... still rotates at some positions but im on the right track (I think)
|
|
|
Logged
|
|
|
|
eiffie
Guest
|
|
« Reply #6 on: December 11, 2012, 06:21:13 PM » |
|
I'm probably going to get this matrix inverted cause I don't have a code example with me but here is how I do it. You know the direction you want to face but you need one more direction like UP. Take an initial guess that up will be about vec3(0.,1.,0.) then build a rotation matrix like this... mat3 matForward(vec3 fw){ vec3 up=vec3(0.,1.,0.),rt=normalize(cross(fw,up)); up=cross(rt,fw); return mat3(-rt,up,fw); } I should probably check this first lol Not sure about -rt and hopefully the order isn't mat3(rt.x,up.x,fw.x..
|
|
|
Logged
|
|
|
|
jehovajah
|
|
« Reply #7 on: December 17, 2012, 10:51:37 AM » |
|
this is what tickles me all the time, when programming 3d ... seemingly simple rotations can lead to crappy animations due to indeterminism of the alignment, and basically you show an example for the holy grail problem, because this is comparable to what happens when creating a 3d rotation vector out of a 3d point ... the transform is not smooth, meaning you have one "jump" point due to the hairy ball problem ... It tickles me too. We do not know 3d space like we think we do, and our mathematical models are only worked out for certain boundary conditions. Our computers are fantastic and can now show us where we are going wrong in our modeling. The behaviour reminds me of the inverse aspect of the spherical reference frame, that is for every point there is also an inverse point. so when you model sphere for large r you also get a sphere for inverse r. You probably just have to splice the section where this happens out in your formulation. Have you ever wondered why hose pipes and electrical cables get twisted up? Paul Dirac gave an explanation of this which essentially says that we should work with 4π not 2π to get things straightened out, so maybe look at your angular ratios too. Trochoids, man. Everything in 3d space is Trochoids! lol!
|
|
|
Logged
|
May a trochoid of ¥h¶h iteratively entrain your Logos Response transforming into iridescent fractals of orgasmic delight and joy, with kindness, peace and gratitude at all scales within your experience. I beg of you to enrich others as you have been enriched, in vorticose pulsations of extravagance!
|
|
|
Kali
|
|
« Reply #8 on: December 17, 2012, 05:51:32 PM » |
|
I couldn't resolve this yet, thanks for your comments anyway. @eiffie: didn't work, or I'm doing it wrong (most likely )
|
|
|
Logged
|
|
|
|
fractower
Iterator
Posts: 173
|
|
« Reply #9 on: December 17, 2012, 06:43:49 PM » |
|
Try starting with the normal that points toward the origin (which you already have) and the direction you want to object to go. The axis of rotation is just the cross product R = cross(direction, normal).
For example if you want to orbit in the XZ plain then start with position = (0,0,-1), normal = (0,0,1) and direction =(1,0,0).
The axis of rotation is R = cross(direction, normal) = (0,-1,0).
Even if the direction is not orthogonal to the normal the resulting motion will be.
|
|
|
Logged
|
|
|
|
Syntopia
|
|
« Reply #10 on: December 17, 2012, 09:22:04 PM » |
|
The rotation matrix from Wikipedia that fractower refers to, is the same as the 'rotationMatrix3' function in Fragmentarium. Eiffies solution is the same as I suggested (change-of-coordinate matrix), but you still need to have more than one than one axis to align two objects. As fractower suggests, if you know the trajectory in advance (or can calculate force and acceleration), you may use this to define a coordinate system following the object - this is a called a Frenet frame: http://en.wikipedia.org/wiki/Frenet%E2%80%93Serret_formulasYou could also derive a velocity vector based on the last position of your object, but that is not really possible in Fragmentarium, since you cannot access the last value of a uniform variable.
|
|
|
Logged
|
|
|
|
cKleinhuis
|
|
« Reply #11 on: December 18, 2012, 12:18:53 AM » |
|
hey kali and others isnt this the hairy ball theorem problem ? http://en.wikipedia.org/wiki/Hairy_ball_theoremthis bugged me often enough, but you already have the solution: what syntopia meant was: you need to define your object with a 3 component normal on each vertice
|
|
|
Logged
|
---
divide and conquer - iterate and rule - chaos is No random!
|
|
|
cKleinhuis
|
|
« Reply #12 on: December 18, 2012, 12:21:19 AM » |
|
and what you are seeing there is basically the interpolated transform over the non-continous parts of your function... to get you another view on this what you are visualisating is the tranform from a cartesian coordinate to a polar representation this operation is used in the triplex algebra fractalforums.com members rumour that this could be the reason for the "whipped cream" in the standard bulb ....
|
|
« Last Edit: December 18, 2012, 12:24:50 AM by cKleinhuis »
|
Logged
|
---
divide and conquer - iterate and rule - chaos is No random!
|
|
|
eiffie
Guest
|
|
« Reply #13 on: December 18, 2012, 09:00:37 PM » |
|
OK Kali here is what you want (see attached). This brought up an interesting question about apparent wobble. I think I'll make a video to show what I mean since talking in 3d is challenging.
|
|
|
Logged
|
|
|
|
Syntopia
|
|
« Reply #14 on: December 18, 2012, 09:44:49 PM » |
|
Ah. now I can understand what you where asking about, Kali. You just wanted to attach the box rigidly to the ring. I thought you wanted to place the box on an arbitrary DE-object. Sorry for all the confusion :-)
|
|
|
Logged
|
|
|
|
|