Calculating value between points

Hello,

I’m very new to grasshopper so I’m still not completely comfortable with the paradyme. Please excuse stupid questions. I am playing around with 3d print slicing.

In gcode produced by 3d printing slicers, the E value is a function of the XYZ. We have to tell the printer how much goo to extrude between the two points.

G1 X34.726 Y33.117 E0.06435
G1 X35.29 Y32.806 E0.09648
G1 X35.889 Y32.568 E0.12864
G1 X36.513 Y32.405 E0.16082
G1 X37.462 Y32.3 E0.20845
G1 X86.793 Y32.3 E2.66958
G1 X87.565 Y32.311 E2.7081
G1 X88.208 Y32.36 E2.74028

I am struggling to work out how I can acheive the same thing in grasshopper.

G1 F1200 X25 Y0 Z0 E1
G1 F1200 X24.950668 Y1.569763 Z0 E1
G1 F1200 X24.802868 Y3.133331 Z0 E1
G1 F1200 X24.557181 Y4.684533 Z0 E1
G1 F1200 X24.214579 Y6.217247 Z0 E1
G1 F1200 X23.776413 Y7.725425 Z0 E1
G1 F1200 X23.244413 Y9.203113 Z0 E1
G1 F1200 X22.620677 Y10.644481 Z0 E1

I have

Cylinder → Contours → Divide Curve → Flatten Tree → Point deconstruct → concatenate.

If I were doing this in Python I would iterate over the output of Flatten tree, working out the distances between each XYZ and writing E as a function of that distance.

Please could I have some pointers of example of how to do this kind of list iteration or perhaps explain a nice, more grasshoppery way of calculating something from my list of XYZs.

Ta,

Andrew
unnamed.gh (14.9 KB)

I’m not sure about gcode but the purple group calculates distance between successive points in a list. Avoid flatten to treat each branch as a separate list of points. They all have the same distance value.

distance_2023Jun12a
distance_2023Jun12a.gh (18.5 KB)

For making more complex strings, the Format component will be easier to work with that Concatenate. But that’s not really what you were asking.

Do I understand that you are asking how to compute the E values from the point coordinates? If so, that’s the equation you need to encode?

P.S. My previous post assumed straight line distances between points and no connection between contours. If you want the curve length between points, that’s a different method and result?

If you follow the single polyline between all points, every 100th point (each time around), there is a longer segment connecting the contours: 1.625726 instead of 1.570538 for all the other segments.

98. 1.570538
99. 1.625726
100. 1.570538