# Find curve parameters at local min and max, and at inflection points

I have a user defined curve. For fabrication purposes, I need to divide the curve at the inflection points (where the 2nd derivative = 0). There is need to specify a thickness at the local min and max points (where the 1st derivative = 0). I would like to do this all in Grasshopper with a clean flow of data, for purpose of later manipulations and fabrication. Currently, I am marking the points in Rhino, then referencing those points in GH.

Curve and points are internalized into the attached file.
internalized curve - to find inflection points and local min-max.gh (3.6 KB)

See image: this is a structural moment diagram, that it represents the thickness and how I hope to vary the thickness.

For your curiosity, this is what we are planning to install.

Hello,

Rhinocommon V6 has method to get the extremas of a NurbsCurve. If you cant script you can also make a simple hodograph. Just sample you curve and display m values in a xy plane, where x is t and y is m.interpolate the 2dpoints and intersect at m=0 and get the t value

hope this helps

1 Like

Hello,

I cannot script, so I tried make a hodograph, but I cant quite visualize your instructions. Is this what you mean by sampling my curve? I analyzed for the first derivative at 1000 points along the curve.

Hi,

sorry I currently have no access to rhino. I can post you both possibilities at the end of the week.

1 Like

TomTom,

Ok, I would really appreciate that.

Karl

If your curve does not have any kinks or rational weights, you can derive an analytical form for the hodograph without any need for sampling / interpolation:

