CinnamonMetal Posted April 14, 2019 Share Posted April 14, 2019 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 ? Quote Link to comment Share on other sites More sharing options...
Librarian Posted April 15, 2019 Share Posted April 15, 2019 (edited) 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 April 15, 2019 by srletak Quote Link to comment Share on other sites More sharing options...
Librarian Posted April 15, 2019 Share Posted April 15, 2019 Or try to download qLib. I think they have a function ( otl. ) Quote Link to comment Share on other sites More sharing options...
CinnamonMetal Posted April 15, 2019 Author Share Posted April 15, 2019 @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 ? Quote Link to comment Share on other sites More sharing options...
Librarian Posted April 15, 2019 Share Posted April 15, 2019 @CinnamonMetal github.com/qLab/qLib 1 Quote Link to comment Share on other sites More sharing options...
CinnamonMetal Posted April 15, 2019 Author Share Posted April 15, 2019 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 ? Quote Link to comment Share on other sites More sharing options...
Aizatulin Posted April 15, 2019 Share Posted April 15, 2019 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 Quote Link to comment Share on other sites More sharing options...
CinnamonMetal Posted April 15, 2019 Author Share Posted April 15, 2019 @Aizatulin Your parabola curve is not a full curve Quote Link to comment Share on other sites More sharing options...
CinnamonMetal Posted April 16, 2019 Author Share Posted April 16, 2019 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 ? Quote Link to comment Share on other sites More sharing options...
Aizatulin Posted April 16, 2019 Share Posted April 16, 2019 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? Quote Link to comment Share on other sites More sharing options...
CinnamonMetal Posted April 16, 2019 Author Share Posted April 16, 2019 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 Quote Link to comment Share on other sites More sharing options...
Aizatulin Posted April 16, 2019 Share Posted April 16, 2019 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 Quote Link to comment Share on other sites More sharing options...
CinnamonMetal Posted April 17, 2019 Author Share Posted April 17, 2019 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 ? Quote Link to comment Share on other sites More sharing options...
Aizatulin Posted April 17, 2019 Share Posted April 17, 2019 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?). Quote Link to comment Share on other sites More sharing options...
CinnamonMetal Posted April 17, 2019 Author Share Posted April 17, 2019 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 ? Quote Link to comment Share on other sites More sharing options...
Aizatulin Posted April 17, 2019 Share Posted April 17, 2019 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. Quote Link to comment Share on other sites More sharing options...
CinnamonMetal Posted April 17, 2019 Author Share Posted April 17, 2019 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 ? Quote Link to comment Share on other sites More sharing options...
Aizatulin Posted April 17, 2019 Share Posted April 17, 2019 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 Quote Link to comment Share on other sites More sharing options...
CinnamonMetal Posted April 17, 2019 Author Share Posted April 17, 2019 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 ? Quote Link to comment Share on other sites More sharing options...
Aizatulin Posted April 17, 2019 Share Posted April 17, 2019 the fit is already good, so raising the degree will only have little effect. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.