# How to create a curve with some points and tangent values on the points?

Dear All.

I’m a beginner for developing Rhino-plugin with c#.

I’m developing a Rhino-plugin to import my own formatted script file that consists of some commands (curve, surface, etc.).
I tried to create a curve with some points and tangent values on some points.
In example, there are three points (15, 55, 0), (30, 25, 0), (55, 15, 0) and a tangent value(-45 degrees) at start point(15, 55, 0).
In this case, I wonder how I can create a curve using these values.

I’ve already tried to find some functions of Curve and NurbsCurve class, but I can’t.
So, I need some help to solve this problem.
I hope to know some solution for this problem from you.

What function can I use? How can I make a curve using these criteria.
Thank you all.

Try the Curve.CreateInterpolatedCurve method.

One of the options has “startTangent” and “endTangent” vectors.

I’m trying to solve my problem using the Curve.CreateInterpolatedCurve method as your mention.
But I can’t do it yet.

My goal is like following image. (I hope that you can understand this image.)
As following sample(image), I have just one tangent vector on start point without a tangent vector on end point.
In order to use Curve.CreateInterpolatedCurve method, should I calculate a tangent vector on end point?

Otherwise, is there a way to do following step.

1. Creating curve by using the NurbsCurve.Create() method with 3 points.
2. Changing a tangent vector on a specific point.

I want to get new hints, tips or solutions.
I’ll say again, thank you all.

I think you can use Vector3d.Unset for the tangent on the end point - this way only the tangent on the start will be used.

Although there are other questions still, I’ve got the idea from you.
Thank you so much.

I wanted to follow up on this question since it was not fully answered and I am running into a similar situation. I’d like to define a set of points to generate a curve. I’m able to define the tangents at the ends of the curve, but I’m struggling to find a way to define a tangent constraint at any interior point. Is this possible through the SDK? It doesn’t look like the curve class exposes any way to add interior constraints? – If tangency isn’t exposed, is there any way to directly manipulate the control points that are generated by calling the CreateInterpolatedCurve method?

Thanks!

I think you’d have to code your own interpolation routine for that.

Is there any way to at least manipulate the control points through rhinocommon? This seems like a major drawback of generating curves that aren’t able to manipulated through the API. I’ve been trying to make updates to controls points in NurbsCurve.Points, but nothing seems to be happening after the assignment of a new location to specific control point.

curve = Rhino.Geometry.Curve.CreateInterpolatedCurve(curvePoints, 3, 0, Vector3d(-1,0,0), Vector3d(0,-1,0))
curve.Points[1].Location[0] = 0

but this assignment doesn’t stick or change the curve.

It seems you have updated the curve, but not replaced the old curve with the new curve. Rhino works basically as follows: 1. get an object reference 2. get the geometry associated with the object reference 3. modify the geometry 4. replace the object reference with the new geometry It seems that you are not performing step 4.

Can you provide an example of what you mean here? I haven’t called Objects.AddCurve(curve) yet, so I’m not sure why I would have to update the object reference yet if I’m just editing one of the internal class parameters. In my example from the last post, I would have called Objects.AddCurve(curve) after the location assignment, and then redraw() after that. What step satisfies your description of “step 4”?

Oops sorry, I don’t know what I was thinking. The origin of the problem is completely different and quite subtle. It has to do with the difference between value types (struct) and reference types (class).

Most variables in RhinoCommon are reference types, for example `Curve` is a class. A variable of type `ControlPoint`, however, is a value type. That means that when you get a `ControlPoint` from the list of control points, that you get a copy and not a reference.

Therefore, assigning a new value to a member of the struct like you do in the code above will not change the `ControlPoint` in the list of points of the curve, only the copy you obtain. You must re-assign the changed `ControlPoint` to the curve’s control point list like so:

``````// create cp as a copy of (and not a reference to) curve.Points[1]
cp = curve.Points[1];

// assign a new value to member X
cp.X = 0;

// assign the changed control point to curve.Points[1] - this will change the curve
curve.Points[1] = cp;
``````

Ah yes. This makes sense, and works. Thanks for the help.