Jump to content

Path problem


Recommended Posts

Hi, i'm always in trouble trying to write some plugin and learn c++ coding...

I' m trying to write a plugin that use a spline as a motion and deformation path and found a problem. To clarify what the problem is i'll do a simple example that can be tried directly within houdini.

Add a nurbs circle and use it as the path for the camera...

Moving the camera on path you'll see that at position 0 and position 0.5 on the path (and cycling of course) the camera flips its orientation. <_<

Is there a way to avoid this ? :rolleyes:

How to use an up vector with the HDK? :rolleyes:

Is there a way to calculate rotation angle from a direction vector? :rolleyes:

As always thanks for your great support :P

Link to comment
Share on other sites

Hi, i'm always in trouble trying to write some plugin and learn c++ coding...

I' m trying to write a plugin that use a spline as a motion and deformation path and found a problem. To clarify what the problem is i'll do a simple example that can be tried directly within houdini.

Add a nurbs circle and use it as the path for the camera...

Moving the camera on path you'll see that at position 0 and position 0.5 on the path (and cycling of course) the camera flips its orientation.  <_<

This is true if the up vector is not orthogonal to the (local) plane of the path. In the case of a circle on the XY plane for example, you will get flipping if your up vector is X={1,0,0} or Y={0,1,0}, or any other vector that lies on the XY plane (there's an infinite number of them). The flipping will happen at different locations along the circle, but it *will* happen. To avoid flipping (and continuing with the example of a circle on the XY plane), you'd need to choose the up vector Z={0,0,1} or -Z={0,0,-1}.

As far as *why* the flipping happens, the short answer is that if you choose an up vector on the plane of the circle, then at some point along the path, the up vector and the direction of travel (local tangent to the path) become colinear (or linearly dependent). And in the case of a circle, this will happen at two locations (180 degrees apart from each other).

Is there a way to avoid this ?  :rolleyes:

Yes. You can choose an up vector that is perpendicular to the plane tangent to the path (think of it as the "normal" to the path). In the XY-circle example, the choice of UP={0,0,1} would work for the whole path, but of course, an arbitrary curve in 3D doesn't have such a nice implicit surface as your circle example. If the curve is being constructed as a "curve-on-surface", then you can just use the surface's normal as the up vector. If it's not, then you have two choices: 1) ask the user for a global up vector (and expect the solution to flip at some places) -- but basically pass the headache on to the user, or 2) construct a smoothly varying perpendicular to the direction of travel, so that if the tangent to the path (first partial derivative of P with respect to u) is dPdu, then an (arbitrary but smoothly varying) orthogonal vector to it can be constructed with UP = {dPdu.z-dPdu.y,dPdu.x-dPdu.z,dPdu.y-dPdu.x}. This second solution doesn't suffer from the "flipping problem" because it basically spreads the flip over all the angles... but then it doesn't have a controlable orientation.

A third possibility would be to derive a local tangent plane using dPdu and some point further ahead (or behind) along the curve (call it P'), then the up vector would be the (normalized) cross product of dPdu and (P'-P). But in the case of polygonal curves, P' would have to be at least two CVs away from P. But obviously this method would break down if the curve is a stright line.

How to use an up vector with the HDK?  :rolleyes:

An up vector is just a vector, so to "use it with the HDK" you'd just declare it and use it as you would any vector:

#include &lt;UT/UT_Vector3.h&gt;
   //...//
   UT_Vector3 up(0,1,0);
   //... get busy with your newly minted up vector...

If you mean "How do I implement an 'orient' or 'lookat' or 'dihedral' or an axis-angle rotation using the HDK?", then look in the matrix classes -- that's where you'd normally find these kinds of transformations. I just had a quick look at UT_Matrix3 and saw the members dihedral(), lookat(), orient(), rotate() etc... they're all there :) .

Is there a way to calculate rotation angle from a direction vector?  :rolleyes:

Sure. You could express it in spherical coordinates. See this entry at the wiki.

Cheers!

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...