By following this post one can draw an ellipse with a given shape matrix (A):
library(car)
A <- matrix(c(20.43, -8.59,-8.59, 24.03), nrow = 2)
ellipse(c(-0.05, 0.09), shape=A, radius=1.44, col="red", lty=2, asp = 1)
Now how to get the major/minor (pair of intersect points of the major/minor axis and the ellipse) vertices of this ellipse?
Still highly unsure this will really answer the question but here's my try:
first, define the center of the ellipse as a vector for later use:
draw the ellipse and get the matrix of "points" with enought values to get a close enough to reality point:
Create a data.table with it and compute the distance of each point toward center (point_x - center_x)² + (point_y - center_y)²:
Order the vertices by distance:
Get the min and max points:
Don't add too much segments or the two first values will be two points really close to each other instead of opposite.
with a visual results this sounds not so exact at end:
I know this question has been seen as solved, but actually there is a super elegant solution to this, in only a few lines as follow. Such computation is precise, without any sort of numerical optimization.
In order to explain the mathematics behind, I am going to take 3 steps:
Where does this ellipse comes from?
In practice, this ellipse can be obtained by some linear transformation to the unit circle
x ^ 2 + y ^ 2 = 1
.Cholesky decomposition method and its drawback
We see that the linear transform matrix
R
does not appear to have natural interpretation. The original vertices of the circle do not map to vertices of the ellipse.Eigen decomposition method and its natural interpretation
Here we see that in both stages of the transform, vertices are still mapped to vertices. It is exactly based on such property we have the neat solution given at the very beginning.
For practical purposes, @Tensibai's answer is probably good enough. Just use a large enough value for the
segments
argument so that the points give a good approximation to the true vertices.If you want something a bit more rigorous, you can solve for the location along the ellipse that maximises/minimises the distance from the center, parametrised by the angle. This is more complex than just taking
angle={0, pi/2, pi, 3pi/2}
because of the presence of the shape matrix. But it's not too difficult: