Take the 2-minute tour ×
Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. It's 100% free, no registration required.

I need to draw a conic curve when quadratic equation in two variables is given:

$$Ax^2 + Bxy + Cy^2 + Dx + Ey + F = 0$$

Since I can't simply check whether the pixel is solving the equation, what I'm doing is plotting this function as a height map in 2D: the closest the function value to 0 the more greener the pixel, so it looks like this: enter image description here

But then I get a non unique curve, in some places the curve is thick and in others thin and the more sharp the curve the more thick the curve. I know that it's because the function is still close to 0 at this point.

So I tried normalizing the values by dividing them with the partial derivatives, since they are greater at the thin place and that way the curve should become more unique, but then it got even worst: enter image description here

So do anyone know of a way to draw the curve exactly as it is (only the correct or almost correct solutions), or how to correctly normalize my solution.

Solution by Henning Makholm:

"Plot all pixels where the sign of the polynomial differs from that of one of its neighbors."

Result: enter image description here

I did lost the fade effect but it's very simple and yet still looking good, thanks.

share|improve this question
1  
You can get some crude anti-aliasing as follows: Let $(x',y')$ be the neighbor pixel to $(x,y)$ whose value differs most from $f(x,y)$ (in the appropriate direction), and color pixel $(x,y)$ in proportion to $\frac{|f(x',y')|}{|f(x',y')-f(x,y)|}$. –  Henning Makholm Sep 28 '12 at 18:39

2 Answers 2

up vote 3 down vote accepted

Plot all pixels where the sign of the polynomial differs from that of one of its neighbors.

share|improve this answer

If you hold x fixed, you can solve the equation for y using the standard formula for quadradic equations. You'll get 0, 1 or 2 solutions for y for each x. Then, iterate over all x values you're interested in, compute the solution(s) for y, and paint the corresponding pixel(s) green.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.