In the second part of the Shapes snippets, I will show you how to draw an ellipse. The good thing is that it is indeed very easy and not more difficult than drawing a circle which was shown in the previous snippet. First thing, what is an ellipse? It's a curve or simply a flattened circle whose sides have different length's. For a very detailed and mathematical definition, take a look here.
One way to draw the ellipse would be to take the function of an ellipse and draw the points of the ellipse using this equation:
a and b are the length's of the both sides. You would simply extract e.g. the y coord and and iterate from the left side of the ellipse on the x-axis to the right side and draw the corresponding y-coordinate You would have to repeat the same for the lower area of the ellipse making y negative.
But this method is terribly uneffective and rather complicated. The only good thing is that you don't have to use trigonometric functions. The best and fastest method is simply to draw the ellipse like the circle in the last snippet but using different scalings for both x and y coordinates. The x-coordinate is cos § times the x-radius and the y-coordinate is cos § times the y-radius. Take a look at the code:
The code looks very similar to the code to draw a circle. In fact it's a circle but with two different radius'. As said above it's nothing more than a circle with two different scalings. The code is very easy and fast and the result will be a perfectly looking ellipse centered at (0,0,0). Example how to use it:
If you have further questions, simply visit the message board. Happy Coding!