Jump to content

Calculator a Parabola Curve


CinnamonMetal

Recommended Posts

search please 

just feed line with alot points :)

// Convert the umap range from 0-1 to 0-1-0
float curveToHalf(
        float value;
        ) {

        return clamp(value, 0, 0.5) * clamp(fit(value, 0, 1, 1, 0) , 0, 0.5) * 4;
}
// Complement function
float complement(
        float value;
        ) {

        return 1 + (value * -1);
}
// Main interpolation function
float interpolate_curve(
        float value;
        string sign;
        ) {

        float pi_half = 1.57079632679;

        value = cos(value * pi_half);

        if ( sign == "-" )
                return 1 + (value * -1);
        else
                return value;

}
// Get user parameters from the UI
string  sign            = ch("sign");
int             complement      = int(ch("complement"));
int             curve_half      = int(ch("curve_half"));

// Create our classic umap attribute ranging over the points from 0-1
float   umap = float(@ptnum) / (npoints(@OpInput1) - 1);

// Convert the umap range
if ( curve_half == 1)
        umap = curveToHalf(umap);

// Do the complement for the umap
if ( complement == 1)
        umap = complement(umap);

// Interpolate curve based on the parameters
@P.y = interpolate_curve(umap, sign);

 

Edited by srletak
Link to comment
Share on other sites

Hi,

you can use (for example) python -> numpy -> polyfit to perform a least square fit. The result will be a parameter set for a polynomial function. For degree = 2 it will be a parabola. This method will work, if you have a defined (sub)set of points which are in the x,y plane.  But the parabola is not a closed curve, since it is a function from x to y.

fit_curve.hipnc

Link to comment
Share on other sites

Afaik this type of fitting only works for (1D) polynomial functions [like y = a*x^2 + b*x + c [which is degree 2] -> [a,b,c] will be calculated]. The "id" attribute is if you want to select a subset of points (not all points), so you can filter the "id" points. You cannot generally invert a function (or what do you mean with flip/invert?).  

Link to comment
Share on other sites

I haven't tried multiple y, but it sounds, that the fits are indepentent from each other. So if y has k components, it will perform k different fits for the same x, where each fit represents a function 1D -> 1D.

You can invert a function if there is no y-value with multiple x values. For examples a parabola y=x^2 for y=1 there are two x-values with y=1: x=1 and x=-1, so you can't invert this function. 

Link to comment
Share on other sites

The id is used to select the points, which are used for the fit. If you want to use all points just set i@id = 1 in a wrangle. You can use cubic or higher degrees aswell just change degree in python node to 3,4,... .

Every x-value has y-value in points set, since the values are extracted from the curve @P = (P.x, P.y, P.z), where P.x ~ x, P.y ~ y and P.z = 0

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...