Lecture07 - Output Primitives (Part III)

Lecture07 - Output Primitives (Part III) - OutputPrimitives...

Info iconThis preview shows pages 1–9. Sign up to view the full content.

View Full Document Right Arrow Icon
Output Primitives Output Primitives Part III Circle-Generating Algorithm
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
2 A very fine place to start A very fine place to start Let’s begin by looking at the equation of a circle: Solving for y :
Background image of page 2
3 A very fine place to start A very fine place to start And this is one of the sample codes: void circleSimple(int xCenter, int yCenter, int radius, Color c) { int x, y, r2; r2 = radius * radius; for (x = -radius; x <= radius; x++) { y = (int)(sqrt(r2 - x*x) + 0.5); setPixel(xCenter + x, yCenter + y, c); setPixel(xCenter + x, yCenter – y, c); } }
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
4 The result The result We came across this problem with lines before… Sometimes the slope of the line tangent to a point the circle is greater than 1. Stepping in x won’t work there. So we could look for this case and step in y
Background image of page 4
5 Is it a good solution? Is it a good solution? … maybe not! But on both cases, we were taking advantage of the circle’s symmetry when we draw both positive and negative values for y (or x). This is called 2-way symmetry . Are there more symmetries to exploit?
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
6 Symmetry abounds Symmetry abounds Sure, let’s try 4-way symmetry . With just a quick hack, we get:
Background image of page 6
7 Symmetry abounds Symmetry abounds void circle4Way(int xCenter, int yCenter, int radius, Color c) { int x, y, r2; setPixel(xCenter, yCenter + radius, c); setPixel(xCenter, yCenter – radius, c); r2 = radius * radius; for (x = 1; x <= radius; x++) { y = (int)(sqrt(r2 - x*x) + 0.5); setPixel(xCenter + x, yCenter + y, c); setPixel(xCenter + x, yCenter – y, c); setPixel(xCenter - x, yCenter + y, c); setPixel(xCenter - x, yCenter – y, c); } }
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
The same result but in half the time … The same result but in half the time … That didn’t fix a thing. Oh sure, it’s faster – just half as many evaluations – but it’s no more correct than our first try. Why didn’t this work?
Background image of page 8
Image of page 9
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 24

Lecture07 - Output Primitives (Part III) - OutputPrimitives...

This preview shows document pages 1 - 9. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online