Notifications
Clear all

[Closed] Best way to find difference between two rotations?

Finding the differences between two positions in pretty straightforward, but what is the best way to get the difference between two rotations?

I want to be able to determine whether two rotations are within a specified tolerance of each other along the most direct angle between the two. What would be entailed for this?

8 Replies
1 Reply
(@denist)
Joined: 11 months ago

Posts: 0

two people… one is tall, another is short… some is stout, some is skinny. how to get the difference?
the same is for two rotations (quaternions)… compare the distance between their vectors and angles.

Are we talking about rotations or orientations ? i.e rotation is an action (rotate an object x degrees along an axis) and orientation is a state (the orientation of the “up” vector)

If you talk about orientation you can basically calculate the angle between the two up vectors (Z) of your objects.

With nodes A and B :

 angleBetweenAandB = acos (dot $A.dir $B.dir)

Yes, I do mean orientation. (MaxScript uses “rotation”, hence my using it too…)

I was noticing that I was getting some strange values for bones (i.e. two bones would be identical when their orientations clearly did not match), and then realized that I needed to switch to (normalize <bone>.transform[1]) as my basis for comparison instead. 9_9

Also, I was rather surprised to discover that <object>.transform[3] and <object>.dir sometimes diverge in value after the 5th decimal place or so. I assume there is some difference in how the values are calculated?

Okay, so, having a small problem, namely that this method seems to have problems with identical values.

For example:

acos(dot $.dir $.dir)

Normally this returns 0.0, as I would expect it to, but on occasion will randomly return -1.#IND instead.

you have a numeric precision problem.
the dir property should give a normalized vector and the dot product of two unit vectors should be between -1.0 and 1.0. but due to precision issues it sometimes go slightly out of these bounds. The problem is the ArcCos function is defined only for numbers between -1 and 1. Any number that is out of these bounds will return the ±1.#IND value.
Here is a way around it:

fn getAngle obj1 obj2 =
(
	local d = dot obj1.dir obj2.dir
	d = amax d -1.0
	d = amin d 1.0
	acos d
)

Thanks, that helps immensely! The biggest problem with that “indeterminate” value is that you can’t do anything with it once you have it. You can’t even check for it as far I can tell (such as with undefined or unsupplied.)

Max really does some weird things with numbers. I’ve looked through threads where the reasons are explained by smarter people than I, but it’s all over my head and probably wouldn’t help me much even if I understood it.

1 Reply
(@denist)
Joined: 11 months ago

Posts: 0

[left]bit.isNAN and bit.isFinite
[/left]

Denis, thanks but I got it working by simply first testing for identical values, and running the rest of the function only if the values are different. It’s good to know about bit.isNAN and bit.isFinite though!