## Recommended Posts

Has anyone calculated a parabola curve ? I assume I need to get the distance between the two points which make up the curve, or must I get the point value of two points ?

##### Share on other sites

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

##### Share on other sites

@srletak I searched for Parabola curve, but my results were empty ? What do you mean qLib ?

I don't want to create a Parabola curve from scratch I want to take a range of points and calculate the curve and the distance on the, in this case -Y ?

##### Share on other sites
• 1

##### Share on other sites

If I get the attribute value for the lowest point, and I square that value that will give me the point value for I assume the base of the parabola curve, then how do I get the radius of the curve ?

##### Share on other sites

Hi,

here are two possibilities (not the only ones) to calculate a parabola curve from a planar curve. The first method uses the relative ptnum and the second uses the distance of the point to zero.

parabola.hipnc

##### Share on other sites

@Aizatulin Your parabola curve is not a full curve ##### Share on other sites

The red shape is what I want to get both the height and the radius; I mentioned a Parabola curve as I was informed, as I sorta thought it would be kinda like a Parabola curve ?  ##### Share on other sites

Ok I'm not sure what you mean with radius.

Perhaps you can provide us with (your) definition of a parabola.

For me it is something that you map (float)values to squared values.

What is your goal? Are you trying to fit an existing curve with a parabola?

##### Share on other sites

The red curve circle or curve is what I'm trying to find, the radius in other words Probably not exactly a parabola curve but it's what the shape began anyhow ##### 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

##### Share on other sites

This is what I wanted Although how come the degree only effects the Y but not the X, unless it's due to this line ?

`points_subset = filter(lambda x: x.attribValue('id') == 1, points)`

And how would you flip / invert the curve ?

##### 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?).

##### Share on other sites

The documentation states for the polyfit function in numpy if y is 2-D then multiple fits are done both for the x and y; therefore why is the result a 1-D co-efficient ?

Invert the curve, if the curve is like a Parabola Curve, flip it; so it's the opposite ? ##### 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.

##### Share on other sites

There is no way to make the fits dependent on each other ?

How do you know if the x-value has no y-values based on the curve, if the id is only set to check for 1 ? It's possible a cubic will work over Quadratic ?

##### 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

##### Share on other sites

When changing the degree whether it's 3,4 etc; the point curve which are to the right of the curve, stay the same; they don't change, I want to change both ?

## Create an account

Register a new account