NaN errors calculating points on elipse.
in
Programming Questions
•
2 years ago
I'm working on code to render the path of the sun and moon where they travel slowly at the top of the screen and move faster as they approach the horizon at 1/2 screen height. What I've got is working, but, about every three iterations through the calculation of y for the position of x, it generates a NaN error.
What is a NaN error? What does the acronym NaN mean? What effect do they have on memory use? Is it necessary to trap them?
What is a NaN error? What does the acronym NaN mean? What effect do they have on memory use? Is it necessary to trap them?
- float x;
- float y;
- void setup() {
- size(600,200);
- noLoop();
- //frameRate(1);
- x = width;
- y = height/2;
- }
- void draw(){
- ellipse(width/2,height/2,width,height);
- ellipse(x,y,10,10);
- //
- for (int i = 0; i <= width;i++)
- {
- x = width - x-i;
- y = -((float)(height/2)/(width/2)) * sqrt((float)sq(width/2) - sq(x-((float)width/2)))+height/2;
- if (x <= 0) {x *= -1;}// y *= -1;}
- //if (y <= 100) {y *= -1;}
- ellipse(x,y,14,14);
- ellipse(x,height-y,14,14);
- println(str(y));
- }
- }
1