Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to obtain the lengths of semi axes of an ellipse? in R

I have this set of x and y coordinates:

x<-c(1.798805,2.402390,2.000000,3.000000,1.000000)
y<-c(0.3130147,0.4739707,0.2000000,0.8000000,0.1000000)
as.matrix(cbind(x,y))->d

and I want to calculate the ellipsoid that contains this set of points, I use the function ellipsoidhull() in the package "cluster", and I get:

> ellipsoidhull(d)
'ellipsoid' in 2 dimensions:`
 center = ( 2.00108 0.36696 ); squared ave.radius d^2 =  2`
and shape matrix =
x 0.66590 0.233106
y 0.23311 0.095482
  hence, area  =  0.60406

However it's not obvious to me how I can get from these results, the lengths of the semi-major axes of this ellipse.

Any idea?

Thank you very much in advance.

Tina.

like image 318
user18441 Avatar asked Aug 16 '13 16:08

user18441


People also ask

How do you find the length of the semi-major axis of an ellipse?

The semi-major axis is half of the major axis. To find the length of the semi-major axis, we can use the following formula: Length of the semi-major axis = (AF + AG) / 2, where A is any point on the ellipse, and F and G are the foci of the ellipse.

How do you find the semi-minor axis of an ellipse?

The semi-minor axis of an ellipse runs from the center of the ellipse (a point halfway between and on the line running between the foci) to the edge of the ellipse. The semi-minor axis is half of the minor axis.

How do you find the length of a minor axis?

The minor axis is the line segment connecting the two co-vertices of the ellipse. If the co-vertices are at points (n,0) and (−n,0), then the length of the minor axis is 2n. The semi-minor axis is the distance from the center to one of the co-vertices and is half the length of the minor axis.

What is the length of its semi-minor axis?

The semi-minor axis is the length of the shortest radius of an ellipse, that is the smallest distance between the centre of the ellipse and the perimeter of the ellipse. with b≤a, the semi-minor axis is b.


2 Answers

The square of the semi-axes are the eigenvalues of the shape matrix, times the average squared radius.

x <- c(1.798805,2.402390,2.000000,3.000000,1.000000)
y <- c(0.3130147,0.4739707,0.2000000,0.8000000,0.1000000)
d <- cbind( x, y )
library(cluster)
r <- ellipsoidhull(d)
plot( x, y, asp=1, xlim=c(0,4) )
lines( predict(r) )
e <- sqrt(eigen(r$cov)$values)
a <- sqrt(r$d2) * e[1]  # semi-major axis
b <- sqrt(r$d2) * e[2]  # semi-minor axis
theta <- seq(0, 2*pi, length=200)
lines( r$loc[1] + a * cos(theta), r$loc[2] + a * sin(theta) )
lines( r$loc[1] + b * cos(theta), r$loc[2] + b * sin(theta) )
like image 68
Vincent Zoonekynd Avatar answered Oct 19 '22 13:10

Vincent Zoonekynd


You can do this:

exy <- predict(ellipsoidhull(d)) ## the ellipsoid boundary
me <- colMeans((exy))            ## center of the ellipse

Then you compute the minimum and maximum distance to get respectively minor and major axis:

dist2center <- sqrt(rowSums((t(t(exy)-me))^2))
max(dist2center)     ## major axis
[1] 1.264351
> min(dist2center)   ## minor axis
[1] 0.1537401

EDIT plot the ellipse with the axis:

plot(exy,type='l',asp=1)
points(d,col='blue')
points(me,col='red')
lines(rbind(me,exy[dist2center == min(dist2center),]))
lines(exy[dist2center == max(dist2center),])

enter image description here

like image 28
agstudy Avatar answered Oct 19 '22 13:10

agstudy