<p>You can't perform this transformation by applying constant transformation matrix to the ladder model since it's not linear transformation like joojaa said in the comments. What you would have to do instead is to define the transformation as a function of height as you have done in both of your proposals.</p>

<p>So both of your proposals are kind of correct, except for the typo in second one where you should use $R$ instead of $T$ that you raise to power of y. However, you might have difficulties raising a matrix to non-integer power (requires expansion of Taylor series, AFAIK), so your first proposal is much more practical.</p>

CC BY-SA 3.0
2016-11-18T17:45:23.680Z
If I define the transformation as a function of height, how can I then express it as a matrix ? or does this mean that I cannot keep it as the traditional matrix form and there should be input inside my rotation matrix? and if so, can I use such matrix in OpenGL to achieve the same results?
Thank you
Ibrahim Radwan
CC BY-SA 3.0
2016-11-18T18:12:43.130Z
You can't express it as a constant matrix, because that's able to do only linear transformations (rotate, translate, skew, scale). Instead you would have to create the matrix for every vertex you transform based on the y-coordinate of the vertex.
JarkkoL
CC BY-SA 3.0
2016-11-18T16:52:42.817Z
2016-11-18T16:52:42.817Z
JarkkoL
<p>In my last Graphic mid-term, the exam contained a Transformation Matrices problem, its statement was:</p>

<h1>Question</h1>

<blockquote>
  <p>Rotate the following ladder to form a DNA-shaped ladder using a transformation matrix.</p>
</blockquote>

<p><a href="https://i.sstatic.net/U2aS1.jpg" rel="nofollow noreferrer"><img src="https://i.sstatic.net/U2aS1l.jpg" alt="enter image description here" title="click for full sized image"></a></p>

<h1>Notes</h1>

