<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>Is composing horz + vert shear the same thing as shearing both?</title>
		<link>http://www.allegro.cc/forums/view/616238</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Tue, 03 May 2016 08:24:49 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>That topic title was probably confusing, so here&#39;s a better explanation: Allegro has these functions for doing shear transformation:</p><div class="source-code snippet"><div class="inner"><pre>al_horizontal_shear_transform<span class="k2">(</span><span class="k2">)</span>
al_vertical_shear_transform<span class="k2">(</span><span class="k2">)</span>
</pre></div></div><p>

If I call both of these in sequence, is that the same thing as shearing both X and Y simultaneously?  Think of CSS transformations, it has skewX/skewY() and then just skew() to do both at the same time.</p><p>I ask this because, in general, matrix multiplication is not commutative.  For example translate + rotate is not the same thing as rotate + translate, and I wonder if the same caveat applies here.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Bruce Pascoe)</author>
		<pubDate>Sun, 01 May 2016 06:45:34 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>No, you do indeed get different effects depending on which way you skew first. To skew on both axes simulateously, you need a matrix that looks like this:</p><div class="source-code snippet"><div class="inner"><pre><span class="n">1</span> x <span class="n">0</span> <span class="n">0</span>
y <span class="n">1</span> <span class="n">0</span> <span class="n">0</span>
<span class="n">0</span> <span class="n">0</span> <span class="n">1</span> <span class="n">0</span>
<span class="n">0</span> <span class="n">0</span> <span class="n">0</span> <span class="n">1</span>
</pre></div></div><p>

Which Allegro doesn&#39;t have a simple function to create. I&#39;d do this:</p><div class="source-code snippet"><div class="inner"><pre><a href="http://www.allegro.cc/manual/ALLEGRO_TRANSFORM"><span class="a">ALLEGRO_TRANSFORM</span></a> t<span class="k2">;</span>
<a href="http://www.allegro.cc/manual/al_identity_transform"><span class="a">al_identity_transform</span></a><span class="k2">(</span><span class="k3">&amp;</span>t<span class="k2">)</span><span class="k2">;</span>
t.m<span class="k2">[</span><span class="n">1</span><span class="k2">]</span><span class="k2">[</span><span class="n">0</span><span class="k2">]</span> <span class="k3">=</span> x<span class="k2">;</span>
t.m<span class="k2">[</span><span class="n">0</span><span class="k2">]</span><span class="k2">[</span><span class="n">1</span><span class="k2">]</span> <span class="k3">=</span> y<span class="k2">;</span>
<a href="http://www.allegro.cc/manual/al_compose_transform"><span class="a">al_compose_transform</span></a><span class="k2">(</span><span class="k3">&amp;</span>your_transform, <span class="k3">&amp;</span>t<span class="k2">)</span><span class="k2">;</span>
</pre></div></div><p>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (SiegeLord)</author>
		<pubDate>Sun, 01 May 2016 08:29:49 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Thanks, that&#39;s what I figured.  On a related note, how would I figure out the shear factor given a skew angle?  I think tan() is the right function here, but my trig is a bit rusty...
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Bruce Pascoe)</author>
		<pubDate>Sun, 01 May 2016 10:18:23 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Wikipedia suggests it&#39;s the cotangent, or <span class="source-code"><span class="n">1</span><span class="k3">/</span><a href="http://www.delorie.com/djgpp/doc/libc/libc_803.html" target="_blank">tan</a><span class="k2">(</span>angle<span class="k2">)</span></span>.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (SiegeLord)</author>
		<pubDate>Sun, 01 May 2016 11:00:41 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Intuitively I expect it&#39;s tan if you&#39;re measuring the angle by which a horizontal or vertical line will change from its unskewed position; 1/tan if you&#39;re measuring the angle of the skewed line against the <i>other</i> axis.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Bruce Perry)</author>
		<pubDate>Sun, 01 May 2016 21:09:23 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>@Bruce: I&#39;m actually trying to figure out which values to plug into the matrix for a given skew angle--i.e. the angle is already known, and I need to calculate the shear factor from that.  Allegro itself seems to use tan for this in <span class="source-code">al_<span class="k3">*</span>_shear_transform<span class="k2">(</span><span class="k2">)</span></span>, but like SiegeLord said Wikipedia calls to use the cotangent instead, so... yeah, I&#39;m confused.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Bruce Pascoe)</author>
		<pubDate>Mon, 02 May 2016 07:50:16 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Hmm. I already knew what you were trying to do (you haven&#39;t told me anything new), and I was already trying to pre-empt and explain the exact confusion as to how it could be both tan and 1/tan. I assume Wikipedia is using the cotangent because their idea of an identity matrix would have an angle of 90°, whereas yours or Allegro&#39;s would have an angle of 0. (Of course remember to use radians in the implementation.)</p><p>(Possibly missing piece of the puzzle: tan(angle) = 1/tan(90° - angle).)</p><p>By the way, where is this on Wikipedia?</p><p>[EDIT]<br />I just found <a href="https://en.wikipedia.org/wiki/Shear_mapping">this</a>:
</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>Straight lines parallel to the x-axis remain where they are, while all other lines are turned, by various angles, about the point where they cross the x-axis. Vertical lines, in particular, become oblique lines with slope 1/m. Therefore the shear factor m is the cotangent of the angle φ by which the vertical lines tilt, called the shear angle.</p></div></div><p>
I think it&#39;s either unclear in its definition of the angle, or wrong. It absolutely has to be tan because tan(0) is 0 which leads to an identity matrix whereas 1/tan(0) is infinity (sort of). Who wants to fix Wikipedia?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Bruce Perry)</author>
		<pubDate>Mon, 02 May 2016 14:56:20 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Okay, I understand you now.  I got confused because you said &quot;measuring the angle&quot;, when in my case the angle is already known (and therefore doesn&#39;t need to be measured).</p><p>As for Wikipedia&#39;s definition, now that I read it again it actually seems to be correct, in a roundabout way.  The article uses vertical lines as an example, but assumes the shear is along the X axis.  In the case of perfectly vertical lines, the slope 1/m is either undefined or infinity, depending on how you want to interpret the division by zero.  If they&#39;re measuring the angle of the oblique against the Y axis--in which case perfectly vertical lines are parallel, i.e. so that the slope is 1/Infinity = 0 (for our purposes anyway)--that might actually be correct.   I say <i>might</i> because it&#39;s still very confusingly written, in any case--this is why Wikipedia is useless for any kind of mathematics research.</p><p>Trigonometry is fascinating! <img src="http://www.allegro.cc/forums/smileys/smiley.gif" alt=":)" /></p><p><b>edit + tl;dr:</b> Wikipedia is measuring the oblique against the Y axis, not X.  1/tan is correct in that case.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Bruce Pascoe)</author>
		<pubDate>Tue, 03 May 2016 08:24:49 +0000</pubDate>
	</item>
</rss>
