Grasshopper

algorithmic modeling for Rhino

Hello,

I know it's a really silly question, but...how can I translate the crv cp component (closest point on a curve) in C#? I found the ClosestPoint metod but it returns me doubles, I need the point exactly as the component. 

I'm trying to code it because I want to keep the canvas as clean as possible.

I tried also the ClosestPoints method but I didn't understand yet the "IEnumerable" thing and right now I have no time to understand it.

 

Thank you,

bye

Views: 2658

Replies to This Discussion

Hi Andrea,

 

IEnumerable is an interface (all interfaces in the .NET framework start with upper case I). An interface is basically an agreement that a certain class makes. When a class implements IEnumerable it must provide certain functions. Practically all classes in .NET that represent some sort of data list (Array, ArrayList, List(Of T), etc. etc.) implement IEnumerable which means you can use a For...Each loop for iterate over all of them.

 

The difference between classes and interfaces is very important. If you don't understand it, you'll run into the same problems over and over again.

 

The ClosestPoint method returns curve parameters. If you want the coordinate at that specific curve parameter, you need to use Curve.PointAt()

 

--

David Rutten

david@mcneel.com

Poprad, Slovakia

Thank you David, for the explantion.

Yes I know I have to understand it, but at the moment I can't even find time to sleep...

 

Curve parameters! It was so obvious! I will try it right now.

thank you again, 

bye

 

Hi David, i tried the ClosestPoint output as the parameter of a curve to get the point. However ClosestPoint returns a boolean (see below) not a double as Andrea and yourself suggest.

"Finds parameter of the point on a curve that is closest to testPoint. If the maximumDistance parameter is > 0, then only points whose distance to the given point is <= maximumDistance will be returned. Using a positive value of maximumDistance can substantially speed up the search."

Syntax

C#
public bool ClosestPoint(Point3d testPoint, out double t )
Visual Basic
Public Function ClosestPoint ( _ testPoint As Point3d, _ <OutAttribute> ByRef t As Double _ ) As Boolean

Parameters

testPoint
Type: Rhino.Geometry.Point3d
Point to search from.
t
Type: System.Double
Parameter of local closest point.

Return Value

true on success, false on failure.


(http://4.rhino3d.com/5/rhinocommon/)

The description suggests that it will return the closest curve parameter yet it actually returns a bool. I have no idea what "true on success, false on failure." means in relation to the curve and the point. Am i using the wrong closest point method? and if so where can i find the correct one? Any help would be much appreciated. (i am using c#)


Thanks

If the ClosestPoint operation fails, it returns False. If it succeeds it returns True. The actual curve parameter is written to the t argument. Whenever a function argument uses the ref or out qualifier, it means that a value is returned there.

--

David Rutten

david@mcneel.com

Tirol, Austria

RSS

About

Translate

Search

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service