Unfortunatelly (again) rotation questions

Could someone elaborate on how to properly align object along ( or rotate to ) normal? I tried many ways but always i get unpredictable results objects are spinning around like crazy - it looks like Transform.Rotation cannot decide how x,y aligned during the transform - i’m using Transform.Rotation(Vector3d startDirection, Vector3d endDirection, Point3d rotationCenter);

@RIL I saw that you were fighting a lot with similar things maybe some thoughts?
@pascal i don’t know who i should ask about that? @dale is always very helpful but i believe he can be tired cause of my never-ending questions :wink:

It might be helpful to include some of the things you tried and maybe a testcase that fails.

Where is the object you want to align and how do you expect it to align?

A normal does not define the rotational position of the object around the normal direction. How do you want to define that?

Hi @HaLo if normal vector does not define that why objects are rotating randomly even on the same but rotated 90deg polysrf ( objects are rotated 180 deg in this case if we assume closer one is proper)? :wink:

Here are examples:

Objects are fitting normals of surface:

Normal vectors were changed using standard lerp to -1 so normal which is passed to Transform.Rotation is actually -(Vector3d.ZAxis)

Here is also example when normal is inverted so basically -(normalVector)

I’m not totally sure about the cases you provided so I’m guessing, you see the expected rotation if you use the normal of the curved Surfaces?

Rotation identifies the plane of operation with two vertices and a point. The axis of rotation is perpendicular to that plane. For 180° operations, this deteriorates to a line and a plane of possible axes of rotation. Rhino needs to catch that case and make an assumption about your intended axis. I have no idea what that involves, but I think, you should go with an orient operation (Transform.Rotation(Vector3d, Vector3d, Vector3d, Vector3d, Vector3d, Vector3d)) to make sure your object is aligned correctly.

Here is lerp from up -> normal -> down -> -normal - lerp uses small deviations on x and y when ZAxis and -Zaxis and works ok but look at the end that -normal performs unexpected rotations and ends like -normal - 90 deg on Z whats more interesting when it is done on flat surface it is ok ( we must assume that on inverted axis proper Z rotation is always Pi and now when it is -Zaxis (+ small deviations on xy ) i get this right but as soon as we’ll try to get -normal ( so we should get - normal and Pi around normal) we’ll get additional 3/2Pi - and if you’ll watch closely it does not happen for all objects for eg this in center (is rotating more than needed but it ends more or less where it should but others not)

@HaLo method mentioned above needs exact 2 planes always ( if not object is deformed ) so i can’t just use world XYplane there.

Some of the rotation methods will implicitly use a certain plane to orient themselves. You are probably best off by using Transform.Rotation(double angleRad, Vector3d axis, Point3d rotationPoint) which completely specifies a rotation of given angle (in radians) around a given axis, oriented at a given point, i.e. without implicit assumptions.

Also, you may have run into the problem of gimbal lock. An alternative is to use Quaternions to specify a rotation.

Quaternion q; // you specifiy this
Transform t =  q.MatrixForm();

@menno that is what i thought of but i always try to keep things simple as possible - it is very interesting topic but quaternions are new to me and it isn’t very obvious for me in case of four-dimensional vectors :smiley: For now i fixed issue leaving part of the rotation to bottom and further i relate to -Zaxis to -normal and works ok however it would be nice if someone more clever and educated could tell more about this stuff here :wink:

Quaternions is not a trivial topic. Here’s what Lord Kelvin had to say about them:

" Quaternions came from Hamilton after his really good work had been done, and though beautifully ingenious, have been an unmixed evil to those who have touched them in any way."

// Rolf

2 Likes

@RIL it didnt helped at all :smile: to be honest i dont even have idea how to tackle this cause ‘cheating’ didnt worked either here - when normals points downwards problem returns like a bumerang…

@menno since using mentioned method is good idea im not sure how should i lerp all rotations in conjunction.

How can you know what I spared you from touching? :wink:

// Rolf

Since my code isn’t targeting any CAM stuff i’m glad you stoped me :smiley: I have to find a way to cheat it somehow around but if it won’t work i’ll have to dive into this evil … :sweat_smile:

Say, how exactly do you interpolate the target vectors?

I’m still confused by your animation. If you run into gimbal lock or have a unstable rotation at 180 degrees, you should see jumps once you reach the condition and not those smooth transitions.

@HaLo i use the simplest possible lerp without any easing exactly like this in dx Vector3 class:
from + interpolater*(to - from) - https://docs.microsoft.com/en-us/previous-versions/windows/desktop/bb324347(v=vs.85)