/************************************************************************************/ /* Lathe city */ /* calculating the slicing of spherical (ball) shapes for manual lathe operations */ /* (c) U. Burghaus, 2010 */ /* shown here is a program skelleton and not a complete and user friedly code */ /* add graphics and data input/output procedures depending on the "C" compiler used */ /* or get the windows exe version from our on-line shop */ /**Start*****************************************************************************/ /* Header for graphic part of the program */ ... /* Header for numeric part of the program */ ... // stock parameters float StockLength = 3.0; float StockDiameter = 1.0; // circle parameters float x0 = 1.0; float y0 = 3.0; float r=0.5; // process parameters float SliceThickness=0.02; float StopAt=0.6; // stop position for cuts, last slice // the numbers given here are just an example, the program works for various geometries // program parameters float alfa; // parameter for the circle float AlfaStart; // starting angle / starting (first) slice position float alfa_sl; // current angle corresponding to the current slice float alfa_sl_end; // for inside geometries float xcor; // current positing of the slice float CircleX[400]; // for plotting the circle float CircleY[400]; float SlicePlot[100]; // plotting the slices float SlicePlotEnd[100];// for inside geometries float SlicePlotStart[100];// for inside geometries float SliceLength[100]; // calculated slice length for cuts with the lathe int scaling; // auto scaling on/off for graphics int NumberOfSlices; // storr last slice table**************************************************** int CVICALLBACK save (...) { int j,i; FILE *fd; char buffer[150]; for (j=1;j= StockLength) { // circle overlaps with the edge of stock piece while ((xcor > StopAt) & (((SliceThickness*i+(x0-StockDiameter))/r) < 1)) { // calculate angle for slice if (x0==StockDiameter) alfa_sl=asin(SliceThickness*i/r); // quarter circle geometry if (x0>StockDiameter) alfa_sl=asin( (SliceThickness*i+(x0-StockDiameter))/r ); // circle segment // calculate position on circle for the slice SlicePlot[i]=y0+r*sin(AlfaStart-alfa_sl); SliceLength[i]=StockLength-SlicePlot[i]; // screen plot PlotRectangle (... StockDiameter-SliceThickness*i, StockLength, // upper corner StockDiameter-SliceThickness*(i+1), SlicePlot[i], // lower corner ...); // go to next slice position xcor = xcor-SliceThickness; i++; }// end of while loop };// end of if statement // this section may be more tricky to understand // always the angles are used to calculate the slice positions since a circle is given by // a parameterization with the angle // most of these shapes are, however, nearly impossible to cut manually if (y0 < StockLength) { // circle entirely inside of stock piece, section cuts // this is practical only for shallow cuts while ((xcor > StopAt) & (((SliceThickness*i+(x0-StockDiameter))/r) < 1)) { if (x0==StockDiameter) alfa_sl=asin(SliceThickness*i/r); if (x0>StockDiameter) alfa_sl=asin( (SliceThickness*i+(x0-StockDiameter))/r ); SlicePlotStart[i]=y0+r*sin(AlfaStart-alfa_sl); // circle center at edge of stock, half circle geometry if (x0==StockDiameter) { alfa_sl_end =asin(SliceThickness*i/r)+3.1415; SlicePlotEnd[i]= y0+r*sin(AlfaStart-alfa_sl_end); } // circle center outside of stock piece, circle section if (x0>StockDiameter) { alfa_sl_end=asin( (SliceThickness*i+(x0-StockDiameter))/r ) +3.1415; SlicePlotEnd[i]= y0+r*sin(AlfaStart-alfa_sl_end); } SliceLength[i]=SlicePlotEnd[i]-SlicePlotStart[i]; PlotRectangle (...); xcor = xcor-SliceThickness; i++; }// wile end }; // if end // we may have overlooked some kind of odd geometry but the program should catch most of them NumberOfSlices = i; return 0; } /**end*****************************************************************************/