Another FP Problem

JBrookes

Member
Greetings
I am trying to use a picaxe to control a stepper that does circle shapes. At each trace point, the engraver will move on the tangent of the circle for a short distance, then recalculate.
For instance
The first derivative of a circle is y' = +/- x/sqrt (25-x^2)
This is a circle x^2 + y^2 = 25
This circle has a radius of 5 and it's origin x = 0.
So, the 1st derivative is x divided by sqrt (25-x^2)
Thus, the slope at (-3, 4) - (the upper left convex quadrant of circle) is - (-3/sqrt(25-9)) or 3/4.
The stepper then 'knows' to proceed 4 in x and 3 in y. If the stepper is limited (arbitrarily) to
a distance of 2 per movement in the larger value, then x increments 2 and y increments 1.5.
In cases of rounding, it would be nice to avoid long term drift, but that may be avoided in a random rounding process.

Can a picaxe do a sqrt, and square a value? For this project, I don't need to be very accurate, maybe 1-2%.

Any stabs at this welcome.
 

geoff07

Senior Member
The X2 parts may have what you need. Manual 2 page 26 refers. As for value ranges (critical when you don't have floating point) you will need to use word values and make sure that none of the function results go out of range. It may help to work in units of 1/10 or 1/100 to improve the resolution. You might find the trig functions help you to calculate the slope of the tangent more easily.
 

hippy

Technical Support
Staff member
What you want to do should be possible. I believe there are even well established algorithms which detail how to do it knowing where one is and where one needs to be next with integer steps ( whole, half, quarter etc ).

It's probably worthwhile looking up algorithms for drawing circles and arcs on pixel displays because there will probably be a lot of common ground.
 

eggdweather

Senior Member
IF x^2 + y^2 = 25 then I make the first derivative dy/dx = 2x and if x=3 then y = 6 which is a linear line originating at 0 and drawing a line to 3,6 which will be at a tangent to the circle/equation at that point.
 

eggdweather

Senior Member
Please explain - you've lost me completely. Some code might help? How would you achieve 1-2% accuracy, let's see some real code examples from you to help the op achieve what they want to do.
 

eggdweather

Senior Member
Although I made a mistake on the first derivitive, because I did not do it with respect to a circle, it is worth noting that the result of y' = -x/y so there is no need for any SQRT to be impemented and simplies the code solution enormously.

e.g. at the point of 0.7071 x 5 = x and the same for y, to make things easy y'= +/- 3.5 / (SQRT(25-3.5^) or +/- 3.5/3.5 or x/y = 1 at that point on the circle the slope is 1.
 
Last edited:
Top