Set point on curve

python

(Samuel N Sweeney) #1

Hi Guys,

Simple question I am sure. I want to pick a point on a curve and then make that point on the curve and use CurveTangent to find the tangent at that point.

In grasshopper i would just use a evaluate length on the curve and use a slider to set the length anywhere between 0 and 1, this would then give me the tangent at that result.

What is the best way to say pick a random point on that curve at parameter 0.4? Upon looking around I thought curve domain and evaluate curve may work?

I assume below would find the domain of the full curve and then we are saying divide that by 2?

import rhinoscriptsyntax as rs
obj = rs.GetObject(“Select a curve”)
if rs.IsCurve(obj):
domain = rs.CurveDomain(obj)
t = domain[1]/2.0
point = rs.EvaluateCurve(obj, t)
rs.AddPoint( point )

Thanks, Sam


#2

There is a PointAtNormalizedLength method, I think this is what you are looking for.


(Michael Pryor) #3

In grasshopper i would just use a evaluate length on the curve and use a slider to set the length anywhere between 0 and 1, this would then give me the tangent at that result.

What is the best way to say pick a random point on that curve at parameter 0.4

Keep in mind evaluating length and evaluating parameter are two completely different things. Make sure you know that you want normalized length or a parameter.


(Samuel N Sweeney) #4

Thankyou for that- very interesting!

So I take it the domain is still related to the length- ie. if I wanted the mid point of the curve length the domain divided by two?


(Michael Pryor) #5

The domain has nothing to do with length. Domain is related to curve parameter and knot vectors. If you wanted mid point of the curve length you would do .5 normalized length.


(Samuel N Sweeney) #6

Ok excellent- what would the best syntax to do these be?

Thankyou, Sam


(Samuel N Sweeney) #7

I assume perhaps divide curvelength?


(Graham) #8

Hi Sam,
This seems to work, hacked together from here:

import rhinoscriptsyntax as rs
import Rhino

go = Rhino.Input.Custom.GetObject()
go.SetCommandPrompt("Select curve")
go.GeometryFilter = Rhino.DocObjects.ObjectType.Curve
go.Get()
pt = go.Object(0).Curve().PointAtNormalizedLength(0.4)
rs.AddPoint(pt)

(Samuel N Sweeney) #9

Thanks Michael,

I am keen to just stick with the rhino script syntax.

Lets say I want to find the point at say 60% along the curve, I assume this would be the normalized length of 0.6, what would the syntax be for that?

Sam


(Michael Pryor) #10

.PointAtNormalizedLength(0.6);
as was mentioned here a few times.


(Samuel N Sweeney) #11

Hi Michael.

Sorry to be so hard with this- in very much a novice.

I just can’t seem to find that in the syntax list- or am I going crazy?

https://developer.rhino3d.com/api/RhinoScriptSyntax


(Michael Pryor) #12

It is part of Rhinocommon as far as I know. I don’t use RhinoScript.


(Graham) #13

Hello,
Why do you not want to use the import Rhino. sample I posted above ?
Cheers
Graham


(Samuel N Sweeney) #14

Hi graham. This might be moving away from the question- but I guess as I thought it was best to not use multiple syntax- so I just focussed on rhinosyntax- or is this the writ way of thinking about it?

Would love to know what you think!

Sam


(Graham) #15

Hi
I think it is possible with rs but it becomes messier. The Rhinocommon method is clearly designed to do exactly what you want so I would go for that one…