oh, and you have a typo in 'matX.Set(0,1,0,0,cx,sx,0,-sx,**cx)'
it should be 'matX.Set(1,0,0,0,cx,sx,0,-sx,**cx)'


On Mon, Aug 26, 2013 at 6:45 PM, Vladimir Jankijevic <
[email protected]> wrote:

> if you want to do it the hard way you can do it like this:
>
> # Python
> import math
> x = -45.0
> y = 45.0
> z = 0.0
>
> def degToRad(value):
>     return value * (math.pi / 180)
>
> cx = math.cos(degToRad(x))
> sx = math.sin(degToRad(x))
> cy = math.cos(degToRad(y))
> sy = math.sin(degToRad(y))
> cz = math.cos(degToRad(z))
> sz = math.sin(degToRad(z))
>
>
> rotationX = XSIMath.CreateMatrix3( 1,0,0,
>  0,cx,sx,
> 0,-sx,cx)
> rotationY = XSIMath.CreateMatrix3( cy,0,-sy,
>  0,1,0,
> sy,0,cy)
> rotationZ = XSIMath.CreateMatrix3( cz,sz,0,
>  -sz,cz,0,
> 0,0,1)
>  rotationXY = XSIMath.CreateMatrix3( rotationX.Value(0,0) *
> rotationY.Value(0,0) + rotationX.Value(0,1) * rotationY.Value(1,0) +
> rotationX.Value(0,2) * rotationY.Value(2,0),
>  rotationX.Value(0,0) * rotationY.Value(0,1) + rotationX.Value(0,1) *
> rotationY.Value(1,1) + rotationX.Value(0,2) * rotationY.Value(2,1),
> rotationX.Value(0,0) * rotationY.Value(0,2) + rotationX.Value(0,1) *
> rotationY.Value(1,2) + rotationX.Value(0,2) * rotationY.Value(2,2),
>  rotationX.Value(1,0) * rotationY.Value(0,0) + rotationX.Value(1,1) *
> rotationY.Value(1,0) + rotationX.Value(1,2) * rotationY.Value(2,0),
>  rotationX.Value(1,0) * rotationY.Value(0,1) + rotationX.Value(1,1) *
> rotationY.Value(1,1) + rotationX.Value(1,2) * rotationY.Value(2,1),
> rotationX.Value(1,0) * rotationY.Value(0,2) + rotationX.Value(1,1) *
> rotationY.Value(1,2) + rotationX.Value(1,2) * rotationY.Value(2,2),
>  rotationX.Value(2,0) * rotationY.Value(0,0) + rotationX.Value(2,1) *
> rotationY.Value(1,0) + rotationX.Value(2,2) * rotationY.Value(2,0),
>  rotationX.Value(2,0) * rotationY.Value(0,1) + rotationX.Value(2,1) *
> rotationY.Value(1,1) + rotationX.Value(2,2) * rotationY.Value(2,1),
> rotationX.Value(2,0) * rotationY.Value(0,2) + rotationX.Value(2,1) *
> rotationY.Value(1,2) + rotationX.Value(2,2) * rotationY.Value(2,2))
>  rotationXYZ = XSIMath.CreateMatrix3(rotationXY.Value(0,0) *
> rotationZ.Value(0,0) + rotationXY.Value(0,1) * rotationZ.Value(1,0) +
> rotationXY.Value(0,2) * rotationZ.Value(2,0),
>  rotationXY.Value(0,0) * rotationZ.Value(0,1) + rotationXY.Value(0,1) *
> rotationZ.Value(1,1) + rotationXY.Value(0,2) * rotationZ.Value(2,1),
> rotationXY.Value(0,0) * rotationZ.Value(0,2) + rotationXY.Value(0,1) *
> rotationZ.Value(1,2) + rotationXY.Value(0,2) * rotationZ.Value(2,2),
>  rotationXY.Value(1,0) * rotationZ.Value(0,0) + rotationXY.Value(1,1) *
> rotationZ.Value(1,0) + rotationXY.Value(1,2) * rotationZ.Value(2,0),
>  rotationXY.Value(1,0) * rotationZ.Value(0,1) + rotationXY.Value(1,1) *
> rotationZ.Value(1,1) + rotationXY.Value(1,2) * rotationZ.Value(2,1),
> rotationXY.Value(1,0) * rotationZ.Value(0,2) + rotationXY.Value(1,1) *
> rotationZ.Value(1,2) + rotationXY.Value(1,2) * rotationZ.Value(2,2),
>  rotationXY.Value(2,0) * rotationZ.Value(0,0) + rotationXY.Value(2,1) *
> rotationZ.Value(1,0) + rotationXY.Value(2,2) * rotationZ.Value(2,0),
>  rotationXY.Value(2,0) * rotationZ.Value(0,1) + rotationXY.Value(2,1) *
> rotationZ.Value(1,1) + rotationXY.Value(2,2) * rotationZ.Value(2,1),
> rotationXY.Value(2,0) * rotationZ.Value(0,2) + rotationXY.Value(2,1) *
> rotationZ.Value(1,2) + rotationXY.Value(2,2) * rotationZ.Value(2,2))
> xfo = XSIMath.CreateTransform()
> xfo.SetRotationFromMatrix3(rotationXYZ)
>
> Application.Selection(0).Kinematics.Global.PutTransform2(None, xfo)
>
>
>
> On Mon, Aug 26, 2013 at 6:05 PM, Matt Lind <[email protected]>wrote:
>
>> Don't you have Mr LaForge and Mr. LeClaire at your disposal?  I would
>> think they could answer in a heartbeat.
>>
>>
>> Anyway, an alternate way of dealing with this problem is to export the
>> axis vectors instead of computing the rotations.  This ensures you get a
>> match and you don't have to deal with math.
>>
>>
>> Matt
>>
>>
>>
>>
>> -----Original Message-----
>> From: [email protected] [mailto:
>> [email protected]] On Behalf Of Eric Thivierge
>> Sent: Monday, August 26, 2013 2:46 PM
>> To: [email protected]
>> Subject: SI Matrix3 and Maths
>>
>> Hey all,
>>
>> Plunging ever further into the depths of matrices and the fun math issues
>> one may need to solve while building some tools for the studio.
>>
>> I'm trying to figure out how the SI Matrix3's are derived / set and am
>> hitting some walls. I have some Euler angles that I need to convert to
>> Matrix3's then set a Transform from the result.
>>
>> Basically a Euler angle to Matrix3 operation. I need to solve this
>> without the built in methods as I need to convert data from external
>> sources to align with Softimage without the SDK available.
>>
>> I've referenced many of web sites (wikipedia, educational institutions,
>> etc.) and all of the equations for multiplying the 3 matrices (x,y,z) end
>> up with results that are not consistent with Softimage's methods.
>> The only source that has proven to give me valid results is the 3D Math
>> Primer for Graphics and Game Dev book (Chapter 8.7). However it only shows
>> the solution for XYZ rotation order and even that I'm unsure how they got
>> the order in which they multiply the rows / columns.
>>
>> If any of you smart people out there (Raf, Matt?) have a few free minutes
>> to review my below code and show me the error of my ways I'd appreciate it.
>> Maybe others could benefit too.
>>
>> Create 2 nulls. Set one rotation to x = -45, y=45 Select 2nd null and run
>> script.
>> Swap the commented "result" line and run again.
>>
>> # Python
>> import math
>>
>> si = Application
>> log = si.LogMessage
>> sel = si.Selection
>>
>> def degToRad(value):
>>      return value * (math.pi / 180)
>>
>> x = -45
>> y = 45
>> z = 0
>>
>>
>> cx = math.cos(degToRad(x))
>> sx = math.sin(degToRad(x))
>> cy = math.cos(degToRad(y))
>> sy = math.sin(degToRad(y))
>> cz = math.cos(degToRad(z))
>> sz = math.sin(degToRad(z))
>>
>>
>> matX = XSIMath.CreateMatrix3()
>> matX.Set(0,1,0,0,cx,sx,0,-sx,cx)
>>
>> matY = XSIMath.CreateMatrix3()
>> matY.Set(cy,0,-sy,0,1,0,sy,0,cy)
>>
>> matZ = XSIMath.CreateMatrix3()
>> matZ.Set(cz,sz,0,-sz,cz,0,0,0,1)
>>
>> result = XSIMath.CreateMatrix3()
>> # From most sites I referenced-ish
>> #result.Set(cz*cy, sz*cx + cz*sy*sx, sz*sx - cz*sy*cx, -sz*cy, cz*cx -
>> sz*sy*sx, cz*sx + sz*sy*cx, sy, -cy*sx, cy*cx)
>>
>> result.Set(cy*cz + sy*sx*sz, sz*cx, -sy*cz + cy*sx*sz, -cy*sz + sy*sx*cz,
>> cz*cx, sz*sy + cy*sx*cz, sy*cx, -sx, cy*cx) # From Book
>>
>> log(result.Get2())
>>
>> xfo = XSIMath.CreateTransform()
>> xfo.SetRotationFromMatrix3(result)
>>
>> sel(0).Kinematics.Global.PutTransform2(None, xfo)
>>
>> # End Python
>>
>> --
>>
>> Eric Thivierge
>> ===============
>> Character TD / RnD
>> Hybride Technologies
>>
>>
>>
>>
>>
>

Reply via email to