0
$\begingroup$

The problem

I'm using a 3D extension of the well-known "Turtle graphics" to draw plants. My system works by maintaining a position $\vec{p}$ and three vectors:

  • The heading $\vec{H}$
  • The "up" direction $\vec{U}$
  • The "left" direction $\vec{L}$

My problem is now that I want to be able to create 3D objects at the position of the turtle, but with the added difficulty of being "transformed" into the turtle's coordinate system defined by the vectors $\vec{H}, \vec{U}$ and $\vec{L}$, so that the model is "aligned" with the direction and orientation of the turtle. I basically want to achieve that the model is transformed in such a way, that:

  • The local origin becomes the turtle position
  • The local x-Axis is rotated onto the heading vector $\vec{H}$
  • The local y-Axis is rotated onto the right vector $- \vec{L}$
  • The local z-Axis is rotated onto the up vector $\vec{U}$

The reason I want this is to be able to spawn 3D models that describe the leaves of a plant on stalks generated by the turtle.

My own idea so far

I'm not very good at linear algebra, but I thought of using a base change matrix of the form: $$A := \begin{pmatrix}\vec{H} & -\vec{L} & \vec{U} \end{pmatrix}$$ And combining that with the translation by $\vec{p}$ to obtain the following model matrix:

$$T := \begin{pmatrix} A & \begin{matrix} p_1 \\ p_2 \\ p_3\end{matrix}\\ \begin{matrix}0 & 0& 0\end{matrix} & 1 \end{pmatrix}$$

Would this achieve the effect I want? I am currently only in the planning phase of the project this will be used in, so I can't check this myself.

$\endgroup$
6
  • $\begingroup$ Sure that should work $\endgroup$
    – joojaa
    Dec 16, 2019 at 22:28
  • $\begingroup$ @joojaa Thanks! In addition, i also wanna scale the model by a factor $f$. Do i have to apply the scaling matrix before $T$ (as in $T \cdot S$), or after it (as in $S\cdot T$)? I never worked with base change matrices before. $\endgroup$
    – Katharina
    Dec 16, 2019 at 22:58
  • $\begingroup$ Depends on about what you want to scale. OTOH if you do a $T^{-1} S T$ it does not matter much. $\endgroup$
    – joojaa
    Dec 17, 2019 at 7:19
  • $\begingroup$ @joojaa I basically want to scale the model I am placing, so I would like to basically scale it, and then move it into the new coordinate system. That would be $T * S$ then, right? $\endgroup$
    – nshct
    Dec 17, 2019 at 14:37
  • $\begingroup$ But scale about what point $\endgroup$
    – joojaa
    Dec 17, 2019 at 14:53

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.