(taken from https://pages.mtu.edu/~shene/COURSES/cs3621/NOTES/spline/B-spline/bspline-derv.html

Basic implementation in Rhinocommon / Python:

from Rhino.Geometry import NurbsCurve, Point3d

def get_hodograph(crv):
nc = crv.ToNurbsCurve()  # type: NurbsCurve
deg = nc.Degree
pts = []
for i in range(nc.Points.Count - 1):
k = deg * 1.0 / (nc.Knots[i + deg] - nc.Knots[i])
pt = Point3d(k * (nc.Points[i + 1].Location - nc.Points[i].Location))
pts.append(pt)

hodo_crv = NurbsCurve.CreateControlPointCurve(pts, deg - 1)

for i in range(nc.Knots.Count - 2):
hodo_crv.Knots[i] = nc.Knots[i + 1]

return hodo_crv


Intersect with XZ plane to find all “stationary points” where the tangent of the original curve is zero in Y direction.
hodograph.gh (11.3 KB)

1 Like

@qythium, I really like your approach. However I am not knowledgeable of scripting, so I cant really work with it well. For example, I also want to use this to split the curve at its inflection points.

Your script seems to work great, but it does not match with Rhino’s _curvature command. Do you know the reason for this, and which is more accurate?

Here is a grasshopper file with the curve and relevant points internalized.
internalized curve - to find inflection points and local min-max.gh (3.6 KB)

Here’s what I get from plugging your points into Grasshopper’s curve derivatives component:

Evidently the 1st derivative vectors are not horizontal at those points. Rhino’s _Curvature command marks out points where the curvature is at an extrema - i.e. \frac{d}{ds} ||\gamma''(s)|| =0 (where \gamma(s) is the curve’s arc-length parameterization)

It may be useful to keep in mind that you’re dealing with 3D space curves in arbitrary directions, where their derivatives are always vectors and dependent on the curve’s NURBS parameterization. Saying the first / second derivative = 0 doesn’t mean anything, unless you’re specific about what (scalar) value you’re differentiating, and along what parameter.

1 Like

@qythium, thanks for the explanation. So would you say that your Hodograph is more accurate in the 3D space than Rhino’s _Curvature command?

extrem.gh (11.6 KB)
Extremas_RhinocommonV6.gh (5.3 KB)

1 Like

Hi here it is: Although @qythium actually made it nicer.

1 Like

@TomTom, extremely helpful. Im starting to get a grasp of it now. I appreciate your definition as it also yields the inflection points for the curve.

Thank you.

I think there might be some confusion here - can you specify what you mean by “inflection points”? I’m assuming you’re looking at the curve as a sort of X-Y cartesian plot, and asking where \frac{d^2y}{dx^2}=0? This is not the same thing as @TomTom’s script, which plots out the curvature vs arc length. ( and is not technically a hodograph in the mathematical sense )

is it not? … oh okay, good to know. I’m not a mathematician, I took the term hodograph as a general term for plotting out (movement) relations in 2d space. By the way, its not the curvature, its the delta of curvature, which is equivalent to a differentiation of the curvature isn’t it? Or am I wrong here? Isn’t walking down the curve parameter kind of a velocity diagram?

Yes. I would like to find the points where the curvature flips from concave up to concave down. My understanding is that the 2nd derivative would be 0 at that point.

@karl.6180
Yep, so the thing is - when talking about Bézier/NURBS curves, the term “curvature” refers to the magnitude of 2nd derivative along the arc-length parameterization of the curve, which always points in the curve’s normal direction and is independent of the parameter t.
\kappa = ||\gamma''(s)|| =\frac{\|\gamma' \times \gamma''\|}{\|\gamma'\|^3}

This has more geometrical meaning, which is why most CAD programs use it instead of parameter-domain derivatives. (difference btw C1 vs. G1 continuity)

“concave up” and “concave down” make sense in a x-y graph where X is your parameter, but not so much here where the curve itself is your parameter - think of it as driving down a curved road at constant speed and measuring if you’re accelerating to the left or right.
e.g. the curve below has no inflection points where curvature=0, but changes “up/down concavity”

@karl.6180 @qythium
Is this the answer to Karl or to me?

I think you are wrong on this one, or I didn’t understand what you are saying:

k dependents on t, your formula, just uses the char “s” for “t”. The same goes for gamma. Sure first and second derivative of gamma are still dependent on t when evaluating it numerically; Because de Casteljau/de Boor require t, so does their derivatives, so does k.

What I did, I didn’t evaluate the curve itself but the “curvature curve”. By drawing the “hodograph” I found the parameter where the acceleration of this “curvature curve” is 0. At the “infliction points” the acceleration is 0 because its locally not increasing curvature nor decreasing curvature and it usually “flips” from positive to negative or the opposite. However I didn’t changed the parametric formula, I just evaluated the delta of curvature of t - curvature of t+smallStep (which is what derivation does in a non-mathematical way). So I derived k.

…which is the slope(m) of the curvature curve

It was in response to Karl , I must have clicked on the wrong “Reply” button and couldn’t edit it afterwards.

I didn’t realise the term ‘hodograph’ had a more general meaning (just looked it up), had only encountered it before in the context of Bezier/Nurbs curves, where I think it has the more specific meaning of the degree n-1 curve produced by the derivative in the t parameter domain ( see the link in my first post above)

Sorry, what I meant above was that κ is independent of the curve parameterization, because two geometrically identical curves can have different control point locations, degrees, weights, knot vectors, etc, which changes the parameter t but not s (the arc-length parameter, which is defined geometrically)

By convention I believe \kappa refers to the curvature itself, and in your hodograph you are representing the derivative of κ with respect to t, although at equally spaced intervals along the arc length ( which is unequally spaced in the t domain)

But of course in the context of the original question ,all this doesn’t really matter… And I think your method fits the intention well enough- I just wanted to be clear on the geometric meaning

2 Likes

…well my method isn’t perfect in any meaning. It works but I know its not the best way in solving this. However this whole NURBS topic is really hard to understand, and the moment I get the answer to one question 10 new more rise up. At least for me there is more confusion rather then understanding, and sometimes you find a solution to a problem but its much harder to prove or express it mathematically. Sounds easy to derive from k in respect to t, but doing it mathematically is quite challenging I believe. Not even sure if it works like this. Its just that anything related to math is super bad explained. Its like people writing math books don’t want non-math people to know what’s going on. … or maybe its just me … anyway I’ll going to enjoy my extended weekend now.

1 Like