Grasshopper

algorithmic modeling for Rhino

Hi All,

I'm trying to figure out how does the PerpFrame component work.. It essentially creates planes along the curve that do not twist (If you simply create a plane using the curve tangent, it flips over several times..). I have emptied my bag of tricks, but have not been able to achieve it through code.. I need to use it within some components of my own, so it's essential that I do it with code, not by using the GH component.

I tried looking up the PerpFrame component in Reflector, but it doesn't show up there either. I noticed that sweep needs to do the same thing in order to not let the profile flip around the curve, so there obviously is a known trick to get this to work.. Would greatly appreciate any help.

Many Thanks!

Views: 1154

Replies to This Discussion

The key to getting this to work lies with cross products, which will allow you to generate the perpendicular vectors that you need.

1) Determine a static vector that you will be using. Personally I like using something like the Z vector, but technically you can use any vector you want. This vector will actually determine the static rotatation of all the planes, so you can control that here if you like. One important thing that I've noticed is that the closer the vector is to the plane of the curve or if its too similar to one of the tangent vectors, the more likely you'll have "flipping"

2) Take the cross product between the tangent and the static vector. This will be your first perpendicular vector, which you can use for the X component of the plane.

3) Take the cross product between the tangent and the result of the previous cross product. Use this result as the Y component of the plane. All three components (X, Y, and Z (which is the tangent vector)) are all perpendicular to each other now.

After you've done that you should have planes that decrease twisting. If your curve is not planar, then there will always be some twisting in the frames, but it will be minimal enough to use them effectively.

There also may be "flipping" within the frames, which means one (or both) of two things. First, you could have planes that have reversed their vectors, so the X vector is properly oriented, but pointing down when it should be pointing up. Second, the X and Y vectors could have potentially swapped, so that Y "should" be X and X "should" be Y. In order to check these things, you'll need to do a few tests. The first one is find out whether the vector (X or Y) of the plane your testing is pointing in the opposite direction of previous vector. The second test is to find out whether the vector (X or Y) of the plane your testing is perpendicular to the previous vector. In both cases, an angle test between the two vectors will be able to tell you what you need to know, but you will likely NEVER get exactly 180 for an opposite test or 90 for a perpendicular test. That means that you have to choose a range with which to determine that a given vector is opposite or perpendicular.

You should start testing the X vector to see if anything is wrong. If you find that the X vector is fine, then just move on because Rhino will only allow you to create right handed planes, and the Z vector (the tangent) will always be the same.

I don't believe that there's a native function within the old dotNET SDK for calculating angles, so use the example at the link below. It basically takes the arcCosine of the Dot Product of the two vectors your testing to return the angle in Radians. I'm not sure if this function is included in RhinoCommon or not....

http://wiki.mcneel.com/developer/sdksamples/anglebetweenvectors
Hey thanks Damien! That is a very detailed explanation.. I'm guessing you've also had to deal with this issue for Rhino Hair?

I did try using the comparing angles to a static vector, but I wasn't doing it right. With planar curves, I've noticed that the planes always flip when the tangent is at 45,135,225 and 315 degrees from X-axis.. which is pretty easy to deal with, but I couldn't find any such pattern with 3d curves -- that's when things start getting really really wacky.

I'll try this method and tell you how it goes. I'm still wondering why the PerpFrame didn't appear on Reflector though..
perFrame is part of the NurbsCurve class

NurbsCurve myCurve;

Plane[] perpPlane = myCurve.GetPerpendicularFrames(5);
also if it helps here is a def that i made as a workaround for pipeSweep which uses perpFrame , back before it was add in to .7
Attachments:
Hey Robert, thanks a lot for that tip!

Unfortunately, I was in need of that function with the old .NET SDK as I was compiling some custom components, and therefore couldn't use the functions available in the new RhinoCommon SDK.

The reason being that I still think the 0.7xx series has several bugs that remain to be ironed out before it is suitable for mass consumption -- especially a lot of stuff missing from the SDK, and GH also not behaving very predictively in certain cases.

But now I'm in a state where the new SDK has as much new on offer as the last one was missing, but the last one still offers some stuff that's not been ported to the new one yet -- making my choice much harder. I have finally ended up coding the 'perpendicular frame' function myself for the old SDK. The outcome is not as pretty as the native function ofcourse, but it's getting the job done for the moment.

Thanks again.

RSS

About

Translate

Search

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service