14
3
An algebraic curve is a certain "1D subset" of the "2D-plane" that can be described as set of zeros {(x,y) in R^2 : f(x,y)=0 }
of a polynomial f
. Here we consider the 2D-plane as the real plane R^2
such that we can easily imagine what such a curve could look like, basically a thing you can draw with a pencil.
Examples:
0 = x^2 + y^2 -1
a circle of radius 10 = x^2 + 2y^2 -1
an ellipse0 = xy
a cross shape, basically the union of the x-axis and the y-axis0 = y^2 - x
a parabola0 = y^2 - (x^3 - x + 1)
an elliptic curve0 = x^3 + y^3 - 3xy
the folium of Descartes0 = x^4 - (x^2 - y^2)
a lemniscate0 = (x^2 + y^2)^2 - (x^3 - 3xy^2)
a trifolium0 = (x^2 + y^2 - 1)^3 + 27x^2y^2
an astroid
Task
Given a polynomial f
(as defined below), and the x/y-ranges, output an black and white image of at least 100x100 pixels that shows the curve as black line on a white background.
Details
Color: You can use any two other colours of your choice, it should just be easy to tell them apart.
Plot: Instead of a pixel image you can also output this image as ascii-art, where the background "pixels" should be space/underline or an other character that "looks empty" and the line can be made of a character that looks "full" like M
or X
or #
.
You do not have to worry about aliasing.
You only need to plot lines where the sign of the polynomial changes from one side of the line to the other (that means you could e.g. use the marching square algorithm), you do not have to correctly plot "pathological cases like 0 = x^2
where the sign does not change when going from one side of the line to the other. But the line should be continuous and separating the regions of the different signs of f(x,y)
.
Polynomial: The polynomial is given as a (m+1) x (n+1)
matrix/list of lists of (real) coefficients, in the example below the terms of the coefficients are given in their position:
[ 1 * 1, 1 * x, 1 * x^2, 1 * x^3, ... , 1 * x^n ]
[ y * 1, y * x, y * x^2, y * x^4, ... , y * x^n ]
[ ... , ... , ... , ... , ... , ... ]
[ y^m * 1, y^m * x, y^m * x^2, y^m * x^3 , ..., y^m * x^n]
If you prefer, you can assume the matrix to be square (which can always be done with the necessary zero-padding), and if you want, you can also assume that the size of the matrix is given as aditional inputs.
In the following, the examples from above are represented as a matrix defined like this:
Circle: Ellipse: Parabola: Cross: Elliptic Curve: e.t.c
[-1, 0, 1] [-1, 0, 1] [ 0,-1] [ 0, 0] [-1, 1, 0,-1]
[ 0, 0, 0] [ 0, 0, 0] [ 0, 0] [ 0, 1] [ 0, 0, 0, 0]
[ 1, 0, 0] [ 2, 0, 0] [ 1, 0] [ 1, 0, 0, 0]
Test cases with x-range / y-range:
(In a not so readable but better copy-paste-able format available here on pastebin.)
Circle:
[-1, 0, 1] [-2,2] [-2,2]
[ 0, 0, 0]
[ 1, 0, 0]
Ellipse:
[-1, 0, 1] [-2,2] [-1,1]
[ 0, 0, 0]
[ 2, 0, 0]
Cross:
[ 0, 0] [-1,2] [-2,1]
[ 0, 1]
Parabola:
[ 0,-1] [-1,3] [-2,2]
[ 0, 0]
[ 1, 0]
Elliptic Curve:
[-1, 1, 0,-1] [-2,2] [-3,3]
[ 0, 0, 0, 0]
[ 1, 0, 0, 0]
Folium of Descartes:
[ 0, 0, 0, 1] [-3,3] [-3,3]
[ 0, -3, 0, 0]
[ 0, 0, 0, 0]
[ 1, 0, 0, 0]
Lemniscate:
[ 0, 0, -1, 0, 1] [-2,2] [-1,1]
[ 0, 0, 0, 0, 0]
[ 1, 0, 0, 0, 0]
Trifolium:
[ 0, 0, 0,-1, 1] [-1,1] [-1,1]
[ 0, 0, 0, 0, 0]
[ 0, 3, 2, 0, 0]
[ 0, 0, 0, 0, 0]
[ 1, 0, 0, 0, 0]
Astroid:
[ -1, 0, 3, 0, -3, 0, 1] [-1,1] [-1,1]
[ 0, 0, 0, 0, 0, 0, 0]
[ 3, 0, 21, 0, 3, 0, 0]
[ 0, 0, 0, 0, 0, 0, 0]
[ -3, 0, 3, 0, 0, 0, 0]
[ 0, 0, 0, 0, 0, 0, 0]
[ 1, 0, 0, 0, 0, 0, 0]
I've got the inspiration for some curves from this pdf.
Does "You do not have to worry about aliasing" mean that we can just colour each pixel according to whether its centre lies on the line? – Peter Taylor – 2016-07-29T15:19:53.070
I don't see the connection to aliasing. But no, there should be a continuous line separating the regions of different signs. – flawr – 2016-07-29T15:32:27.677
The matrix is not
m
xn
, but(m+1)
x(n+1)
. What do we take as input:m, n
, orm+1,n+1
? Or can we choose? – Luis Mendo – 2016-07-29T23:18:58.693Can we just show the graphed function in a new window? – R. Kap – 2016-07-30T07:35:36.620
@R.Kap Yes, sure! – flawr – 2016-07-30T09:41:08.393
@LuisMendo Thanks. It doesn't really matter whether you take
m-1,m or m+1
, or as unary or whatever. – flawr – 2016-07-30T09:42:37.800Can we choose axis orientation? Like showing the figures flipped – Luis Mendo – 2016-07-30T17:54:21.207
1@LuisMendo Yes, the axis can be in any direction you like. (As long they are orthogonal=) – flawr – 2016-07-30T18:13:12.770
Why’s this tagged [tag:abstract-algebra]? – Lynn – 2016-07-30T18:49:39.103
@Lynn Algebraic curves are studied in algebraic geometry which is part of abstract algebra. – flawr – 2016-07-30T19:02:38.403