# mathematical burden

hi all,

I have a mathematical question:

I have a circle with a radius between 18 and 25 meters.
A crossing perpendicular line chops of a very small portion of this circle. The lengthe of the line is varying between 0 and 50 cm inside the circle.
I woud like to calculate the difference in length of the full circe radius and the piece shopped by the line.
The differences are varying between 0 and 900 nm.
What ever I do I bounch into issues with the fact a long int is large enough but a integer, while taking the sqrt of a large number shops off the decimals needed to calulate the differnce.
I’n using in excel the follwing formule, which works out fine, but fails in the arduino:

Difference = Radius - √ ( Radius2 – X2) , whereby the Radius varius between 18 and 25 meters, while x is between 0 and 25 cm and is perpendicular on the radius.

Is there some one who can help me out finding the right approach?

but a integer, while taking the sqrt of a large number shops off the decimals

Not really a surprise as an int cannot hold a float value.

One solution would be to multiply the values by say 100 before doing the calculation and use integer maths for the calculation

You would usually use a float or a double for this kind of thing. Square root and trigonomentric functions are probably inbuilt. If the problem is that you are losing precision, rather than calculating radius-X2, when X2 is very small compared to the radius, redo your other calculations so they work with R and X2 directly.

I'd be inclined to approach this type of calculation by precalculating it using software that can work at that precision, and generating an array of values to include in your code. You'd do linear or quadratic interpolation with those values.

I'm sensing an XY problem here, incidentally. What are you actually trying to calculate here? You'd only encounter something like nanometres when you are dealing with visible light. Are you trying to work out the spacing of a laser interference pattern? Fooling about with holograms?

The reference page for floats on an arduino specifies that the precision is 6 to 7 digits, while excel has 15 digis of precision (at least that is what I find with a google search). That is probably enough difference to account for the 900nm error. The precision of the answer is also related to the precision of your measurements, you cannot create a result precise to a few nanometers if your measurements are only precise to a millimeter.

900 nm.

Do you really mean nanometers (10^-9 meters)?

If so, why does that difference matter on a scale of meters? You can't measure it easily.

let me explain a bit more.

What I would like to do is to measure the curve (radius) in speedskates. This curve is a radius between 18 m and 25 m. The skate itself has a length of approx 45 cm. So you can imagine the curve is from beginning to end all within 1 mm. The skates are clamped upside down into a frame on a fixed height. a measure device with a calibrated nanometer is checking every 10 mm the actual height of the skates. On these 10 mm spots I would like to compare the measurement value with the theoretical value. All results together indicate if the radius of the skates is still aqurate or the skates need a redo of the radius.

Oh this gets much simpler then. Let's reduce the problem to the part the computer sees. The computer doesn't know about skates or anything like that. To the computer it's just a data problem.

You are taking a set of measurements with the nanometer and you want to record those measurements and see if they fit some particular mathematical function.

Recording the values from the nanometer is the first challenge. Does it have any sort of output port? What type of nanometer is it? How does it work? Got links? Datasheets? Pictures?

The second part is easy. Once you get the readings you want to record them in memory. That part is trivial. Then you want to do some sort of mathematics on the data to get an answer yes or no. Before you can even think about writing that code, you have to write that out in math terms. If you have that math ready, then turning math into code is the easy part.

Well stating it in this way, Is it possible to store in the Arduino a kind of lookup table. So I can compare the value of the recording with the theoretical value?
The Nanometer has an usb output and I have an data ship translating this into a TTL serial string which can be read by the arduino. So that part is under control. The comparison with the theoretical value is the issue.

regards,
Martienn

Yeah storing numbers in memory is kind of what computers do. Comparing two numbers is just an if statement. This is a trivial exercise.

Shitani:
he skates are clamped upside down into a frame on a fixed height. a measure device with a calibrated nanometer is checking every 10 mm the actual height of the skates. On these 10 mm spots I would like to compare the measurement value with the theoretical value.

What does the arduino do? Wouldn't you just be typing the values into an Excel spreadsheet?

The part of the circle cut off by a chord is a Circular Segment:

Sounds like you want to measure the height (sagitta) of a circular segment where the length of the chord is known and want to see if the radius is consistent and within the limits of 18 to 25 meters?

Across 45 cm of skate blade the sagitta will only vary about 0.03 mm (22500 nm at 25 m radius and 31500 nm at 18 m radius). Over the much shorter chord length of 10 mm you’re talking 500 to 700 nm.

Problem: Aren’t the blades hollow-ground? I suspect the difference between the bottom of the grind and the top of the edges will be greater than the curve along any 10 mm segment. Are you measuring to the bottom of the curve? One edge? Both edges?

Notes:
sagitta = R - sqrt(RR - (cc) / 4)

Given:
R=25000 mm (25 m)
c = 10 mm

sagitta = 25000 - sqrt( 2500025000 - (1010)/4)
sagitta = 25000 - sqrt( 625000000 - 100 / 4)
sagitta = 25000 - sqrt( 625000000 - 25)
sagitta = 25000 - sqrt( 624997500)
sagitta = 25000 - 24999.999499999995
sagitta = 0.000500000005 mm. Let’s call it 0.000500 mm (500 nm) over a 10 mm span.

Given:
R=18000 mm (18 m)
c = 10 mm

sagitta = 18000 - sqrt( 1800018000 - (1010)/4)
sagitta = 18000 - sqrt( 324000000 - 100 / 4)
sagitta = 18000 - sqrt( 324000000 - 25)
sagitta = 18000 - sqrt( 323999975)
sagitta = 18000 - 17999.99930555554216
sagitta = 0.00069444445784 mm. Let’s call it 0.000700 mm (700 nm) over a 10 mm span.

So it is nanometers, in this case the wavelength range of green to near-IR light!

In fact the Arduino can calculate that without loss of precision, if you avoid subtracting numbers that are very close to being equal.

Expand the square root and ignore terms higher than first order: sqrt(1-x) ~ 1-x/2 for x << 1
Then sagitta = R - sqrt(RR - (cc) / 4) = R (1 - sqrt(1 - (cc)/(4R*R)) ~ c2/(8R)

``````void setup() {
Serial.begin(9600);
while (!Serial);
float R=25000.0; //mm
float c=10.0; //mm
float s=c*c/8/R;
Serial.println(s,6);  //prints 0.000500 (mm) = 500 nm
}
void loop() {}
``````