<?xml version="1.0" encoding="utf-8"?>
<!--?xml-stylesheet type="text/xsl" href="pmathml.xsl"?-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1 plus MathML 2.0//EN"
"http://www.w3.org/TR/MathML2/dtd/xhtml-math11-f.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">


<!--<?xml version="1.0"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1 plus MathML 2.0 plus SVG 1.1//EN"
               "http://www.w3.org/Math/DTD/mathml2/xhtml-math11-f.dtd" [
  <!ENTITY mathml "http://www.w3.org/1998/Math/MathML">
]>  
<html xmlns="http://www.w3.org/1999/xhtml">-->
<head>
	<title>More Circle Pixels</title>
	<style type="text/css">
	    <!---->indent {text-indent: 1cm}
		comment {color: #056f00}
		keyword {color: #0000ff}
		cppcode {font-family: courier}
		hr {color: sienna}
		p {margin-left: 20px}
		body {background-image: url("images/back40.gif");
		     color: #000000; background-color: #FFFFFF; }
			.cpp1-assembler { color: #0000FF; }
			.cpp1-character { color: #000000; }
			.cpp1-comment { color: #008000; font-style: italic; }
			.cpp1-float { color: #800080; }
			.cpp1-hexadecimal { color: #800080; }
			.cpp1-identifier { color: #000000; }
			.cpp1-illegalchar { color: #000000; }
			.cpp1-number { color: #800080; }
			.cpp1-octal { color: #800080; }
			.cpp1-preprocessor { color: #0000FF; }
			.cpp1-reservedword { color: #000000; font-weight: bold; }
			.cpp1-space {  color: #000000; } 
			.cpp1-string { color: #FF0000; }
			.cpp1-symbol { color: #000000; } 
	</style>

</head>
<body>
<table border="0" cellpadding="0" style="border-collapse: collapse" bgcolor="#FFFFFF">

<tr >
				<td style='width:308px;padding-left:5.4pt; padding-right:5.4pt; padding-top:0in; padding-bottom:0in'>
				<p><b ><span
  style='font-size:16.0pt'>&nbsp;</span></b><a href="../october05.htm">Back to 
				October Calendar</a></p>
				</td>
				<td style='width:296px;padding-left:5.4pt; padding-right:5.4pt; padding-top:0in; padding-bottom:0in'>
				<a href="slog-10-22-weq-05.htm"><font face="Times New Roman">&#8592;</font>Previous Entry</a></td>
				<td style='width:167px;padding-left:5.4pt; padding-right:5.4pt; padding-top:0in; padding-bottom:0in'>
				<a href="slog-10-17-05.htm">Next Entry&#8594;</a></td>
</tr>


<h1>More Circle Pixels w/Mozilla</h1>

<p>This page was supposed to demonstrate the new MathPlayer 2.0 support XHTML + MathML pages.  Ha!</p>
<p>&nbsp;</p>
<p> A few links I've looked at of late</p>
<p><a href="http://web.mit.edu/is/topics/webpublishing/mathml/">
http://web.mit.edu/is/topics/webpublishing/mathml/</a> </p>
<p><a href="http://www.hostsrv.com/webMathematica/Resources/Documentation/English/indexE_5_1.html#t:67">
http://www.hostsrv.com/webMathematica/Resources/Documentation/English/indexE_5_1.html#t:67</a> </p>
<h1>Mozilla Testing and More Circle Pixels</h1>

<p>From http://www.dynamicdrive.com/forums/archive/index.php/t-1085.html </p>

<blockquote>

Sorry for the delay in answering your question, but I only saw your post this morning. Here's what you need to do to author a page that's viewable in both Netscape/Mozilla/Firefox and IE 6 + MathPlayer 2:<br />
	<br />1. These lines should be the first 4 lines in your code:<br />&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;<br />&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.1 plus MathML 2.0//EN&quot;<br />&quot;http://www.w3.org/TR/MathML2/dtd/xhtml-math11-f.dtd&quot;&gt;<br />&lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt;<br />
	<br />2. Each &lt;math&gt; tag in your MathML needs to have this attribute: xmlns='http://www.w3.org/1998/Math/MathML'.<br />
	<br />3. MathPlayer installs all fonts required for display in IE. For display in the Netscape browsers, you may need extra fonts. See http://www.mozilla.org/projects/mathml/fonts/ for more information.<br />
	<br />We have an article on our web site that may be helpful: A Math on the Web Publishing Process (http://www.dessci.com/en/support/tutorials/mt_mp/tutorial.htm) . Also if you're using Dreamweaver, we have a tutorial for using Dreamweaver to author XHTML+MathML pages (http://www.dessci.com/en/support/tutorials/mathml/mathmldw.htm) .<br />
	<br />Bob Mathews<br />bobm at dessci.com<br />Director of Training<br />Design Science, Inc. -- &quot;How Science Communicates&quot; (http://www.dessci.com/free.asp?free=news)
	<br />FREE fully-functional 30-day evaluation of MathType 5<br />MathType, WebEQ, MathPlayer, MathFlow, Equation Editor, TeXaide</blockquote>
<hr />


<p>


<p>Here are some math expressions.</p>
<math xmlns='http://www.w3.org/1998/Math/MathML'>
<msup>
<mi>x</mi>
<mn>2</mn>
</msup></math>

<br/>
<br/>

<math xmlns='http://www.w3.org/1998/Math/MathML'><mrow><mi>y</mi><mo>=</mo><mi>k</mi><mo>&plusmn;</mo><msqrt><mrow><msubsup><mi>r</mi><mrow></mrow><mn>2</mn></msubsup><mo>-</mo><msubsup><mrow><mo>(</mo><mrow><mi>x</mi><mo>-</mo><mi>h</mi></mrow><mo>)</mo></mrow><mrow></mrow><mn>2</mn></msubsup></mrow></msqrt></mrow></math>
&nbsp;</p>

<p>Today I want to continue the subject of yesterday's slog, but with an 
emphasis on accommodating Mozilla, if not both Mozilla and IE.&nbsp; So if this 
doesn't work with IE, try a Mozilla type browser like <a href="http://www.mozilla.com/firefox/">
FireFox</a>, though, if it doesn't work, you mayn't be 
getting this missive.&nbsp; Oh, well.</p>
<p>I used a simple point class to get started on implementing the midpoint 
algorithm as outlined yesterday (below).  Since I'm authoring an xml document, I'm unable to use Frontpage's "design" wysiwyg 
feature and so I'm trying to use styles...very tedious to get the following...not worth the trouble, really, yet.</p>
<p>&nbsp;</p>
<blockquote>
	<table border="0" cellpadding="0" style="border-collapse: collapse" bgcolor="#CCFFFF">
		<cppcode><tr>
			<td><comment>// class ScreenPt header file</comment>
<keyword><br/><br/>
			class</keyword><font SIZE="2"> screenPt </font>{
			<br/>
				<indent><indent><keyword>&nbsp;&nbsp;&nbsp;private</keyword>		GLint x, y;</indent></indent><br/>
	<keyword>&nbsp;&nbsp;&nbsp;public:</keyword><br/>
		<comment>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// default constructor  initializes coordinates to (0,0)</comment><br/>
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;screenPt() 	{
			x = y = 0;
		&nbsp;&nbsp;&nbsp;}
		<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<keyword>void</keyword> setCoords( GLint xCoordValue, GLint yCoordValue) 		{
			<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;x = xCoordValue;
			<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;y = yCoordValue;
		<br/>}

		 
		<br/><keyword>&nbsp;&nbsp;&nbsp;void</keyword> getx (GLint x_input) {<br/>
			&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;x =  x_input;<br/>
		&nbsp;&nbsp;&nbsp;}<br/>
		 
		&nbsp;&nbsp;&nbsp;<keyword>void</keyword> gety (GLint y_input ) {<br/>
			&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;y = y_input;<br/>
		&nbsp;&nbsp;&nbsp;}<br/>
		 
		&nbsp;&nbsp;&nbsp;GLint getx ( ) <keyword>const</keyword> 	{<br/>
					&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<keyword>return</keyword> x;<br/>
		&nbsp;&nbsp;&nbsp;}<br/>
		 
		&nbsp;&nbsp;&nbsp;GLint gety ( ) <keyword>const</keyword>	 {<br/>
			&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<keyword>return</keyword> y;<br/>
		&nbsp;&nbsp;&nbsp;}<br/>
		
		&nbsp;&nbsp;&nbsp;<keyword>void</keyword> incrementx( ) 	 {<br/>
			&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;++x;<br/>
		&nbsp;&nbsp;&nbsp;}<br/>
		
		&nbsp;&nbsp;&nbsp;<keyword>void</keyword> decrementy( ) {<br/>
			&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;--y;<br/>
		&nbsp;&nbsp;&nbsp;}<br/>
		&nbsp;&nbsp;&nbsp;<keyword>void</keyword> setPixel (GLint x, GLint y);<br/>
};</td><br/>
		</tr>
	</cppcode></table>
</blockquote>

<br/><br/>
Using DevCpp from bloodshed's export to html utility I was able to cut and paste style elements and the 
following code into this document, which makes it much easier to format code...
<br/>
<br/>


<blockquote>
	<table border="0" cellpadding="0" style="border-collapse: collapse" bgcolor="#CCFFFF">

<pre>
<code><span style="font: 10pt Courier New;"><span class="cpp1-preprocessor">#include &lt;gl/glut.h&gt;
#include &quot;ScreenPt.h&quot;

#include &lt;iostream&gt;
</span><span class="cpp1-reservedword">using</span><span class="cpp1-space"> </span><span class="cpp1-reservedword">namespace</span><span class="cpp1-space"> std;

</span><span class="cpp1-reservedword">void</span><span class="cpp1-space"> circleMidpoint (screenPt , GLint);
</span><span class="cpp1-reservedword">void</span><span class="cpp1-space"> circlePlotPoints (screenPt circCtr, screenPt circPt);

</span><span class="cpp1-reservedword">void</span><span class="cpp1-space"> setPixel (GLint x, GLint y) {
	glColor3f(</span><span class="cpp1-float">0.</span><span class="cpp1-symbol">,</span><span class="cpp1-float">0.</span><span class="cpp1-symbol">,</span><span class="cpp1-float">1.</span><span class="cpp1-symbol">);
	glBegin (GL_POINTS);
		glVertex2i (x, y);
	glEnd ( );
}


</span><span class="cpp1-comment">//&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt; init &gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;
</span><span class="cpp1-reservedword">void</span><span class="cpp1-space"> init(</span><span class="cpp1-reservedword">void</span><span class="cpp1-symbol">)  {
	glClearColor(</span><span class="cpp1-float">1.0</span><span class="cpp1-symbol">,</span><span class="cpp1-float">1.0</span><span class="cpp1-symbol">,</span><span class="cpp1-float">1.0</span><span class="cpp1-symbol">,</span><span class="cpp1-float">1.0</span><span class="cpp1-symbol">); </span><span class="cpp1-comment">//white background

</span><span class="cpp1-space">	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	</span><span class="cpp1-comment">//set the viewing coordinates
</span><span class="cpp1-space">	gluOrtho2D(-</span><span class="cpp1-number">100</span><span class="cpp1-symbol">, </span><span class="cpp1-number">100</span><span class="cpp1-symbol">, -</span><span class="cpp1-number">100</span><span class="cpp1-symbol">, </span><span class="cpp1-number">100</span><span class="cpp1-symbol">);
}

</span><span class="cpp1-comment">//&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt; display &gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;

</span><span class="cpp1-reservedword">void</span><span class="cpp1-space"> display(</span><span class="cpp1-reservedword">void</span><span class="cpp1-symbol">)
{
	glClear(GL_COLOR_BUFFER_BIT); </span><span class="cpp1-comment">// clear the screen
</span><span class="cpp1-space">	glColor3f(</span><span class="cpp1-float">1.0</span><span class="cpp1-symbol">,</span><span class="cpp1-float">1.0</span><span class="cpp1-symbol">,</span><span class="cpp1-float">1.0</span><span class="cpp1-symbol">); </span><span class="cpp1-comment">//white
</span><span class="cpp1-space">	glColor3f(</span><span class="cpp1-float">0.</span><span class="cpp1-symbol">,</span><span class="cpp1-float">0.</span><span class="cpp1-symbol">,</span><span class="cpp1-float">0.</span><span class="cpp1-symbol">);
	glBegin(GL_POLYGON);
		glVertex2i(-</span><span class="cpp1-number">30</span><span class="cpp1-symbol">,-</span><span class="cpp1-number">30</span><span class="cpp1-symbol">);
		glVertex2i(</span><span class="cpp1-number">10</span><span class="cpp1-symbol">,-</span><span class="cpp1-number">30</span><span class="cpp1-symbol">);
		glVertex2i(</span><span class="cpp1-number">10</span><span class="cpp1-symbol">,</span><span class="cpp1-number">0</span><span class="cpp1-symbol">);
		glVertex2i(-</span><span class="cpp1-number">30</span><span class="cpp1-symbol">,</span><span class="cpp1-number">10</span><span class="cpp1-symbol">);
	glEnd();
    
	screenPt center;
	GLint center_x, center_y, radius;
	cout &lt;&lt; </span><span class="cpp1-string">&quot;\nEnter the coordinates of the center point of the circle: &quot;</span><span class="cpp1-symbol">;
	cin &gt;&gt; center_x &gt;&gt; center_y;
	center.setCoords(center_x,center_y);
	cout &lt;&lt; </span><span class="cpp1-string">&quot;\nEnter the radius of the circle: &quot;</span><span class="cpp1-symbol">;
	cin &gt;&gt; radius;
	</span><span class="cpp1-comment">//The big function call:

</span><span class="cpp1-space">	circleMidpoint(center,radius);
	glFlush(); </span><span class="cpp1-comment">// send all output to display
</span><span class="cpp1-space">	</span><span class="cpp1-reservedword">char</span><span class="cpp1-space"> ch; cin &gt;&gt; ch;  </span><span class="cpp1-comment">//pause
</span><span class="cpp1-symbol">}

</span><span class="cpp1-comment">//&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt; main &gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;
</span><span class="cpp1-reservedword">int</span><span class="cpp1-space"> main(</span><span class="cpp1-reservedword">int</span><span class="cpp1-space"> argc, </span><span class="cpp1-reservedword">char</span><span class="cpp1-symbol">** argv)
{
	glutInit(&amp;argc, argv); </span><span class="cpp1-comment">// initialize the toolkit

</span><span class="cpp1-space">	glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
	glutInitWindowSize(</span><span class="cpp1-number">200</span><span class="cpp1-symbol">,</span><span class="cpp1-number">200</span><span class="cpp1-symbol">); </span><span class="cpp1-comment">// set window size

</span><span class="cpp1-space">	</span><span class="cpp1-comment">// set window position on screen
</span><span class="cpp1-space">	glutInitWindowPosition(</span><span class="cpp1-number">0</span><span class="cpp1-symbol">, </span><span class="cpp1-number">0</span><span class="cpp1-symbol">);
	</span><span class="cpp1-comment">// open the screen window and set the name
</span><span class="cpp1-space">	glutCreateWindow(</span><span class="cpp1-string">&quot;circle pixels&quot;</span><span class="cpp1-symbol">);
	</span><span class="cpp1-comment">//register your functions

</span><span class="cpp1-space">	glutDisplayFunc(display);
	init();

	glutMainLoop(); </span><span class="cpp1-comment">// go into a perpetual loop
</span><span class="cpp1-space">	</span><span class="cpp1-reservedword">return</span><span class="cpp1-space"> </span><span class="cpp1-number">0</span><span class="cpp1-symbol">;
}

</span><span class="cpp1-reservedword">void</span><span class="cpp1-space"> circleMidpoint (screenPt circCtr, GLint radius)    {
	screenPt circPt;
	</span><span class="cpp1-comment">// GLfloat p = 1.25 - radius
</span><span class="cpp1-space">	GLint p = </span><span class="cpp1-number">1</span><span class="cpp1-space"> - radius;         </span><span class="cpp1-comment">// Initial value of decision parameter.

</span><span class="cpp1-space">	circPt.setCoords(</span><span class="cpp1-number">0</span><span class="cpp1-symbol">,radius);   </span><span class="cpp1-comment">// Set coordinates for top point of circle.
</span><span class="cpp1-space">	
	</span><span class="cpp1-reservedword">void</span><span class="cpp1-space"> circlePlotPoints (screenPt, screenPt);
	
	</span><span class="cpp1-comment">/* Plot the initial point in each circle quadrant. */
</span><span class="cpp1-space">	circlePlotPoints (circCtr, circPt);
    
	</span><span class="cpp1-comment">/* Calculate next points and plot in each octant. */
</span><span class="cpp1-space">	</span><span class="cpp1-reservedword">while</span><span class="cpp1-space"> (circPt.getx() &lt; circPt.gety()) {
		circPt.incrementx();
		</span><span class="cpp1-reservedword">if</span><span class="cpp1-space"> (p &lt; </span><span class="cpp1-number">0</span><span class="cpp1-symbol">)
			p += </span><span class="cpp1-number">2</span><span class="cpp1-space"> * circPt.getx() + </span><span class="cpp1-number">1</span><span class="cpp1-symbol">;
		</span><span class="cpp1-reservedword">else</span><span class="cpp1-space"> {
			circPt.decrementy();
			p += </span><span class="cpp1-number">2</span><span class="cpp1-space"> * (circPt.getx() - circPt.gety()) + </span><span class="cpp1-number">1</span><span class="cpp1-symbol">;
		}
		circlePlotPoints (circCtr, circPt);
	}
	glFlush();
}


</span><span class="cpp1-reservedword">void</span><span class="cpp1-space"> circlePlotPoints (screenPt circCtr, screenPt circPt) {
	</span><span class="cpp1-comment">// the eight symmetric points
</span><span class="cpp1-space">	setPixel (circCtr.getx() + circPt.getx(), circCtr.gety() + circPt.gety());
	setPixel (circCtr.getx() - circPt.getx(), circCtr.gety() + circPt.gety());
	setPixel (circCtr.getx() + circPt.getx(), circCtr.gety() - circPt.gety());
	setPixel (circCtr.getx() - circPt.getx(), circCtr.gety() - circPt.gety());
	setPixel (circCtr.getx() + circPt.gety(), circCtr.gety() + circPt.getx());
	setPixel (circCtr.getx() - circPt.gety(), circCtr.gety() + circPt.getx());
	setPixel (circCtr.getx() + circPt.gety(), circCtr.gety() - circPt.getx());
	setPixel (circCtr.getx() - circPt.gety(), circCtr.gety() - circPt.getx());
}


</span></span>
</code></pre></table>



</blockquote>
<br/><br/>
<table border="1" cellpadding="2" style="border-collapse: collapse">
	<tr>
		<td>Wow, that's easier, but still requires fussing with bground color for the .cppl space, etc.

The result of running this code is to make a funny trapezoid (part of the debugging I did which I kept for now) 
and a prompt for circle parameters, which might look like so:
<p>Enter the coordinates of the center point of the circle: 40 40<br/>
Enter the radius of the circle: 50
</p>
&nbsp;</td>
		<td><img border="0" src="octoberPics/circlepix03.gif" width="215" height="250"></img></td>
	</tr>
</table>
<br/><br/>
Here's a detail of the upper right quadrant of the circle over a pixel grid, together with the data for pixel coordinates.
You can count 7 pixels to right of center on the top row (y = 90), 5 pixels below that (y = 89) and so on.
<br/><br/>
<table border="0" cellpadding="0" style="border-collapse: collapse">
	<tr>
		<td><font size="2">
40 90<br/> 
41 90<br/>
42 90<br/>
43 90<br/>
44 90<br/>
45 90<br/>
46 90<br/>
47 90<br/>
48 89<br/>
49 89<br/>
50 89<br/>
51 89<br/>
52 89<br/>
53 88<br/>
54 88<br/>
55 88<br/>
56 87<br/>
57 87<br/>
58 87<br/>
59 86<br/>
60 86<br/>
61 85<br/>
62 85<br/>
63 84<br/>
64 84<br/>
65 83<br/>
66 83<br/>
67 82<br/>
68 81<br/>
69 81<br/>
70 80<br/>
71 79<br/>
72 78<br/>
73 78<br/>
74 77<br/>
75 76<br/>
76 75</font></td>
		<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
		<img border="0" src="octoberPics/CIRCLE~5.gif" width="659" height="594"></img><p>&nbsp;</p>
		</td></tr>
	
</table>
<p>I'm getting an error when I try to view with IE, but the Mozilla envelope 
seems to be working fine...the reverse of yesterday.</p>
<p>In any case, I'll finish up today by outlining the code I wrote to produce 
the diagram above (which then required lots of fussing to make the pixel grid 
work out right.&nbsp; You like it good?&nbsp; I hope so.&nbsp; See how how it 
matches the coordinate pairs data in the left column: it had better match since 
the data and the graph were produce simultaneously.</p>

</table>
</body>
</html>
