Sweep1 along a polynomial curve mathematically defined

Hi everyone,
I’d need help to sweep a curve (generated by interpolating some points) along a binary. I’d need to define said binary through an expression and not draw it in Rhino. The expression of the binary is a fifth-degree polynomial and looks like: 1.22e-06x^5-9.42e04x^4+0.29x³-45x²+3.47e+03*x-1.07e+05.
The plot of the polynomial is the blue one in the figure:

I’d need to use the said curve for an extrusion/sweep in the range of 140÷160 along the x-direction.

I attach the code that I have written so far, but I only managed to extrude the curve along a vector. As you can see in the code all my attempts to sweep along a curve mathematically generated have failed miserably!

Does anybody have an idea?

Required files to run the code:
set1.csv (79 Bytes)
set2.csv (79 Bytes)
set3.csv (78 Bytes)
Sweep_polynomial_curve.gh (28.0 KB)


Are you sure your function is correct ?

In order to use Sweep2 you need to actually build the curve, that is construct some points using X and Y coordinates.

However the values are in the 10^13 range… (tried in mm and in m)

After double NaN and posInfinity checks use:

There is either a problem in units, or a problem with the formula.
But assuming x in in meters, the first term of the polynomial is about 10^(-6)(10²)^5 = 10^4 whereas the second term is 10^4(10²)^4 = 10^12.

I tried with 10^(-4) as the coefficient but I get almost a straight line.

1 Like

Hope dies last: finish(*) it: my nerves are a bit broken with that freaky eq.

Equation_ForFreaks_V1.gh (8.0 KB)

(*) or better not

PS: Some good old Gauss thing anyone?

1 Like

Thank you both @PeterFotiadis and @magicteddy for your help. x is in meters, indeed.

The problem may lie in the coordinate system. On the one hand, the curves I am using (those deriving from .csv files) are like “toy curves” placed near the origin of axes. On the other hand, the polynomial takes values from an interpolation in Matlab performed by using the real coordinates of the point cloud. So there’s no point in sweeping in the range 140÷160 in Gh. Thus, I made the sweep with a different range. Anyway, I don’t manage to get satisfactory results by using either a third-grade or fourth-grade polynomial, and I do not understand why. Results are good only with first-grande or second-grade polynomials.
I attach a csv file with the coefficients of the polynomials.
Pol_coeff.csv (307 Bytes)
There are also some attempts in the new Gh file uploaded.
Sweep_polynomial_curve_V2.gh (19.8 KB)
Here there is a plot with the polynomials I am using in Gh.

Moreover, I am also facing another issue. I need to sweep different curves along different binaries. Ex. the curve from set1.csv goes with polynomial 1 (a certain fourth-grade polynomial), the curve from set2.csv goes with polynomial 2 (another fourth-grade polynomial), and so on.
If the problem was in Matlab I would use something like a for-loop, but I have no clue how to do it here.

Just a moment: you have any MatLab code for that? If yes … post the code here (PS in this case why GH? )

That said I don’t have Pancake nor I have any idea what that thing is/does.

No Pancake here either so hard to be very helpful.
For a sweep to work properly, it’s best if the section and the curve intersect at one point. However I see here your Grade 4 curve starts on top.

So actually instead of removing the constant term, you should calculate it so it makes the rail match with the section curve.

Don’t know if there is a problem in the csv but there are lines with a single coordinate and this makes an overlapping section.

Finally, if you want to repeat your sweep operation on multiple couples of rails/sections, you’ll need data trees. Using Entwine here seems to do the job.

Sweep_polynomial_curve_V2_magicteddy.gh (24.9 KB)

1 Like

I wasn’t sure to be allowed to post the code here, that’s why I didn’t provide you with it earlier.

In the code, use xyz_coordinates_RIGHT.csv (198.2 KB) instead of

Here there is the code:


[xq_R,yq_R] = meshgrid(min(xyz_coord_RIGHT(:,1)):0.1:max(xyz_coord_RIGHT(:,1)),min(xyz_coord_RIGHT(:,2)):0.0005:max(xyz_coord_RIGHT(:,2)));
[Xq_R,Yq_R,vq_R] = griddata(xyz_coord_RIGHT(:,1),xyz_coord_RIGHT(:,2),xyz_coord_RIGHT(:,3),xq_R,yq_R);

pbaspect([10 1 10])

z_RIGHT_mean= mean(xyz_coord_RIGHT(:,1));
z_RIGHT_std= std(xyz_coord_RIGHT(:,1));

[f_RIGHT,xi] = ksdensity(xyz_coord_RIGHT(:,3));
hold on
h_RIGHT = histogram(xyz_coord_RIGHT(:,3),'BinWidth',0.01,'Normalization','pdf');
hold off

ypos_RIGHT= xyz_coord_RIGHT(:,2);
A_RIGHT= xyz_coord_RIGHT(ypos_RIGHT==65.9820000000000,:);
Atab_RIGHT = array2table(A_RIGHT);
Atab_RIGHT.Properties.VariableNames(1:3) = {'X', 'Y', 'Z'};
B_RIGHT= sortrows(A_RIGHT);
B_RIGHT= B_RIGHT(1:end-3, 1:3);
Zmin_RIGHT= min(B_RIGHT_Zcoord); %USELESS
Zmax_RIGHT= max(B_RIGHT_Zcoord); %USELESS
Xmin_RIGHT= min(B_RIGHT_Xcoord); %USELESS
Xmax_RIGHT= max(B_RIGHT_Xcoord); %USELESS

n= size(B_RIGHT,1);
start= 1;
for i=1:n-1
if (B_RIGHT(i+1,1)-B_RIGHT(i,1)) > 0.01
C_RIGHT(start,:)= B_RIGHT(i,:);
start= start+1;

x_grid_RIGHT = min(C_RIGHT(:,1)):0.5:max(C_RIGHT(:,1));
x_grid2_RIGHT = min(C_RIGHT(:,1)):0.1:max(C_RIGHT(:,1));

F_RIGHT = griddedInterpolant(C_RIGHT(:,1),C_RIGHT(:,3), 'spline');

plot(x_grid_RIGHT,V_RIGHT,'--bs'); %'--ro'
grid on
xlabel('X-longitudinal [m]')
ylabel('Z [m]')
title('Right side')

hold on
for pp=1:4
[P_RIGHT,S_RIGHT]= polyfit (x_grid_RIGHT(3:end-3),V_RIGHT(3:end-3),pp);
nr(pp,1)= S_RIGHT.normr;
V2_RIGHT= polyval(P_RIGHT,x_grid2_RIGHT(:));
hold on
legend('filtered PC points','grade 1', 'grade 2', 'grade 3', 'grade 4')

[P1_RIGHT,S1_RIGHT]= polyfit (x_grid_RIGHT(3:end-3),V_RIGHT(3:end-3),pp1);
[P2_RIGHT,S2_RIGHT]= polyfit (x_grid_RIGHT(3:end-3),V_RIGHT(3:end-3),pp2);
[P3_RIGHT,S3_RIGHT]= polyfit (x_grid_RIGHT(3:end-3),V_RIGHT(3:end-3),pp3);
[P4_RIGHT,S4_RIGHT]= polyfit (x_grid_RIGHT(3:end-3),V_RIGHT(3:end-3),pp4);

Thank you for your previous reply.