# [Bf-committers] Scale from Matrix

Ramon Carlos Ruiz ramoncarlosruiz at gmail.com
Sun May 7 02:42:35 CEST 2006

```well I think I have to study more the mathematical functions of blenders
jejeje. I did that step by step and it work fine

float mat[3][4];
float sc[3];
float v[3],norm,may;
int i;
v[0]=obmat[0][0];
v[1]=obmat[0][1];
v[2]=obmat[0][2];
if (abs(v[0])>abs(v[1])){i=0; may=v[0];}
else {i=1; may=v[1];}
if (abs(v[2])>abs(may)) {i=2; may=v[2];};
norm = (float) sqrt(v[0] * v[0] + v[1] * v[1] + v[2] * v[2]);
v[0] /= norm;
v[1] /= norm;
v[2] /= norm;
sc[0]=(may/v[i]);

Un Saludo
RCRuiz

On 5/6/06, Chris Want <cwant at ualberta.ca> wrote:
>
>
> Hi Ramon,
>
> We've tried something that I think is along the lines
> of what you are suggesting:
>
> float mat1[4][4], mat2[4][4], mat3[4][4];
>
> EulToMat4( ob->rot, mat1);
> Mat4Invert(mat2, mat1);
> Mat4MulMat4(mat3, ob->obmat, mat2);
>
> sizeX = mat3[0][0];
> sizeY = mat3[1][1];
> sizeZ = mat3[2][2];
>
> The problem is that it fails when there is
> parenting involved. Actually, the calculation
> of size when there is parenting is really weird
> since it always depends in part on the size of
> the parent at the time the parenting relationship
> was defined.
>
> Chris
>
>
> Ramon Carlos Ruiz wrote:
> > Hi, this is very simple. For Sx first normailze
> > mat[0][0],mat[0][1],mat[0][2] and create n[0][0],n[0][1],n[0][2], that
> > contain the rotation only. now pick the bigger number of the first row .
> > . lets said mat[0][0], then divide that element with n[0][0] and that's
> > Sx or 1/Sx
> >
> > Un Saludo
> > RCRuiz
> >
> > On 5/6/06, *Chris Want* <cwant at ualberta.ca <mailto:cwant at ualberta.ca>>
> > wrote:
> >
> >
> >     Hrmm, this is quite wrong, please disregard
> >     (serves me right to do math on a Friday night).
> >
> >     Chris
> >
> >
> >     Chris Want wrote:
> >
> >      > Hi Campbell,
> >      >
> >      > My linear algebra is a bit shaky, but I think it goes something
> >      > like this:
> >      >
> >      > Suppose you have mat (the one you are feeding to Mat4ToSize),
> >      > and the positive output from Mat4ToSize, sx, sy, sz.
> >      >
> >      > The real SizeX, SizeY and SizeZ should be eigenvalues of mat.
> >      > The eigenvectors should be the columns of mat (so first column of
> >      > mat cooresponds to eigenvalue SizeX, etc). Call these column
> vectors
> >      > v1, v2, v3.
> >      >
> >      > So, what I believe you should do is test that mat*v1 == sx*v1
> >      > (both sides are column vectors, left side is matrix
> multiplication,
> >      > right side is scalar multiplication).
> >      >
> >      > If this is true (within some error tolerance), then sx is indeed
> >      > the correct eigenvalue, so you can set SizeX = sx,
> >      > else SizeX = -sx (might be prudent to test that mat*v1 ==
> -sx*v1).
> >      >
> >      > Similarly, test mat*v2 = sy*v2 and mat*v3 = sz*v3.
> >      >
> >      > Anyways, I hope my recollection isn't too hazy, and that the
> >     description
> >      > isn't too incoherent.
> >      >
> >      > Regards,
> >      > Chris
> >      >
> >      > _______________________________________________
> >      > Bf-committers mailing list
> >      > Bf-committers at projects.blender.org
> >     <mailto:Bf-committers at projects.blender.org>
> >      > http://projects.blender.org/mailman/listinfo/bf-committers
> >      >
> >
> >     _______________________________________________
> >     Bf-committers mailing list
> >     Bf-committers at projects.blender.org
> >     <mailto:Bf-committers at projects.blender.org>
> >     http://projects.blender.org/mailman/listinfo/bf-committers
> >     <http://projects.blender.org/mailman/listinfo/bf-committers>
> >
> >
> >
> > ------------------------------------------------------------------------
> >
> > _______________________________________________
> > Bf-committers mailing list
> > Bf-committers at projects.blender.org
> > http://projects.blender.org/mailman/listinfo/bf-committers
>
> _______________________________________________
> Bf-committers mailing list
> Bf-committers at projects.blender.org
> http://projects.blender.org/mailman/listinfo/bf-committers
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://projects.blender.org/pipermail/bf-committers/attachments/20060506/1e99dfbf/attachment-0001.htm
```