Utterly stupid maths question: area of an ellipse
lazarus / 21-General
----------------------------------------------------------------------
MarkMLl · 2021-10-12 11:07
I'm very sorry to be asking this in public, but for some reason this
is challenging me. I'm trying to output a couple of outlines,
represented by routes, into a .gpx file which is basically XML. I
don't think that really matters, I'm just trying to give some
background for the fragment below.
I've got mean and standard deviation lat and long, accumulated using
Welford's Method. I'm fairly happy with that bit, and they display OK
using QGIS.
I can draw a rectangular or elliptical outline with edges
corresponding to the standard deviation. However that leaves the area
of the ellipse slightly smaller than that of the rectangle: to get a
better visual approximation what fudge factor do I have to apply to
boost the ellipse's area to that of the rectangle, and why?
Code: Pascal [Select][+][-]window.onload = function(){var x1 =
document.getElementById("main_content_section"); if (x1) { var x =
document.getElementsByClassName("geshi");for (var i = 0; i
WriteLn(gpx, ' '); WriteLn(gpx, ' Cartesian standard
deviation'); x := meanLong + sigmaLong; y := meanLat
+ sigmaLat; WriteLn(gpx, ' '); x := meanLong + sigmaLong; y := meanLat -
sigmaLat; WriteLn(gpx, ' '); x := meanLong - sigmaLong; y := meanLat -
sigmaLat; WriteLn(gpx, ' '); x := meanLong - sigmaLong; y := meanLat +
sigmaLat; WriteLn(gpx, ' '); x := meanLong + sigmaLong; y := meanLat +
sigmaLat; WriteLn(gpx, ' '); WriteLn(gpx, ' '); // As an approximation, I
suppose that I could get the area of an ellipse// using pi *
minor_radius * major_radius, compare it with the area of// the
Cartesian standard deviation and introduce a fudge factor to draw an//
ellipse with the same area... fudge := 1.0; WriteLn(gpx, '
'); WriteLn(gpx, ' Polar standard deviation');
for i := 0 to 30 do begin x := meanLong + sigmaLong * fudge * Cos(i
* (2 * Pi / 30)); y := meanLat + sigmaLat * fudge * Sin(i * (2 * Pi
/ 30)); WriteLn(gpx, ' ') end; WriteLn(gpx, ' ');
MarkMLl
----------------------------------------------------------------------
wp · 2021-10-12 12:36
If I understand correctly you have a rectangle and an ellipse which
tightly is enclosed in the rectangle. The major and minor axes of the
ellipse are a and b, respectively, and the lengths of the rectangle
sides are 2*a and 2*b, respectively.
The area of the ellipse is pi*a*b.
The area of the rectangle is (2*a) * (2*b) = 4*a*b.
Their ratio is 4/pi (rectangle / ellipse).
Therefore, you must draw an ellipse with major and minor axes 4a/pi
and 4b/pi to get an ellipse which has the same area as the rectangle.
----------------------------------------------------------------------
engkin · 2021-10-12 12:44
Code: Pascal [Select][+][-]window.onload = function(){var x1 =
document.getElementById("main_content_section"); if (x1) { var x =
document.getElementsByClassName("geshi");for (var i = 0; i
fudge:=2/sqrt(pi);
Edit:
I think wp meant to mention the square root of the ratio to change it
from area to length ratio.
----------------------------------------------------------------------
MarkMLl · 2021-10-12 12:46
Quote from: wp on October 12, 2021, 02:36:50 pmIf I understand
correctly you have a rectangle and an ellipse which tightly is
enclosed in the rectangle. The major and minor axes of the ellipse are
a and b, respectively, and the lengths of the rectangle sides are 2*a
and 2*b, respectively.
The area of the ellipse is pi*a*b.
The area of the rectangle is (2*a) * (2*b) = 4*a*b.
Their ratio is 4/pi (rectangle / ellipse).
Therefore, you must draw an ellipse with major and minor axes 4a/pi
and 4b/pi to get an ellipse which has the same area as the rectangle.
That's what I thought, but it leaves the ellipse oversized...
Checking on the screen, rectangle is 47.25mm high, x 4/pi = 60.16
which is what I measure.
MarkMLl
----------------------------------------------------------------------
wp · 2021-10-12 12:58
Oh, yes! When x and y of the ellipse are scaled by 4/pi then the area
increases by the factor sqr(4/pi), of course! You must scale the
ellipse axes by the factor 2/sqrt(pi) only (square root).
----------------------------------------------------------------------
MarkMLl · 2021-10-12 13:17
Many thanks: I'm happy to take it on trust that that's right, and that
even if it still looks a bit tight that's an optical illusion.
At some point I'll return to this and redo the standard deviation
using polar coordinates so that I can orient the rectangle/ellipse,
but that's low down in the list of priorities.
Of rather more interest, but only if somebody can answer it without
effort: allowing that the data I'm looking at can't be assumed to be
normally distributed, is there an equivalent or extension of Welford's
Method which also produces the 2-sigma and 3-sigma values?
I looked a bit at LazMapViewer for displaying this stuff over the
weekend, but ended up going back to QGIS since it can zoom in further
(presumably just by scaling the raster map). I'll almost certainly get
back to that at some point...
MarkMLl
----------------------------------------------------------------------
wp · 2021-10-12 14:13
Quote from: MarkMLl on October 12, 2021, 03:17:20 pmOf rather more
interest, but only if somebody can answer it without effort: allowing
that the data I'm looking at can't be assumed to be normally
distributed, is there an equivalent or extension of Welford's Method
which also produces the 2-sigma and 3-sigma values?
When Welford's method calculates the standard deviation of a
distribution, sigma, then 2-sigma is the double value, 3-sigma the
triple. There's no magic here.
----------------------------------------------------------------------
MarkMLl · 2021-10-12 14:22
Quote from: wp on October 12, 2021, 04:13:20 pmWhen Welford's method
calculates the standard deviation of a distribution, sigma, then
2-sigma is the double value, 3-sigma the triple. There's no magic
here.
But surely that applies only to normal distribution? The stuff I'm
looking at (part-corrected GNSS constellation data) is decidedly non-
normal.
MarkMLl
----------------------------------------------------------------------
wp · 2021-10-12 14:39
Quote from: MarkMLl on October 12, 2021, 04:22:33 pmQuote from: wp on
October 12, 2021, 04:13:20 pmWhen Welford's method calculates the
standard deviation of a distribution, sigma, then 2-sigma is the
double value, 3-sigma the triple. There's no magic here.
But surely that applies only to normal distribution? The stuff I'm
looking at (part-corrected GNSS constellation data) is decidedly non-
normal.
2-sigma is the double single standard deviation, in the same way that
2*3 is 6, just arithmetics, no relation to the underlying
distribution. The standard deviation, however, comes into play when
you make a statement that 68 percent of all events are within a range
of +/- 1 sigma around the mean, and that 95 percent are within +/- 2
sigma and 99.7 percent are within +/- 3 sigma (https://en.wikipedia.or
g/wiki/Standard_deviation#Rules_for_normally_distributed_data). These
percentages do depend on the distribution.
----------------------------------------------------------------------
MarkMLl · 2021-10-12 15:18
So put another way: Welford's Method allows you to estimate the mean
and spread of a distribution which might or might not be normal, with
~68% of the points falling inside that spread. Is there a
corresponding way of finding out the ~95% and ~99.7% spreads which
make no assumption about the actual distribution shape?
MarkMLl
----------------------------------------------------------------------
wp · 2021-10-12 16:04
I even doubt that for an arbitrary distribution 68% of the points are
inside the range calculated by Welford's method.
I have no idea what GNSS constellation data are... What do you know
about the distribution of these points? Is it radially symmetric? This
would mean that the distribution depends only on the distance from the
center. The ellipse that you mentioned indicates that this is not
true, but this may just be a consequence of not enough data points.
Here's what I would do (again: not knowing anything about GNSS): I'd
calculate the "center" of the distribution, this is the mean of the x
and y coordinates. Then I would calculate the distance, sqrt((xi-
xcenter)^2 + (yi-ycenter)^2) of all points from the center and store
the values in an array and sort it by the distances. Then I'd take the
index of each distance point in this array and normalize it to the
total count of data points - this produces the cumulative probability
of all data points having the same or a smaller distance from the
center. For a given percentile, I'd look for the distance for which
the cumulative probability is less than this percentage value. Finally
I'd use this as the radius of a circle in the original x/y plot of the
data points.
Note that very many data points are required to make a statement on
the 95% and 99.7% limits.
I can write a small project for you which demonstrates this idea, but
you should upload a typical data file (ideally as csv so that I do not
have to struggle with the xml of the gpx file).
----------------------------------------------------------------------
MarkMLl · 2021-10-12 16:20
Thanks @wp, I think I've probably got enough for the moment and the
fact that you've not pulled anything out of a hat suggests that my own
next-stage thoughts- much the same as yours- are probably something to
pursue if I need to.
GNSS is the generic term for things like GPS, but covering multiple
constellations. So you've got the GPS constellation, and can compare
that instantaneously against the Chinese Beidou constellation etc.
The .gpx files I'm emitting and postprocessing are a standardised
format used by lots of programs to store tracks of points, e.g.
generated by people orienteering etc. That allows me to use standard
programs such as QGIS and Google Earth (which is far more powerful
than most people realise) to render the output.
MarkMLl