Re: Help with understanding matrices
Re: Help with understanding matrices
- Subject: Re: Help with understanding matrices
- From: deivy petrescu <email@hidden>
- Date: Mon, 18 Feb 2008 22:54:39 -0500
On Feb 15, 2008, at 9:20, Simon Topliss wrote:
On 14 Feb 2008, at 21:07, Mark J. Reed wrote:
This page has a good overview of matrix transforms - it's about
Flash,
but it uses the same Adobe-standard terminology:
http://www.senocular.com/flash/tutorials/transformmatrix/
Yes, I've read that. That's where I came up with the modified
handler that uses the format below.
mvalue_a = x scale
mvalue_b = y skew
mvalue_c = x skew
mvalue_d = y scale
mvalue_tx = x translation (position)
mvalue_ty = y translation (position)
Ok, you're mixing up interpretations here. The first four values in
the matrix represent a combination of scaling with *either* skew or
rotation. You can consider either the skew or the rotation as the
primary value and the other one is the result of combining it with
the
scale. But it doesn't make sense to try and extract both rotation
and
skew from a matrix... you'll get two values that depend on each
other.
Probably. I'm pretty poor at math!
I think I understand. But what I'm still not sure about is what if
an object has been scaled, rotated and skewed along one axis (e.g
horizontally skewed)?
This matrix represents an image that is at 100%, but has been
horizontally skewed 12 degrees, then rotated 45 degrees.
{class:matrix, mvalue_a:0.707106769085, mvalue_b:-0.707106769085,
mvalue_c:-0.556806564331, mvalue_d:-0.857406973839,
mvalue_tx:-1.012733203125E+4, mvalue_ty:2137.982421875}
Rotating and skewing an image isn't common, but I'd like to get the
handler nailed-down for all instances.
For example:
set {theta_deg, hscale, vscale, hskew, vskew} to
decode_matrix({mvalue_a:0.707106769085, mvalue_b:-0.707106769085,
mvalue_c:-0.556806564331, mvalue_d:-0.857406973839,
mvalue_tx:-1.012733203125E+4, mvalue_ty:2137.982421875})
log -- (*-38.21843067341, 0.900018629234, -1.091323521466,
-128.21843067341, -38.21843067341*)
on decode_matrix(mat)
set _a to mvalue_a of mat
set _b to mvalue_b of mat
set _c to mvalue_c of mat
set _d to mvalue_d of mat
set theta to atan2 {_c, _a}
set cos_theta to cos (theta)
set hscale to _a / cos_theta
set vscale to _d / cos_theta
set hskew to 180 / pi * theta - 90
set vskew to 180 / pi * theta
set theta_deg to theta / pi * 180
return {theta_deg, hscale, vscale, hskew, vskew}
end decode_matrix
Ideally, what I want the handler to return would be {45.0, 100.0,
100.0, 12.0, 0.0}. So I guess some other calculations are going to
be required?
Simon
Simon,
there are some constyraints. As Mark said, there are only so much you
can do with the information you have. Besides, I have no idea on how
to use "mvalue_ty" or "mvalue_tx". It could help.
Using the handler above and, since I knew what I needed to get :) this
is the handler I came up with:
---
decode_matrix({mvalue_a:0.707106769085, mvalue_b:-0.707106769085,
mvalue_c:-0.556806564331, mvalue_d:-0.857406973839,
mvalue_tx:-1.012733203125E+4, mvalue_ty:2137.982421875})
on decode_matrix(mat)
set _a to mvalue_a of mat
set _b to mvalue_b of mat
set _c to mvalue_c of mat
set _d to mvalue_d of mat
set thetax to atan (_b / _a)---x rotation
set thetay to -1 * (atan (_c / _d))---y rotation
set cos_thetax to cos (thetax)
set cos_thetay to (cos (thetay))
set hscale to _a / cos_thetax
set vscale to _d / cos_thetay
set thetax to 180 / pi * thetax
set thetay to 180 / pi * thetay
set skew to thetay - thetax
return {thetax, thetay, hscale, vscale, skew}
end decode_matrix
--->{-45.0, -32.999998357716, 0.999999982886, -1.022340583597,
12.000001642284}
---
Noticed that I get skew not vskew or hskew. The problem is I have no
way if you actually rotated 33 degrees then skewed vertically 12 or
you rotated 45 degrees and skewed horizontally 12 (to the other side).
Once those 2 other variables are understood you have a better chance.
Deivy
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden