# Get curve from equation and vice versa

I know this question has been asked several times in different ways. But none of the suggested solutions works for me.

What I want to do:
I want to write a function (mathematical, Python or any other programming language) that describes the shape of a curve in Rhino. In a second step it would also be nice to read out the equation from a given curve, but that is optional.

What does not help me:
Every suggestion about creating a bunch of points and then create an InterpCrv does not work for me. I need that curve to have exactly the shape given by my function(s) and not only at the given points.

How can this be done?

Ray

1 Like

Something akin to y = x^2 or y = \sqrt{x} ?

Isn’t each curve defined by some sort of points, not necessarily interpolated through them, but control points and other data (e.g. tangents, weights, etc.)?

Hi @RayL
I have no idea if the V5 version of Jess Maertterer‘s Math plugin will run in V7, but it’s worth a shot - or dig into grasshopper, which is probably the better/more up-to-date approach.
HTH, Jakob

Something akin to y=x2 or y=√x ?

Exactly!

Isn’t each curve defined by some sort of points, not necessarily interpolated through them, but control points and other data (e.g. tangents, weights, etc.)?

If you talk about splines, I think this could be true. I don’t know the internals of Rhino, but I would be very surprised if internally no formulas are used and just points are used for each shape. I am not too deep into the mathematics but I think there are some kind of functions / shapes you cannot transform to a number of control points. Think of sin(x) this would take an infinite amount of control points.

I have no idea if the V5 version of Jess Maertterer‘s Math plugin will run in V7, but it’s worth a shot - or dig into grasshopper, which is probably the better/more up-to-date approach.
HTH, Jakob

Thanks Jakob! I already looked into that, but sadly it says in the documentation:

The Math Plugin calculates the sampling points based on the input and draws an interpolated curve or surface with degree 3 through these points.

edit: All Grasshopper “solutions” I found also worked with IntercpCrv which again does not help me.

OK, but you understand that the x and y in y=x^2 and y=\sqrt{x} represent two-dimensional coordinates that could also be seen as points (x, y), right? The resulting curves are thus kinda interpolated though them, no?

This how n.u.r.b.s. curves AKA splines work! There are control points, tangency and curvature vectors, and weights that define the curve.

Than there’s the Bezier curve, which works a little simpler.

You can visit wikipedia if you’re interested in the formulas.

No, the controls points are usually not points on the curve, but rather points forming some sort of control cage, I guess. For y = \sin(x), the same counts as for y=x^2. x and y describe a two-dimensional point! It takes an infinite amount of points for an infinite interval, but for ten x values you get ten y values, nothing more nothing less!

I believe that all formulas basically work like this: At the end, they spit out a set of coordinates of points forming/drawing the curve in question. Curves or lines are really probably illusions. They are really connected points and their smoothness is proportional to the amount of points?

Thanks diff-arch for the reply. I really appreciate you taking your time to help me out!

I understand that I can interpret y=x^{2} as x and y coordinates. Sure, for 10 x values I get 10 y values and respectively 10 full point coordinates. My problem is that I don’t just need a curve that goes through all of these points but also fulfils the example function y=x^{2} in between these points. When I use IntercpCrv the curve between my 10 points is not where my function says it should be.

As far as I understand controls points for splines/NURBS help to create a mathematical formulation for a continuous curve/surface. If I could create the “correct” control points for any mathematical fomula I would be happy to solve my problem by first creating my mathematical fomula, then creating the derived control points for a spline and lastly creating the curve from the spline control points. Is there a way to get spline control points for any (continuous) mathematical formula?

I don’t understand that. A spline is a continuous function I could get a y value for each x value I give to it. A spline does not get “more continuous” (start hating me mathematicians ) if you give it more control points. (Sure for rendering/display you would again create sample points from that spline.)

You’re welcome. Although I’m not sure if I’m really helping you.

I understand. What you could do is simply dial up the number of samples, meaning the more points you have, the more precision you get. Other than that I really don’t know.

Sorry, I don’t know. What I can show you is how to set the n.ur.b.s. curve control points (randomly) and to change an existing curve:

Maybe, I was wrong about that. Yes, I was talking about rendering the curves. I think there is no such thing as infinite resolution.

Thanks again!

I know! But that doesn’t help me

You’re kind of right. The fomula y=x^2 has what you meant with infinite resolution. The more accurate one value gets the more accurate the other gets too. You could store these function accurately in a vector/list like (1,0,0) standing for y=1*x^2+0*x^1+0x^0. But even though some floating point numbers can be accurately stored with the standards (IEEE-754), it is not true for most of them. So at some point your right, they are just nearly correct values, atleast when you store them in a computer memory.

Aren’t those 2 sentences the same thing?
You are asking for something that compile a formula based on a curve, or better, a set of points + degree (and maybe weights?).

I think, then, you are interested also in something that, from a given formula, creates a “perfect” curve without using interpolation… ?

Now i’m “citing” the usual and trivial thing about nurbs, just to remember to myself and make things less abstract.

For the simplest case where:

• n = number of points
• d = degree = n - 1
• weights = 1
• non periodic

any point in the nurbs curve is the result of linear interpolations (looped d times) through points.
Everything become much more complex if any of the 4 “rules” is skipped.

