To come back to the 1st point, I want to stress out the fact that the main reason to not draw too many points is not related to performance but rather to visual quality.
Using too many points will no necessarily result in a less choppy shape for the reasons I mentioned in my previous post.
But it is also true that using too few will also result in a choppy shape as the shape is only approximated by straight lines.
So there is a middle ground to be found.
Another trick is to use curves to approximate the shape like bezier, catmull-rom splines, etc. For example in my first post, the shape is using only 34 points in total (vs the 600+ currently used in the second version with the delta angle = 0.01) â That might still be a bit too much: something around 80-100 points should probably be enough.
Now for the second point.
In your code you have this section to calculate the coordinate of a point:
for (float a = 0; a < TWO_PI; a = a + 0.0001) {
float r = 50;
float x = c + r*pow(cos(a), 3);
float y= d + r*sin(a)*2;
vertex(x, y);
}
It looks like polar coordinates since you are using a radius r and an angle a but it is not really since, in that case, you would calculate x and y with those formulas:
x = r * cos(a);
y = r * sin(a);
Because it is not the case, your angle a does not really mean the angle from the x-axis (like it would with polar coordinates) and the same goes for r.
To have more control over the effect and fully understand the impact of the random values, I needed to convert everything to true polar coordinates.
Letâs take the following exemple to illustrate:
In purple you have the shape and the points defining the shape.
In your code, I could extract, for each point, the (x, y) coordinate - in blue on the figure.
This list of coordinates where imported into excel and based on those values I could compute the (r, theta) components of the polar coordinates using the formula in the bottom right.
So what I did was simply translate the (x, y) coordinates given by your program to (r, theta) coordinates if they where given in polar coordinates.
The next step was plotting the curve of the points (r, theta) - theta being the âx-axisâ - and finding a function f(theta) that would match as closely as possible the original points.
Hereâs how it looks in excel:
- The blue columns x and y are the (x, y) coordinates computed by your code for a given shape.
- The yellow columns are the translation to (r, theta) polar coordinates of the (x, y) coordinates. (the âtheta modâ is a simple formula with some modulo to take into account the symmetry of your shape)
- The green columns are the computed r values of different candidate functions used to approximate the real r values. To simplify, the less delta there is between the column r and one of the function column the better it is.
The excel graph I showed you above was simply the r value plotting against theta and one of the 5 test functions.
To simplify my life, I gave each function some parameters that I could change on the fly and see straight away the result on the graph:
Hope it helps.