Notifications
Clear all

[Closed] Average transform?

 PEN

What is the best way to get the average of several transforms. I know that I can add up the rows, average them and rebuild a transform but is there a better mathmatical way?

11 Replies

Do you need to dynamically change the number of your transforms object?
If there’s a fix number of transforms, e.g. you are always finding average transforms of 4 objects then i might know of a way to get it faster without re-add/average them.

 PEN

The amount will always change but I would still like to see your answer.

instead of adding the rows i think using slerp for rotation is better.

So lerp the position and scale, and slerp the rotation (as a quat).

I was wondering about this … how do you get an average? Because …
slerp (slerp qA qB 0.5) qC 0.5 != slerp (slerp qB qC 0.5) qA 0.5, etc. etc.

3 Replies
(@kees)
Joined: 11 months ago

Posts: 0

That’s right.

I believe you have to slerp all of them from 0 rotation (quat 0 0 0 1).

So it you have 4 rotations, then you slerp each one with (quat 0 0 0 1) with a interpolation value of 0.25…

But to be sure I have to look at the transform-list code I wrote a year ago to double check what problems I ran into. It could be that I always kept the slerping in the same order there.

So if a rotation is in the third spot in the transform-list, it always gets slerped as 3rd and so on so things remain consistant.

I can’t remember what issues I ran into with averaging the rows in a matrix, but I know there’s problems with that method (probably something to do with scale and rotation being mixed…)

(@drdubosc)
Joined: 11 months ago

Posts: 0

Since we’re looking for an average, not on a particular interpolation path, would it be naive to extract the spherical angles of rotation (theta, phi,) the translation & scale components, average those, and then reconstruct the TM?

(@kees)
Joined: 11 months ago

Posts: 0

I dont know if the average of that ends up properly back on the imaginary ‘sphere’ that you always see when they explain the difference between linear interpolation and slerp for quaternions.

I mean it will get you close, and probably close enough that no-one cares, but it may not be as acurate/smooth of a blend. So if you were doing this averaging in real-time while interaction with several objects/TMs then maybe you’ll see pops.

I can be completely wrong on this though, i’m trying to imagine it in my head and I suck at that stuff :shrug: .

I’m also used to the SDK a bit more with this kind of stuff and I think the rows have scale and rotation mixed together and I think this might be problematic if you just blindy average those. In the SDK I’m used to doing what they call ‘decompose’ which gives you the proper seperated scale and rotation vector3’s and then you continue your math with those and rebuild the TM in the end.

But…to be honest I would just test your ideas and if they work for your situation, then the simpler the better Plus since Paul mentioned that speed is really important then you can probably give up some accuracy and avoid slerp all together (that still leaves the scale/rotation issue to watch out for though)

For rotation i would agree that slerp probably be the best solution. However i had never really tried it yet.

As for position/scale, it can be as easy as adding a delta to the averaged transform.

For example, if is just averaging the position of 4 objects you can just get the delta of any object from its previous position * 0.25 and add that to your averaged transform. It is good cause you are just reading in one set of data and process it independently. Lets say if you have 100 objects and you need to change one of the objects transform, you just need to use 0.01 * your delta instead of reading all the 100 object’s transform. It is probably be better than reaveraging especially when you are dealing with certain task like viewport updating.

Hope it helps.

 PEN

Kees, interesting idea, not sure if that would be faster or slower as slerp is a slow function. I might do a test on it.

Teirz, not sure that I follow. You are suggesting that I just multiply one transform by a factor? How would this get me an average of all?

drdubosc, sounds good but again will it be slower then the method that I’m using.

I spoke with a PHD of molecular physics and he said that what I’m doing would be the fastest and most stright forward way of going about it.

All I’m doing is adding up the rows and deviding by the samples, then normalizing the three vectors and rebuilding the matrix. I think that the slowest process in there is the normalizing. I only do this once for each vector and not each time it is collected so I don’t think it is that bad. I’m going to see if I can do a speed test today on the others against mine and see what happens. I’m trying to get this as fast as possible as it is slowing things down considerably. I might even add a step value so that sampling would take ever other transform for instance and that might get me close enough.

Paul,

If speed is what matters, then linear interpolation is the fastest that I know of.
So yes, then row by row is what you do.
I still think there are limitations there though, but for the time being I can’t remember what they are, so we’ll just assume there are none

good luck!

 PEN

I’m not concerned with scale at all. The end result needs to be a normalized matrix. I’m just after the rotation and position values really. So this is working and I can’t see it getting faster.

Thanks for the time guys.