<ul>
<li>The ladder base must be kept as it is without any rotating.</li>
<li>The ladder lies in the  x-y plane.</li>
<li>The total rotating angle should equal 540 degrees.</li>
<li>The ladder step width = 2 * ladder step height (This image isn't drawn to scale).</li>
<li>Assume that the curves are straight lines.</li>
</ul>

<h1>First Idea</h1>

<p>When I first read the problem statement, I thought of this basic trivial solution:</p>

<ol>
<li>Translate the ladder such that the ladder's base is on the origin and the y-axis halves the ladder.</li>
<li>Rotate all points by the required angle which depends on the current point y value.</li>
<li>Translate the ladder back to it rotation.</li>
</ol>

<p>Assume that $T(x,y)$ is the transformation matrix that will take care of translation to the origin and its inverse will return the ladder back to its original location, and $R_y(\theta)$ is the rotation matrix around y-axis to perform the rotation to achieve the DNA-shaped ladder.</p>

<p>If we calculate $\theta = 540/12 = 45$ degrees, then we need to rotate as following:</p>

<ul>
<li>1st step by $0$ degrees (to maintain the fixed-base condition).</li>
<li>2nd step by $45$ degrees.</li>
<li>3rd step by $90 = (2*45)$ degrees.</li>
</ul>

<h1>The problem</h1>

<p>I couldn't apply this solution and put it into valid transformation matrix because referring to my previous knowledge (and the logic behind transformation matrices too), I recalled that we cannot put variables (e.g. y) inside the cos, sin functions inside the rotation matrix. Then I thought of another solution if I used power to the rotation matrix by the value of y this will give me the same effect but I also couldn't put this idea into a transformation matrix.</p>

<p>So, to conclude the problem we have 2 ways for achieving this (which I think aren't valid):</p>

<ol>
<li>$\begin{bmatrix}\cos(y\theta)&amp;0&amp;\sin(y\theta)&amp;0\\0&amp;1&amp;0&amp;0\\-\sin(y\theta)&amp;0&amp;\cos(y\theta)&amp;0\\0&amp;0&amp;0&amp;1\end{bmatrix}$</li>
</ol>

<p>And the final answer would be: $P' =  (T(x,y))^{-1} R(45) T(x,y) P$</p>

<ol start="2">
<li>$\begin{bmatrix}\cos(\theta)&amp;0&amp;\sin(\theta)&amp;0\\0&amp;1&amp;0&amp;0\\-\sin(\theta)&amp;0&amp;\cos(\theta)&amp;0\\0&amp;0&amp;0&amp;1\end{bmatrix}$</li>
</ol>

<p>And the final answer would be: $P' =  (T(x,y))^{-1} (R(45))^{y} T(x,y) P$</p>

<h1>Doctor's solution</h1>

<p>My doctor was a big supporter of the first solution and he said this is the correct transformation matrix to solve such problems.</p>

<h1>The real question</h1>

<ul>
<li><p>Do any of these solutions achieve the required result while maintaining the transformation matrix concepts (i.e. avoid equations and direct substitutions and instead use matrices operations)?</p></li>
<li><p>If both solutions are wrong, can you kindly guide me to the valid solution? </p></li>
<li><p>If one of the solutions above is correct, can you please explain why?</p></li>
</ul>

CC BY-SA 3.0
2016-11-18T15:13:30.600Z
A transform like this is not a linear transform!
joojaa
<transformations><matrix>
Ladder to DNA using Transformation Matrix
Ibrahim Radwan
# Ladder to DNA using Transformation Matrix

(Asked by: username_0 on 2016-11-18)

In my last Graphic mid-term, the exam contained a Transformation Matrices problem, its statement was:

# Question

> Rotate the following ladder to form a DNA-shaped ladder using a transformation matrix.

[![enter image description here](https://i.sstatic.net/U2aS1l.jpg "click for full sized image")](https://i.sstatic.net/U2aS1.jpg)

# Notes

* The ladder base must be kept as it is without any rotating.
* The ladder lies in the x-y plane.
* The total rotating angle should equal 540 degrees.
* The ladder step width = 2 \* ladder step height (This image isn't drawn to scale).
* Assume that the curves are straight lines.

# First Idea

When I first read the problem statement, I thought of this basic trivial solution:

1. Translate the ladder such that the ladder's base is on the origin and the y-axis halves the ladder.
2. Rotate all points by the required angle which depends on the current point y value.
3. Translate the ladder back to it rotation.

Assume that $T(x,y)$ is the transformation matrix that will take care of translation to the origin and its inverse will return the ladder back to its original location, and $R\_y(\theta)$ is the rotation matrix around y-axis to perform the rotation to achieve the DNA-shaped ladder.

If we calculate $\theta = 540/12 = 45$ degrees, then we need to rotate as following:

* 1st step by $0$ degrees (to maintain the fixed-base condition).
* 2nd step by $45$ degrees.
* 3rd step by $90 = (2\*45)$ degrees.

# The problem

I couldn't apply this solution and put it into valid transformation matrix because referring to my previous knowledge (and the logic behind transformation matrices too), I recalled that we cannot put variables (e.g. y) inside the cos, sin functions inside the rotation matrix. Then I thought of another solution if I used power to the rotation matrix by the value of y this will give me the same effect but I also couldn't put this idea into a transformation matrix.

So, to conclude the problem we have 2 ways for achieving this (which I think aren't valid):

1. $\begin{bmatrix}\cos(y\theta)&0&\sin(y\theta)&0\\0&1&0&0\\-\sin(y\theta)&0&\cos(y\theta)&0\\0&0&0&1\end{bmatrix}$

And the final answer would be: $P' = (T(x,y))^{-1} R(45) T(x,y) P$

2. $\begin{bmatrix}\cos(\theta)&0&\sin(\theta)&0\\0&1&0&0\\-\sin(\theta)&0&\cos(\theta)&0\\0&0&0&1\end{bmatrix}$

And the final answer would be: $P' = (T(x,y))^{-1} (R(45))^{y} T(x,y) P$

# Doctor's solution

My doctor was a big supporter of the first solution and he said this is the correct transformation matrix to solve such problems.

# The real question

* Do any of these solutions achieve the required result while maintaining the transformation matrix concepts (i.e. avoid equations and direct substitutions and instead use matrices operations)?
* If both solutions are wrong, can you kindly guide me to the valid solution?
* If one of the solutions above is correct, can you please explain why?

**Tags:** transformations, matrix

> **Comments:**
> **username_1**: A transform like this is not a linear transform!  

---

## 1 answers

### Answer by username_2 on 2016-11-18. Score: 3

You can't perform this transformation by applying constant transformation matrix to the ladder model since it's not linear transformation like username_1 said in the comments. What you would have to do instead is to define the transformation as a function of height as you have done in both of your proposals.

So both of your proposals are kind of correct, except for the typo in second one where you should use $R$ instead of $T$ that you raise to power of y. However, you might have difficulties raising a matrix to non-integer power (requires expansion of Taylor series, AFAIK), so your first proposal is much more practical.

> **Comments:**
> **username_0**: If I define the transformation as a function of height, how can I then express it as a matrix ? or does this mean that I cannot keep it as the traditional matrix form and there should be input inside my rotation matrix? and if so, can I use such matrix in OpenGL to achieve the same results? Thank you  
> **username_2**: You can't express it as a constant matrix, because that's able to do only linear transformations (rotate, translate, skew, scale). Instead you would have to create the matrix for every vertex you transform based on the y-coordinate of the vertex.  

---

