Given the general form:
A(x^2)+B(x*y)+C(y^2)+D(x)+E(y)+F=0
How can I go about plotting the upper right (positive x,y) quadrant of these conic sections? I found some code to do it for ellipses using a parametric form, but I'm having trouble figuring out the more general solution.
plot.ellipse <- function (a, b, c, d, e, f, n.points = 1000) {
## solve for centre
A <- matrix(c(a, c / 2, c / 2, b), 2L)
B <- c(-d / 2, -e / 2)
mu <- solve(A, B)
## generate points on circle
r <- sqrt(a * mu[1] ^ 2 + b * mu[2] ^ 2 + c * mu[1] * mu[2] - f)
theta <- seq(0, 2 * pi, length = n.points)
v <- rbind(r * cos(theta), r * sin(theta))
## transform for points on ellipse
z <- backsolve(chol(A), v) + mu
## plot points
# plot(t(z), type = "l", xlim=c(0,1/d), ylim=c(0,1/e))
return(t(z))
}
When using this for non-ellipses, I get:
Error in chol.default(A) :
the leading minor of order 2 is not positive definite
Haven't really found anything that helps me understand if this just requires a tweak or a completely different approach.
The nature of the conic section is determined by the sign of the discriminant
Delta = B² - 4AC
. IfDelta > 0
, this is an ellipse; ifDelta < 0
, this is a hyperbola; ifDelta = 0
, this is a parabola.For an ellipse or a hyperbola, you can use the PlaneGeometry package.
Warning
I don't remember whether the equation is
or
You'll have to check.