degree3.gh (16.9 KB)
The code inside speak for itself better than 1000 words.

So, maybe having to deal with just linear interpolations can be a logic to start with.

Another example is: any 3 points, degree 2 , open curve, with weights=1 is a deformed parabola.

I think asking for a “y=x formula” is going to be a mess.
Usually “y=x formulas” don’t go back in x axis. For any x value there is a single point.
I’m imagining ultra-complex formulas even for simple degree 2 nurbs.

The cool part about nurbs is exactly this: we don’t have to deal with crazy complex formulas. (i think)

Mainly out of curiosity, but also hoping it helps, i want to ask: why?
Why you need that? How will the output be used, then?

That said, I’m absolutely no expert in nurbs, everything i say can be wrong, i’m just making guesses and sort of reverse-engineering by playing on rhino.
A proper opinion from a nurbs expert would be best.

Essential Mathematics for Computational Design by Rajaa Issa is an introduction to the math including NURBS used by Rhino to represent curves and surfaces. It can be downloaded for free at http://blog.rhino3d.com/2019/06/essential-mathematics-4th-edition.html

NURBS are covered comprehensively in The NURBS Book by Piegel and Tiller. It may be a bit in-depth for those with casual questions about NURBS but is an excellent source for anyone wanting or needed more details.

Only certain curves can be represented exactly by a NURBS curve. “Conic curves” including circles and ellipses can be represented exactly. Determining the NURBS version of curves which can be exactly represented by NURBS frequently requires more than simple interpolation or similar. Many of the curves which can be represented as NURBS have weights with values other than 1; ie the NURBS versions are rational rather than non-rational. The best approach to determining the NURBS version of a curve which can be represented exactly is to look up the general form of the representation (if available).

Types of curves which cannot be represented exactly by NURBS include triginometric curves such as sine curves and tangent curves and exponential curves.

This limitation of what curves can be represented exactly by NURBS is a function of how the math of NURBS works, and is true of any software which uses NURBS.

However virtually any curve can be represented with any desired level of accuracy by NURBS curves if a sufficient number of knots and control points are used. Pick the maximum deviation allowed between the exact curve and the NURBS representation and with enough knots and control points there will be a NURBS curve which meets the accuracy criteria.

@RayL This is not possible in general using NURBS, only for special types of curves…

1 Like

The mathematical formulas for NURBS are readily available. The equations use the control point coordinates, the weights for each control point and the parameter values at the knots (knot vector) as coefficients. The equations can be written in several different forms with the choice of form usually depended on the use of the equation. The shape of the curve does not depend on the particular form.

Thank you! This was what I believed!

Also thanks to all for the other answers.

I just read about the step-File standard “ISO 10303-21” (but don’t have it here to look into). And it seems that they also don’t have formulas to specify curves or surfaces. Can anyone confirm that? Is the only way to get a math formulated curve into a step file by creating a near-perfect spline using a lot of control points?

Try with Geogebra i think it is possible

STEP includes many types of geometrical entities, not just NURBS, and for each entity the associated values and formulas are defined in a reference. A STEP file only contains information about the types of entities used in that particular file and the values (coefficients, etc) for those entities. It does not include text with formulas.

The only type of entities which Rhino exports in STEP files are those entities which exist in Rhino.

I have to export my curves/surfaces via STEP.

I know about these standard objects like a circle, an ellipse and so on. But let’s say for the examples above like y=x^2 and y=\sqrt{x}. One could create a “geometrical entity” in a file that uses “associated values and formulas defined in a reference” like it is possible for other geometries in STEP that would represent the exact shape given in these functions (see my polynomial example above).

I just want to know if the only way to bring in a mathematical formula like these above into a Rhino or STEP-file is by transforming these to a near-perfect spline and then storing the spline/its coordinates?

If there is no standard CAD format that has a possibility to store these formulas exactly, I would understand why such a feature never was implemented in Rhino too.

You need to obtain a copy of the STEP documentation to what entities are defined, and the form that those entities are defined in.

This question has already been discussed.

What types of forumlas? Simple algebraic formulas? Formulas using trancendental functions? Any transcendental function?

Many different ways of representing geometry using numbers have been investigated over at least a century… No single system can exactly represent all possible geometry. NURBS have been found to be useful for the types of geometry used in many fields including mechanical systems, automobiles, aircraft, boats, many consumer products, etc. Ocassionally someone will claim to have discovered a universal system. Inevitably limitations of their system are found and they in fact have limiations.

Discourse does not want me to respond anymore:

### Encourage everyone to get involved in the conversation

You’ve replied 3 times to @RayL in this particular topic!

A great discussion includes many voices and perspectives. Can you get anybody else involved?

And don’t forget, if you’d like to continue your conversation with this particular user at length outside of public view, send them a personal message.

NURBS technology has been implemented since able to define a huge amount of curves trough piecewise polynomial description. All.curves in any cad software are parametric to keep simple and limit the amount of code to write to implement all relative functions (intersection, query etc). If you want to define your own parametric curve for sure there is a NURBS representation of it (with low error) but you need to have knowledge on how to compute control points,weights and any other relative Param, in alternative interpolation will produce for you a NURBS curve with small knowledge of its internal Params.