3
\$\begingroup\$

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!

\$\endgroup\$
  • \$\begingroup\$ You could try altering the angle based on the orientation of the current segment. If it's currently tilted to the right of vertical, tilt the next segment a bit farther right as if gravity were pulling on it, and vice versa. \$\endgroup\$ – Nathan Reed Sep 25 '13 at 18:52
  • \$\begingroup\$ Thank you! I have considered that, but only as a last resort as it involves a bunch of conditionals - as you say, IF tilted to the right, tilt a little more to the right, also pitch a little down if heading forward, BUT more up if belly-up and so on. I imagined there would be an easier, straightforward way to simulate a gravitational "pull" on the turtle's trajectory. \$\endgroup\$ – Akareyon Sep 26 '13 at 8:03
  • \$\begingroup\$ Well, I imagined coming up with a formula rather than a bunch of conditionals. The amount of extra tilt should vary continously with the current orientation. \$\endgroup\$ – Nathan Reed Sep 26 '13 at 18:19
  • \$\begingroup\$ Maybe I was being unclear. Here: math.stackexchange.com/questions/40808/… I learned how the gravity vector inside the object is computed, with the world gravity vector and the rotation matrix given; therefor I was under the impression that some similarly trivial approach would suffice to transform a rotation matrix "towards" a world vector, so to speak. \$\endgroup\$ – Akareyon Sep 27 '13 at 8:56
  • \$\begingroup\$ @Akareyon I would love to see this work as I do have an L-System, maybe you could create a separate matrix, and just use matrix multiplication? Other than that, I guess you must resort to some other iterative method. \$\endgroup\$ – akaltar Jun 26 '15 at 22:02
1
\$\begingroup\$

Sounds like your talking about inertial force, if right go further right, that sounds like interia.

Record previous movement use that as inertia value. If rocket adds rotation of x, it will same rotation for every iteration of x time.

If you are talking about gravity, isn't that just a translation of the object some distance based on current speed * time since last computation, and where the speed is increased each tick by the formula of acceleration of gravity?

If your talking about rotating like a falling building, then part of the vector is canceled at first by the reverse force of the 'structure' holding it up(why non leaning buildings don't fall) once you find the pivot point, the force of the building holding up the weight, and the direction of gravity are added, and they move the point outward. If at 15 degree tilt, most of the force of rigidity counters most of the gravity, but some continues to push it outward. As it gets further out, the rigidity is at a different angle, and more of that force is pushing outward.

But I might not know at all what your talking about. Sounds like your trying to deduce gravity of an object that has some ridgid structure as another force.

\$\endgroup\$

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.