Notifications
Clear all

[Closed] Averaging matrices?

could you please using the normal-averaging method average these two matrices and show how you do it?
matrix3 [-1,0,0] [0,1,0] [0,0,-1] [0,0,0]
matrix3 [1,0,0] [0,1,0] [0,0,1] [0,0,0]

2 Replies
 PEN
(@pen)
Joined: 11 months ago

Posts: 0

That is where it will break down of course. I’m not trying to say that yours is not the better mathematical solution.

(@denist)
Joined: 11 months ago

Posts: 0

sorry. maybe I’m wrong, but honestly the normal-averaging methods for transform matrices doesn’t make any sense for me.

 PEN

It worked well for what I needed at the time. What you have is definitely more accurate. I should do a speed test on the two as yours could be faster.

 PEN

Ya something like that. Mine did a loop through any number of transforms to get the solution. Each vector needs to be normalized I find or you get small errors popping up.

 PEN

Correct, it will end up in a skewed transform. how ever you can run orthogonalize on it as well and make sure that it is square.

but if we normalize first three rows it will kill scale at all

fine. so if we want to average scales we have to normalize vectors before sum and after, calculate average scale and pre-scale the final matrix.

it’s in matter of the performance…

1 Reply
(@denist)
Joined: 11 months ago

Posts: 0

and we have to check that pair of vectors are not parallel or not differently directed.so it’s three dot products more.

…and I’d never do it that way either (averaging the vectors).

I prefer to maintain separate components. Something like:

struct  PosRotScale
(
	mPos,
	mRot,
	mScale,
	
	fn applyBlend prs1 prs2 w =  (
		invw = (1 - w)
		mScale = prs1.mScale * invw + prs2.mScale * w
		mRot = slerp prs1.mRot prs2.mRot w
		mPos = prs1.mPos * invw + prs2.mPos * w
		),

	fn fromMatrix3 m = ( mPos = m.translation; mRot = m.rotationpart; mScale = m.scalepart; m ),
		
	fn asMatrix3 = ( translate (rotate (scalematrix mScale) mRot) mPos ),

	fn dump = ( format "Pos: %
Rot: %
Scale: %
asMatrix3:%
" mPos (mRot as eulerangles) mScale (asMatrix3()) )
)

m1 = PosRotScale()
m1.fromMatrix3 ((eulerangles 0 50 0) as matrix3)

m2 = PosRotScale()
m2.fromMatrix3 (transMatrix  [10,20,30])

m3 = PosRotScale()
m3.applyBlend m1 m2 0.25

m3.dump()

A more ‘complete’ solution, where memory is traded for speed, would store the matrix too (and perhaps maintain it’s inverse too, if you find that you are inverting it a lot)

 PEN

Yep, this is why I went with the simple averaging of vectors as it did what I needed it to do at the time.

Page 2 / 2