I have ported the Matlab script from https://instruct1.cit.cornell.edu/courses/bionb441/LSystem/ to POV-Ray and everything works fine (although I’m not quite sure why). To navigate a “turtle” through space, it utilizes a 3D rotation matrix (roll/pitch/yaw).
Now I would like to add a “tropism” command to simulate gravity pulling on the elements of an L-System, similar to how Laurens Laprés LParser does, and this is where I’m stuck.
This sounds trivial maybe, but I’ve been hitting walls for the past week, google and dissecting Lparser source code didn’t help a bit:
What operation must be performed to “add” a gravity vector to the rotation matrix, iow: how do I easily rotate x degrees towards (0, -1, 0)?
—If it is of any help, this is a simplified example of how my script performs a YAW of dA radians. The columns of the matrix are stored in three vectors hT, lT, uT. For each, macro Rup(Vector, Angle) is called and returns the new vector (column of the matrix).
Corresponding macros Rlp & Rhp for pitch and roll exist, of course. vdot(A, B) is a POV Ray function and returns the dot product of A and B.
#if (cmdT = "+") #declare hT=Rup(hT, dA); #declare lT=Rup(lT, dA); #declare uT=Rup(uT, dA);
#macro Rup(RotVec, Angle) #local RotX=vdot(RotVec, < cos(Angle), sin(Angle), 0>); #local RotY=vdot(RotVec, <-sin(Angle), cos(Angle), 0>); #local RotZ=vdot(RotVec, < 0, 0, 1>); <RotX, RotY, RotZ> #end
It works perfectly, but I don’t know why so I don’t know what to do to add gravitation. Thanks in advance!