Logo by HPDZ - Contribute your own Logo!

END OF AN ERA, FRACTALFORUMS.COM IS CONTINUED ON FRACTALFORUMS.ORG

it was a great time but no longer maintainable by c.Kleinhuis contact him for any data retrieval,
thanks and see you perhaps in 10 years again

this forum will stay online for reference
News: Support us via Flattr FLATTR Link
 
*
Welcome, Guest. Please login or register. April 19, 2024, 11:23:58 PM


Login with username, password and session length


The All New FractalForums is now in Public Beta Testing! Visit FractalForums.org and check it out!


Pages: [1] 2   Go Down
  Print  
Share this topic on DiggShare this topic on FacebookShare this topic on GoogleShare this topic on RedditShare this topic on StumbleUponShare this topic on Twitter
Author Topic: Align to normals... what I'm doing wrong?  (Read 705 times)
0 Members and 1 Guest are viewing this topic.
Kali
Fractal Supremo
*****
Posts: 1138


« 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:


<a href="https://dl.dropbox.com/s/zrvszku9nrsifnq/normalign1.swf" target="_blank">https://dl.dropbox.com/s/zrvszku9nrsifnq/normalign1.swf</a>


(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:


<a href="https://dl.dropbox.com/s/r3gb9np1es8upjf/normalign2.swf" target="_blank">https://dl.dropbox.com/s/r3gb9np1es8upjf/normalign2.swf</a>


I had some ideas of what could be going on but now I'm stuck and my brain hurts embarrass

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,



* normalalign.frag (2.87 KB - downloaded 29 times.)
« Last Edit: December 09, 2012, 07:19:18 AM by Kali » Logged

asimes
Fractal Lover
**
Posts: 212



asimes
WWW
« 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
Fractal Molossus
**
Posts: 681



syntopiadk
WWW
« 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
Administrator
Fractal Senior
*******
Posts: 7044


formerly known as 'Trifox'


WWW
« 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 ... wink

Logged

---

divide and conquer - iterate and rule - chaos is No random!
fractower
Iterator
*
Posts: 173


« Reply #4 on: December 09, 2012, 05:44:15 PM »


I have found the rotation matrix described in http://en.wikipedia.org/wiki/Rotation_matrix to be free of artefacts.

<br />R = \begin{bmatrix} \cos \theta +u_x^2 \left(1-\cos \theta\right) & u_x u_y \left(1-\cos \theta\right) - u_z \sin \theta & u_x u_z \left(1-\cos \theta\right) + u_y \sin \theta \\ u_y u_x \left(1-\cos \theta\right) + u_z \sin \theta & \cos \theta + u_y^2\left(1-\cos \theta\right) & u_y u_z \left(1-\cos \theta\right) - u_x \sin \theta \\ u_z u_x \left(1-\cos \theta\right) - u_y \sin \theta & u_z u_y \left(1-\cos \theta\right) + u_x \sin \theta & \cos \theta + u_z^2\left(1-\cos \theta\right) \end{bmatrix}
Logged
Kali
Fractal Supremo
*****
Posts: 1138


« 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 smiley Not sure about -rt and hopefully the order isn't mat3(rt.x,up.x,fw.x..
Logged
jehovajah
Global Moderator
Fractal Senior
******
Posts: 2749


May a trochoid in the void bring you peace


WWW
« 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 ... wink



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
Fractal Supremo
*****
Posts: 1138


« 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  grin)
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
Fractal Molossus
**
Posts: 681



syntopiadk
WWW
« 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_formulas

You 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
Administrator
Fractal Senior
*******
Posts: 7044


formerly known as 'Trifox'


WWW
« 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_theorem

this 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 cheesy
Logged

---

divide and conquer - iterate and rule - chaos is No random!
cKleinhuis
Administrator
Fractal Senior
*******
Posts: 7044


formerly known as 'Trifox'


WWW
« 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 ....  whistling and rolling eyes
« 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.

* normalalignFW.frag (3.03 KB - downloaded 23 times.)
Logged
Syntopia
Fractal Molossus
**
Posts: 681



syntopiadk
WWW
« 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
Pages: [1] 2   Go Down
  Print  
 
Jump to:  

Related Topics
Subject Started by Replies Views Last post
Calculating normals Mandelbulb Implementation « 1 2 3 » ZsquaredplusC 31 13087 Last post December 11, 2009, 11:28:11 AM
by Snakehand
Calculating surface normals for 3D fractals Programming Derakon 0 2680 Last post November 28, 2009, 04:20:30 AM
by Derakon
What is wrong with this image? Mandelbulb 3d Jino 3 1358 Last post June 01, 2012, 02:47:16 PM
by lenord
Snowball Prank Gone Wrong - 3D Animation Animations Showcase (Rate My short Animation) PunishableAnimations 1 2255 Last post January 09, 2016, 12:48:59 AM
by cKleinhuis
Primitives : Align plane / water to view Feature Requests Kyzia 2 1461 Last post July 16, 2017, 09:39:22 PM
by Kyzia

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines

Valid XHTML 1.0! Valid CSS! Dilber MC Theme by HarzeM
Page created in 0.176 seconds with 24 queries. (Pretty URLs adds 0.012s, 2q)