 # Data Types and Sqrt()

Hey guys,

I’m working on plotting a circle using two stepper motors. One controls the X axis, the other controls the Y axis. Pretty simple setup.

Here’s the section of my code that is intended to draw one quadrant of the circle:

``````void circle(long r){
Serial.println("Starting the circle.");
long r2 = sq(r);
Serial.println(r2);
for (int i=0;i<r;i++){
x.step(1);
curx+=1;
long expy = (sqrt(r2 - (sq(curx))))+1;
y.step(expy-cury);
cury = expy;
Serial.println();
Serial.print("  X: "+String(curx));
Serial.print("  Y: "+String(cury));
}
delay(10000);
}
``````

The problem is that when I graph the outputted points, it’s not circular, even though based on my understanding of the code, I feel like it should be.

I threw the datapoints in Excel just to visualize it, peradventure the machine I built was just imprecise. Plotting it in Excel confirmed the issue:

Is there something about the sqrt() function returning a float that could cause this much of an elongation in my circle?

I’ve been staring at this all afternoon, just need a different pair of eyes. TIA!

5 posts were merged into an existing topic: Simple Math Operations Giving Unexpected Outputs