Grasshopper

algorithmic modeling for Rhino

Hi all I am trying to interpolate 2 planes.

I don't know why but my output A is Null even if my planes_interpolate function seems working good.

Here is my code:


private void RunScript(Plane myPlaneA, Plane myPlaneB, ref object A)
{

Plane pl = new Plane();
pl = planes_interpolate(myPlaneA, myPlaneB, 0.5);
Print(Convert.ToString(pl));

A = pl;

}

//
Plane planes_interpolate(Plane plA, Plane plB, Double d)
{
Plane pl = new Plane();
pl.Origin.Interpolate(plA.Origin, plB.Origin, d);
pl.XAxis = vectors_interpolate(plA.XAxis, plB.XAxis, d);
pl.YAxis = vectors_interpolate(plA.YAxis, plB.YAxis, d);
pl.ZAxis = vectors_interpolate(plA.ZAxis, plB.ZAxis, d);
return pl;
}

Vector3d vectors_interpolate (Vector3d vA, Vector3d vB, Double d)
{
Vector3d v = new Vector3d();
v.X = (vA.X + vB.X) * d;
v.Y = (vA.Y + vB.Y) * d;
v.Z = (vA.Z + vB.Z) * d;
return v;
}
//

 

thanks for your help.

Views: 1052

Attachments:

Replies to This Discussion

Hi raf,

 

sorry, I've had one whisky too many (Tantallan, good stuff, give it a go sometimes if you're into malt) and don't feel like backing up my claims tonight. What you've written is not an interpolation function, unless d equals exactly 0.5. It's also not a good idea to interpolate the z-axis, as it's constrained by the x- and y-axis directions. If the result of your planes_interpolate function returns an invalid plane, it might well be ignored by the output (hence the null). But I'm just lazily guessing here (see first sentence).

 

Here's how I'd write it:

 

Plane InterpolatePlanes(Plane A, Plane B, double d)

{

  Return new Plane(InterpolatePoints(A.Origin, B.Origin, d),

                           InterpolateVectors(A.XAxis, B.XAxis, d),

                           InterpolateVectors(A.YAxis, B.YAxis, d));

}

Point3d InterpolatePoints(Point3d A, Point3d B, double d)

{

  return A + d * (B - A);

}

Vector3d InterpolateVectors(Vector3d A, Vector3d B, double d)

{

  return A + d * (B - A);

}

 

This might still give problems if the InterpolateVectors method returns a zero-length vector. The plane orientation will be unspecified which will probably result in an invalid plane.

 

--

David Rutten

david@mcneel.com

Poprad, Slovakia

Hi David,

ah ah, cheers !

well you right "interpolate" (morph would be maybe more appropriate) z-axis is a non sense.

No doubt the way you wrote is cleaner and faster. Thank you.

But I am still trying to understand my mistake. Is it a syntax error ?

If I declare a new Plane(); I thought (according to RhinoCommon doc) that I could set the Xaxis vector of this plane using Plane.XAxis Property but this seems not a good way.

Which is the most weird for me to understand is that my function seems to return a plane. When I Print(Convert.ToString(pl)); I get all my plane information (like origin, axis, etc..), but at the same time when I output A = pl; A is null...

...

I understood that I should not use Properties for setting but prefer the Constructor.

 

raf

 

 

I suspect the problem is that when you set the plane axes yourself, they are neither unitized nor perpendicular to each other. They don't have to be unitized to make a valid plane, but they do have to be perpendicular.

 

Try running pl.IsValid and watch it return False.

 

And yes, I just checked, if you supply an invalid plane for a Script output, it get's ignored and you end up with a null (change the line end-points in the attached file).

 

--

David Rutten

david@mcneel.com

Poprad, Slovakia

Attachments:

RSS

About

Translate

Search

Photos

  • Add Photos
  • View All

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service