1) Explain what the function below does. If there are any errors, fix them. Also, feel free to rewrite the function for efficiency or clarity.
ASSUMPTIONS:
* The function rand_FloatRange(float a, float b) returns a random number x, such that a <= x <= b.
* The function plot_point(float x, float y) plots a point in our display window. The center of the display window is (0.0f, 0.0f).
#define PI 3.14159f
#define CALC_PNT(rad, ang) x = rad*cos(ang); y = rad*sin(ang);
void PlotPnts()
{
for(int i=0; i < 100; i++)
{
float x,y;
CALC_PNT(10.0f, rand_FloatRange(0.0f, 2.0f*PI));
plot_point(x,y);
}
}
[source lang = "c"]
It Randomly plots 100 points in a cirlce of radius 10 and origin (0,0).
void PlotCirclePnts()
{
float x, y;
// Randomly draw 100 points 10.0f units away from coord(0, 0)
for(int i=0; i < 100; ++i)
{
// Get a new random x and y value
CALC_PNT(10.0f, rand_FloatRange(0.0f, 2.0f*PI));
// Draw the point onscreen
plot_point(x,y);
}
}