I have an object that is 9in's in diameter (which is 228.6mm), I'm trying to calculate the speed (mph and kph) of the object for the duration of a laser trip, but I'm struggling with the maths.
The object is likely to trip the laser for between 0.5 or 1 sec, but every time I do the maths and that would be somewhere in the region of 600mph, which I know is wrong, can anyone help me with the math to calculate mph (or kph) of an object 9ins which will trip the laser for x milliseconds,
To simplify a little, if you give the length "l" in mm and the time "t" in ms, the speed "l/t" will come out in m/s anyway, because the millimeters cancel out the milliseconds. So all you need to do then is convert to kph by multiplying by 3600/1000 or 36/10. But to avoid integer maths loosing the decimal places, use ((l * 36) / t) / 10.0. This keeps the calculations in integers until that last divide, which is much faster than using floating point calculations from the start. Floating point calculations take a long time for an Arduino, as its all don e in software, there is no floating point hardware like in PC CPUs.
So your answer comes out as ((230 * 36) / 500) / 10.0 = 1.6 kph
But there is the assumption that the object (circle?) trips the laser for the max diameter - at height 4.5"
If the laser is tripped a lower or higher it is tripped shorter resulting in a higher speed.
example if the laser is tripped at height 6" (1/3 above the middle height) then the width that trips is
sin(arccos(1/3)) * max diameter = 0.94 * 9" = 8.5" (> 5% diff)
if the laser is tripped at height 7.5 (2/3 above)
sin(arccos(2/3)) * max dia = 0.74 * 9"= 6.7" (> 25% diff)
PaulRB:
Yes, we can only take the OP's word for it that the length is 230mm at the point it blocks the laser beam.
The calculations shows that if the beam is broken + or - 1.5" (~3.75 cm) around the max diameter
the error margin is less than (9-8.5)/9 ==> Less 6%
That means there is only a small error if the laser is not aligned perfectly
(assumption) one should be able to align the laser within +- 0.5" ==> 1/6 diameter so the max error is about
sin(arccos(1/6)) * max diameter = 0.986 * 9" = 8.87" (max 1.4%)