Andrew Harvey's Blog - Entries tagged graphicsEntries tagged graphics
//tianjara.net/blog/
en-auThe content on this blog by Andrew Harvey, unless otherwise noted is licensed under a Creative Commons Attribution 3.0 Australia License.Chronicle/blog/img/blog-icon.pngAndrew Harvey's Blog
//tianjara.net/blog/
Australian States Map/Graph API
/blog/archive/2010/02/australian_states_map_graph_api.html
/blog/archive/2010/02/australian_states_map_graph_api.htmlFri, 19 Feb 2010 17:22:25 +1100<p>I've managed to do a couple things all in one here. I've made use of some Geoscience Australia Creative Commons licensed material, in a nice little program with a web API, and I've aggregated some data from the <a href="http://andrewharvey4.wordpress.com/2010/02/07/a-look-into-the-myschool-edu-au-data/">myschool scraper and parser</a>. Putting them all together gives some nice images like this.</p>
<p><a href="http://github.com/andrewharvey/perlmisc/tree/master/australia_map/">The program for generating these images</a> basically takes an SVG template file with placeholder markers and then fills these values based on the CGI parameters. The API is fairly simple so one should be able to work out how to use it from the example in the README file. <a href="http://github.com/andrewharvey/myschool/tree/master/state_nplan_averages/datafiles/">Here are the files I used to make the graphs</a> (and the svg versions as Wordpress.com won't let me upload them to here).</p>
<p>ps. This gets cut off when viewing it from the default web interface of this blog, use print preview or even better look at the <a href="http://andrewharvey4.wordpress.com/feed/">RSS feed</a> to see the cut off parts. Also I tried to ensure the accuracy of the data, but I cannot be 100% sure that there are no bugs, in fact there are discrepancies with the averages I get from my scrape of myschool and the averages provided in the report on the <a href="http://www.naplan.edu.au/">NPLAN website</a>. The numbers I get seem to be consistent (ie. the state rankings seem mostly the same), but nonetheless not exactly the same as those reported in the report. Although I would be very surprised if all the numbers I got were exactly the same as in the report. I mainly did this to use map/graph code I wrote, so if you really care about how certain state averages compare in these tests look at the reports on the NPLAN website.</p>
<p>The lighter the colour the higher the number.</p>
<h2>Primary</h2>
<table style="text-align:center;">
<thead>
<tr>
<td></td>
<td>2008</td>
<td>2009</td>
</tr>
</thead>
<tbody>
<tr>
<td>Literacy</td>
<td><a href="/blog/attachments/2010/02/2008_primary_literacy-csv-svg.png"><img class="aligncenter size-full wp-image-1039" title="2008_primary_literacy.csv.svg" src="/blog/attachments/2010/02/2008_primary_literacy-csv-svg.png" alt="" width="325" height="300" /></a></td>
<td><a href="/blog/attachments/2010/02/2009_primary_literacy-csv-svg.png"><img class="aligncenter size-full wp-image-1037" title="2009_primary_literacy.csv.svg" src="/blog/attachments/2010/02/2009_primary_literacy-csv-svg.png" alt="" width="325" height="300" /></a></td>
</tr>
<tr>
<td>Numeracy</td>
<td><a href="/blog/attachments/2010/02/2008_primary_numeracy-csv-svg.png"><img class="aligncenter size-full wp-image-1040" title="2008_primary_numeracy.csv.svg" src="/blog/attachments/2010/02/2008_primary_numeracy-csv-svg.png" alt="" width="325" height="300" /></a></td>
<td><a href="/blog/attachments/2010/02/2009_primary_numeracy-csv-svg.png"><img class="aligncenter size-full wp-image-1035" title="2009_primary_numeracy.csv.svg" src="/blog/attachments/2010/02/2009_primary_numeracy-csv-svg.png" alt="" width="325" height="300" /></a></td>
</tr>
<tr>
<td>All</td>
<td><a href="/blog/attachments/2010/02/2008_primary_all-csv-svg.png"><img class="aligncenter size-full wp-image-1041" title="2008_primary_all.csv.svg" src="/blog/attachments/2010/02/2008_primary_all-csv-svg.png" alt="" width="325" height="300" /></a></td>
<td><a href="/blog/attachments/2010/02/2009_primary_all-csv-svg.png"><img class="aligncenter size-full wp-image-1033" title="2009_primary_all.csv.svg" src="/blog/attachments/2010/02/2009_primary_all-csv-svg.png" alt="" width="325" height="300" /></a></td>
</tr>
</tbody>
</table>
<h2>Secondary</h2>
<table style="text-align:center;">
<thead>
<tr>
<td></td>
<td>2008</td>
<td>2009</td>
</tr>
</thead>
<tbody>
<tr>
<td>Literacy</td>
<td><a href="/blog/attachments/2010/02/2008_secondary_literacy-csv-svg.png"><img class="aligncenter size-full wp-image-1042" title="2008_secondary_literacy.csv.svg" src="/blog/attachments/2010/02/2008_secondary_literacy-csv-svg.png" alt="" width="325" height="300" /></a></td>
<td><a href="/blog/attachments/2010/02/2009_secondary_literacy-csv-svg.png"><img class="aligncenter size-full wp-image-1038" title="2009_secondary_literacy.csv.svg" src="/blog/attachments/2010/02/2009_secondary_literacy-csv-svg.png" alt="" width="325" height="300" /></a></td>
</tr>
<tr>
<td>Numeracy</td>
<td><a href="/blog/attachments/2010/02/2008_secondary_numeracy-csv-svg.png"><img class="aligncenter size-full wp-image-1043" title="2008_secondary_numeracy.csv.svg" src="/blog/attachments/2010/02/2008_secondary_numeracy-csv-svg.png" alt="" width="325" height="300" /></a></td>
<td><a href="/blog/attachments/2010/02/2009_secondary_numeracy-csv-svg.png"><img class="aligncenter size-full wp-image-1036" title="2009_secondary_numeracy.csv.svg" src="/blog/attachments/2010/02/2009_secondary_numeracy-csv-svg.png" alt="" width="325" height="300" /></a></td>
</tr>
<tr>
<td>All</td>
<td><a href="/blog/attachments/2010/02/2008_secondary_all-csv-svg.png"><img class="aligncenter size-full wp-image-1044" title="2008_secondary_all.csv.svg" src="/blog/attachments/2010/02/2008_secondary_all-csv-svg.png" alt="" width="325" height="300" /></a></td>
<td><a href="/blog/attachments/2010/02/2009_secondary_all-csv-svg.png"><img class="aligncenter size-full wp-image-1034" title="2009_secondary_all.csv.svg" src="/blog/attachments/2010/02/2009_secondary_all-csv-svg.png" alt="" width="325" height="300" /></a></td>
</tr>
</tbody>
</table>
Computer Graphics Notes
/blog/archive/2009/12/computer_graphics_notes.html
/blog/archive/2009/12/computer_graphics_notes.htmlWed, 2 Dec 2009 08:36:10 +1100<p><em>Not really complete...
</em></p>
<p><em><a href="http://andrewharvey4.wordpress.com/2009/08/22/comp3421-lec-1-colour/">Colour notes here</a>, <a href="http://andrewharvey4.wordpress.com/2009/08/23/comp3421-lec-2-transformations/">transformations notes here</a>.</em></p>
<h1>Parametric Curves and Surfaces</h1>
<h2>Parametric Representation</h2>
<p>eg. $latex C(t) = (x(t), y(t))$</p>
<h2>Continuity</h2>
<h3>Parametric Continuity</h3>
<ul>
<li>If the first derivative of a curve is continuous, we say it has C<sup>1</sup> continuity.</li>
</ul>
<h3>Geometric Continuity</h3>
<ul>
<li>If the magnitude of the first derivative of a curve changes but the direction doesn't then, we say it has G<sup>1</sup> continuity.</li>
<li>Curves need G2 continuity in order for a car to drive along them. (ie. not instantly change steering wheel angle at any points).</li>
</ul>
<h2>Control Points</h2>
<p>Control points allow us to shape/define curves visually. A curve will either interpolate or approximate control points.</p>
<h2>Natural Cubic Splines</h2>
<p><a href="/blog/attachments/2009/08/naturalcubic.png"><img title="naturalcubic" src="/blog/attachments/2009/08/naturalcubic.png" alt="naturalcubic" width="102" height="155" /></a></p>
<ul>
<li>Interpolate control points.</li>
<li>A cubic curve between each pair of control points</li>
<li>Four unknowns,
<ul>
<li>
<ul>
<li>interpolating the two control points gives two,</li>
<li>requiring that derivatives match at end of points of these curves gives the other two.</li>
</ul>
</li>
</ul>
</li>
<li>Moving one control point changes the whole curve (ie. no local control over the shape of the curve)</li>
</ul>
<h2>Bezier Curve</h2>
<p><a href="/blog/attachments/2009/08/bez2seg.png"><img title="bez2seg" src="/blog/attachments/2009/08/bez2seg.png" alt="bez2seg" width="223" height="144" /></a></p>
<p>This Bezier curve shown has two segments, where each segment is defined by 4 control points. The curve interpolates two points and approximates the other two. The curve is defined by a Bernstein polynomial. In the diagram changing points 1 and 2 only affects that segment. Changing the corner points (0 and 3) each only affect the two segments that they boarder.</p>
<p>Some properties of Bezier Curves:</p>
<ul>
<li>Tangent Property. Tangent at point 0 is line 0 to 1, similarly for point 3.</li>
<li>Convex Hull Property. The curve lies inside the convex hull of the control points. (The corollary of this is if the control points are colinear, the curve is a line.)</li>
<li>They have affine invariance.</li>
<li>Can't fluctuate more than their control polygon does.</li>
<li>Bezier's are a special case of B-spline curves.</li>
</ul>
<p><a href="/blog/attachments/2009/08/bezier_curvec1.png"><img title="Bezier_curveC1" src="/blog/attachments/2009/08/bezier_curvec1.png" alt="Bezier_curveC1" width="450" height="262" /></a></p>
<p>We can join two Bezier curves together to have C<sup>1</sup> continuity (where B<sub>1</sub>(P<sub>0</sub>, P<sub>1</sub>, P<sub>2</sub>, P<sub>3</sub>) and B<sub>2</sub>(P<sub>0</sub>, P<sub>1</sub>, P<sub>2</sub>, P<sub>3</sub>)) if P<sub>3</sub> - P<sub>2</sub> = P<sub>4</sub> - P<sub>3</sub>. That is P<sub>2</sub>, P<sub>3</sub>, and P<sub>4</sub> are colinear and P<sub>3</sub> is the midpoint of P<sub>2</sub> and P<sub>4</sub>. To get G<sup>1</sup> continuity we just need P<sub>2</sub>, P<sub>3</sub>, and P<sub>4</sub> to be colinear. If we have G<sup>1</sup> continuity but not C<sup>1</sup> continuity the curve still won't have any corners but you will notice a "corner" if your using the curve for something else such as some cases in animation. [Also if the curve defined a road without G<sup>1</sup> continuity there would be points where you must change the steering wheel from one rotation to another instantly in order to stay on the path.]</p>
<h2>De Casteljau Algorithm</h2>
<p>De Casteljau Algorithm is a recursive method to evaluate points on a Bezier curve.</p>
<p><a href="/blog/attachments/2009/08/decasteljau.png"><img title="decasteljau" src="/blog/attachments/2009/08/decasteljau.png" alt="decasteljau" width="357" height="180" /></a></p>
<p><a href="/blog/attachments/2009/08/decasteljau.png"></a>To calculate the point halfway on the curve, that is <em>t</em> = 0.5 using De Casteljau's algorithm we (as shown above) find the midpoints on each of the lines shown in green, then join the midpoints of the lines shown in red, then the midpoint of the resulting line is a point on the curve. To find the points for different values of <em>t</em>, just use that ratio to split the lines instead of using the midpoints. Also note that we have actually split the Bezier curve into two. The first defined by P<sub>0</sub>, P<sub>01</sub>, P<sub>012</sub>, P<sub>0123</sub> and the second by P<sub>0123</sub>, P<sub>123</sub>, P<sub>23</sub>, P<sub>3</sub>.</p>
<h2>Curvature</h2>
<p>The curvature of a circle is $latex \frac{1}{r}$.</p>
<p>The curvature of a curve at any point is the curvature of the osculating circle at that point. The osculating circle for a point on a curve is the circle that "just touches" the curve at that point. The curvature of a curve corresponds to the position of the steering wheel of a car going around that curve.</p>
<h2>Uniform B Splines</h2>
<p>Join with C2 continuity.</p>
<p>Any of the B splines don't interpolate any points, just approximate the control points.</p>
<h2>Non-Uniform B Splines</h2>
<p>Only invariant under affine transformations, not projective transformations.</p>
<h2>Rational B Splines</h2>
<p>Rational means that they are invariant under projective and affine transformations.</p>
<h2>NURBS</h2>
<p>Non-Uniform Rational B Splines</p>
<p>Can be used to model any of the conic sections (circle, ellipse, hyperbola)</p>
<p>=====================</p>
<h1>3D</h1>
<p>When rotating about an axis in OpenGL you can use the right hand rule to determine the + direction (thumb points in axis, finger indicate + rotation direction).</p>
<p>We can think of transformations as changing the coordinate system, where (u, v, n) is the new basis and O is the origin.</p>
<p>$latex \begin{pmatrix}u_x & v_x & n_x & O_x\ u_y & v_y & n_y & O_y\ u_z & v_z & n_z & O_z\ 0 & 0 & 0 & 1 \end{pmatrix}$</p>
<p>This kind of transformation in is known as a local to world transform. This is useful for defining objects which are made up of many smaller objects. It also means to transform the object we just have to change the local to world transform instead of changing the coordinates of each individual vertex. A series of local to world transformations on objects builds up a scene graph, useful for drawing a scene with many distinct models.</p>
<h2>Matrix Stacks</h2>
<p>OpenGL has MODELVIEW, PROJECTION, VIEWPORT, and TEXTURE matrix modes.</p>
<ul>
<li>glLoadIdentity() - puts the Identity matrix on the top of the stack</li>
<li>glPushMatrix() - copies the top of the matrix stack and puts it on top</li>
<li>glPopMatrix()</li>
</ul>
<p>For MODELVIEW operations include glTranslate, glScaled, glRotated... These are post multiplied to the top of the stack, so the last call is done first (ie. a glTranslate then glScaled will scale then translate.).</p>
<p>Any glVertex() called have the value transformed by matrix on the top of the MODELVIEW stack.</p>
<p>Usually the hardware only supports projection and viewport stacks of size 2, whereas the modelview stack should have at least a size of 32.</p>
<h2>The View Volume</h2>
<p>Can set the view volume using,(after setting the the current matrix stack to the PROJECTION stack</p>
<ul>
<li>glOrtho(left, right, bottom, top, near, far)
<a href="/blog/attachments/2009/11/glortho.png"><img title="glOrtho" src="/blog/attachments/2009/11/glortho.png" alt="glOrtho" width="450" height="291" /></a>
(Source: Unknown)</li>
<li>glFrustum(left, right, bottom, top, near, far)
<a href="/blog/attachments/2009/11/glfrustum1.png"><img title="glFrustum" src="/blog/attachments/2009/11/glfrustum1.png" alt="glFrustum" width="450" height="263" /></a>
(Source: Unknown)</li>
<li>gluPerspective(fovy, aspect, zNear, zFar)
<a href="/blog/attachments/2009/11/gluperspective.png"><img title="gluPerspective" src="/blog/attachments/2009/11/gluperspective.png" alt="gluPerspective" width="450" height="254" /></a>
(Source: Unknown)</li>
</ul>
<p>In OpenGL the projection method just determines how to squish the 3D space into the canonical view volume.</p>
<p>Then you can set the direction using gluLookAt (after calling one of the above) where you set the eye location, a forward look at vector and an up vector.</p>
<p>When using perspective the view volume will be a frustum, but this is more complicated to clip against than a cube. So we convert the view volume into the canonical view volume which is just a transformation to make the view volume a cube at 0,0,0 of width 2. Yes this introduces distortion but this will be compensated by the final window to viewport transformation.</p>
<p>Remember we can set the viewport with glViewport(left, bottom, width, height) where x and y are a location in the screen (I think this means window, but also this stuff is probably older that modern window management so I'm not worrying about the details here.)</p>
<h2>Visible Surface Determination (Hidden Surface Removal)</h2>
<p>First clip to the view volume then do back face culling.</p>
<p>Could just sort the polygons and draw the ones further away first (painter's algorithm/depth sorting). But this fails for those three overlapping triangles.</p>
<p>Can fix by splitting the polygons.</p>
<h3>BSP (Binary Space Partitioning)</h3>
<p>For each polygon there is a region in front and a region behind the polygon. Keep subdividing the space for all the polygons.</p>
<p>Can then use this BSP tree to draw.</p>
<pre>void drawBSP(BSPTree m, Point myPos{
if (m.poly.inFront(myPos)) {
drawBSP(m.behind, myPos);
draw(m.poly);
drawBSP(m.front, myPos);
}else{
drawBSP(m.front, myPos);
draw(m.poly);
drawBSP(m.behind, myPos);
}
}
</pre>
<p>If one polygon's plane cuts another polygon, need to split the polygon.</p>
<p>You get different tree structures depending on the order you select the polygons. This does not matter, but some orders will give a more efficient result.</p>
<p>Building the BSP tree is slow, but it does not need to be recalculated when the viewer moves around. We would need to recalculate the tree if the polygons move or new ones are added.</p>
<p>BSP trees are not so common anymore, instead the Z buffer is used.</p>
<h3>Z Buffer</h3>
<p>Before we fill in a pixel into the framebuffer, we check the z buffer and only fill that pixel is the z value (can be a pseudo-depth) is less (large values for further away) than the one in the z buffer. If we fill then we must also update the z buffer value for that pixel.</p>
<p>Try to use the full range of values for each pixel element in the z buffer.</p>
<p>To use in OpenGL just do gl.glEnable(GL.GL_DEPTH_TEST) and to clear the z-buffer use gl.glClear(GL.GL_DEPTH_BUFFER_BIT).</p>
<h2>Fractals</h2>
<h3>L-Systems</h3>
<p>Line systems. eg. koch curve</p>
<h3>Self-similarity</h3>
<ul>
<li>Exact (eg. sierpinski trangle)</li>
<li>Stochastic (eg. mandelbrot set)</li>
</ul>
<h3>IFS - Iterated Function System</h3>
<p>================================================</p>
<h1>Shading Models</h1>
<p>There are two main types of rendering that we cover,</p>
<ul>
<li>polygon rendering</li>
<li>ray tracing</li>
</ul>
<p>Polygon rendering is used to apply illumination models to polygons, whereas ray tracing applies to arbitrary geometrical objects. Ray tracing is more accurate, whereas polygon rendering does a lot of fudging to get things to look real, but polygon rendering is much faster than ray tracing.</p>
<ul>
<li>With polygon rendering we must approximate NURBS into polygons, with ray tracing we don't need to, hence we can get perfectly smooth surfaces.</li>
<li>Much of the light that illuminates a scene is indirect light (meaning it has not come directly from the light source). In polygon rendering we fudge this using ambient light. Global illumination models (such as ray tracing, radiosity) deal with this indirect light.</li>
<li>When rendering we assume that objects have material properties which we denote k<sub>(property)</sub>.</li>
<li>We are trying to determine I which is the colour to draw on the screen.</li>
</ul>
<p>We start with a simple model and build up,</p>
<p>Lets assume each object has a defined colour. Hence our illumination model is $latex I = k_i$, very simple, looks unrealistic.</p>
<p>Now we add ambient light into the scene. Ambient Light is indirect light (ie. did not come straight from the light source) but rather it has reflected off other objects (from diffuse reflection). $latex I = I_a k_a$. We will just assume that all parts of our object have the same amount of ambient light illuminating them for this model.</p>
<p>Next we use the diffuse illumination model to add shading based on light sources. This works well for non-reflective surfaces (matte, not shiny) as we assume that light reflected off the object is equally reflected in every direction.</p>
<h2>Lambert's Law</h2>
<p>"intensity of light reflected from a surface is proportional to the cosine of the angle between L (vector to light source) and N(normal at the point)."</p>
<h2>Gouraud Shading</h2>
<p>Use normals at each vertex to calculate the colour of that vertex (if we don't have them, we can calculate them from the polygon normals for each face). Do for each vertex in the polygon and interpolate the colour to fill the polygon. The vertex normals address the common issue that our polygon surface is just an approximation of a curved surface.</p>
<p>To use gouraud shading in OpenGL use glShadeModel(GL_SMOOTH). But we also need to define the vertex normals with glNormal3f() (which will be set to any glVertex that you specify after calling glNormal).</p>
<p>Highlights don't look realistic as you are only sampling at every vertex.</p>
<p>Interpolated shading is the same, but we use the polygon normal as the normal for each vertex, rather than the vertex normal.</p>
<h2>Phong Shading</h2>
<p>Like gouraud, but you interpolate the normals and then apply the illumination equation for each pixel.</p>
<p>This gives much nicer highlights without needing to increase the number of polygons, as you are sampling at every pixel.</p>
<h2>Phong Illumination Model</h2>
<p>Diffuse reflection and specular reflection.</p>
<div><dl> <dt><a href="/blog/attachments/2009/09/phong_components_version_4.png"><img title="Phong_components_version_4" src="/blog/attachments/2009/09/phong_components_version_4.png" alt="Components of the Phong Model (Brad Smith, http://commons.wikimedia.org/wiki/File:Phong_components_version_4.png)" width="450" height="125" /></a></dt> <dd>Components of the Phong Model (Brad Smith, http://commons.wikimedia.org/wiki/File:Phong_components_version_4.png)</dd> </dl></div>
<p><a href="/blog/attachments/2009/11/reflection_models.png"><img title="reflection_models" src="/blog/attachments/2009/11/reflection_models.png" alt="Source: Lambert" width="450" height="240" /></a>
(Source: COMP3421, Lecture Slides.)</p>
<p>$latex I_s = I_l k_s \cos^n \left ( \alpha \right )$</p>
<p>n is the Phong exponent and determines how shiny the material (the larger n the smaller the highlight circle).</p>
<p>Flat shading. Can do smooth shading with some interpolation.</p>
<p>If you don't have vertex normals, you can interpolate it using the face normals of the surrounding faces.</p>
<p>Gouraud interpolates the colour, phong interpolates the normals.</p>
<h2>Attenuation</h2>
<p>inverse square is physically correct, but looks wrong because real lights are not single points as we usually use in describing a scene, and</p>
<p>For now I assume that all polygons are triangles. We can store the normal per polygon. This will reneder this polygon, but most of the time the polygon model is just an approximation of some smooth surface, so what we really want to do is use vertex normals and interpolate them for the polygon.</p>
<h1>Ray Tracing</h1>
<p>For each pixel on the screen shoot out a ray and bounce it around the scene. The same as shooting rays from the light sources, but only very few would make it into the camera so its not very efficient.</p>
<p>Each object in the scene must provide an intersection(Line2D) function and a normal (Point3D) function</p>
<p>Ray Tree</p>
<p>Nodes are intersections of a light ray with an object. Can branch intersections for reflected/refracted rays. The primary ray is the original ray and the others are secondary rays.</p>
<h1>Shadows</h1>
<p>Can do them using ray tracing, or can use shadow maps along with the Z buffer. The key to shadow maps is to render the scene from the light's perspective and save the depths in the Z buffer. Then can compare this Z value to the transformed Z value of a candidate pixel.</p>
<p>==============</p>
<h1>Rasterisation</h1>
<h2>Line Drawing</h2>
<h3>DDA</h3>
<ul>
<li>You iterate over x or y, and calculate the other coordinate using the line equation (and rounding it).</li>
<li>If the gradient of the line is > 1 we must iterate over y otherwise iterate over x. Otherwise we would have gaps in the line.</li>
<li>Also need to check if x1 is > or < x2 or equal and have different cases for these.</li>
</ul>
<h3>Bresenham</h3>
<ul>
<li>Only uses integer calcs and no multiplications so its much faster than DDA.</li>
<li>We define an algorithm for the 1st octant and deal with the other octant's with cases.</li>
<li>We start with the first pixel being the lower left end point. From there there are only two possible pixels that we would need to fill. The one to the right or the one to the top right. Bresenham's algorithm gives a rule for which pixel to go to. We only need to do this incrementally so we can just keep working out which pixel to go to next.</li>
<li>The idea is we accumulate an error and when that exceeds a certain amount we go up right, then clear the error, other wise we add to the error and go right.</li>
</ul>
<p>We use Bresenham's algorithm for drawing lines this is just doing linear interpolation, so we can use Bresenham's algorithm for other tasks that need linear interpolation.</p>
<h2>Polygon Filling</h2>
<h3>Scan line Algorithm</h3>
<p>The Active Edge List (AEL) is initially empty and the Inactive Edge List (IEL) initially contains all the edges. As the scanline crosses an edge it is moved from the IEL to the AEL, then after the scanline no longer crosses that edge it is removed from the AEL.</p>
<p>To fill the scanline,</p>
<ul>
<li>On the left edge, round up to the nearest integer, with round(n) = n if n is an integer.</li>
<li>On the right edge, round down to the nearest integer, but with round(n) = n-1 if n is an integer.</li>
</ul>
<p>Its really easy to fill a triangle, so an alternative is to split the polygon into triangles and just fill the triangles.</p>
<p>===============</p>
<h1>Anti-Aliasing</h1>
<p>Ideally a pixel's colour should be the area of the polygon that falls inside that pixel (and is on top of other polygons on that pixel) times the average colour of the polygon in that pixel region then multiply with any other resulting pixel colours that you get from other polygons in that pixel that's not on top of any other polygon on that pixel.</p>
<h2>Aliasing Problems</h2>
<ul>
<li>Small objects that fall between the centre of two adjacent pixels are missed by aliasing. Anti-aliasing would fix this by shading the pixels a gray rather than full black if the polygon filled the whole pixel.</li>
<li>Edges look rough ("the jaggies").</li>
<li>Textures disintegrate in the distance</li>
<li>Other non-graphics problems.</li>
</ul>
<h2>Anti-Aliasing</h2>
<p>In order to really understand this anti-aliasing stuff I think you need some basic understanding of how a standard scene is drawn. When using a polygon rendering method (such as is done with most real time 3D), you have a framebuffer which is just an area of memory that stores the RGB values of each pixel. Initially this framebuffer is filled with the background colour, then polygons are drawn on top. If your rending engine uses some kind of hidden surface removal it will ensure that the things that should be on top are actually drawn on top.</p>
<p>Using the example shown (idea from http://cgi.cse.unsw.edu.au/~cs3421/wordpress/2009/09/24/week-10-tutorial/#more-60), and using the rule that if a sample falls exactly on the edge of two polygons, we take the pixel is only filled if it is a top edge of the polygon.</p>
<div><dl> <dt><a href="/blog/attachments/2009/10/aa-pixel.png"><img title="aa-pixel" src="/blog/attachments/2009/10/aa-pixel.png" alt="Anti-Aliasing Example Case. The pixel is the thick square, and the blue dots are samples." width="309" height="197" /></a></dt> <dd>Anti-Aliasing Example Case. The pixel is the thick square, and the blue dots are samples.</dd> </dl></div>
<h3>No Anti-Aliasing</h3>
<p>With no anti-aliasing we just draw the pixel as the colour of the polygon that takes up the most area in the pixel.</p>
<h3>Pre-Filtering</h3>
<ul>
<li>We only know what colours came before this pixel, and we don't know if anything will be drawn on top.</li>
<li>We take a weighted (based on the ratio of how much of the pixel the polygon covers) averages along the way. For example if the pixel was filled with half green, then another half red, the final anti-aliased colour of that pixel would determined by,
Green (0, 1, 0) averaged with red (1, 0, 0) which is (0.5, 0.5, 0). If we had any more colours we would then average (0.5, 0.5, 0) with the next one, and so on.</li>
<li>Remember weighted averages,
$latex \frac{Aa + Bb}{A + B}$
where you are averaging $latex a$ and $latex b$ with weights $latex A$ and $latex B$ respectively.</li>
<li>Pre-filtering is designed to work with polygon rendering because you need to know the ratio which by nature a tracer doesn't know (because it just takes samples), nor does it know which polygons fall in a given pixel (again because ray tracers just take samples).</li>
<li>Pre-filtering works very well for anti-aliasing lines, and other vector graphics.</li>
</ul>
<h3>Post-Filtering</h3>
<ul>
<li>Post-filtering uses supersampling.</li>
<li>We take some samples (can jitter (stochastic sampling) them, but this only really helps when you have vertical or horizontal lines moving vertically or horizontally across a pixel, eg. with vector graphics)</li>
<li>$latex \left ( \frac{6}{9} \right )$ of the samples are Green, and $latex \left ( \frac{3}{9} \right )$ are red. So we use this to take an average to get the final pixel colour of $latex \begin{pmatrix}\frac{1}{3}, & \frac{2}{3}, & 0\end{pmatrix}$</li>
<li>We can weight these samples (usually centre sample has more weight). The method we use for deciding the weights is called the <strong>filter</strong>. (equal weights is called the <em>box filter</em>)</li>
<li>Because we have to store all the colour values for the pixel we use more memory than with pre-filtering (but don't need to calculate the area ratio).</li>
<li>Works for either polygon rendering or ray tracing.</li>
</ul>
<p>Can use adaptive supersampling. If it looks like a region is just one colour, don't bother supersampling that region.</p>
<h3>OpenGL</h3>
<p>Often the graphics card will take over and do supersamling for you (full scene anti aliasing).</p>
<p>To get OpenGL to anti-alias lines you need to first tell it to calculate alpha for each pixel (ie. the ratio of non-filled to filled area of the pixel) using, glEnable(GL_LINE_SMOOTH) and then enable alpha blending to apply this when drawing using,</p>
<pre>glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
</pre>
<p>You can do post-filtering using the accumulation buffer (which is like the framebuffer but will apply averages of the pixels), and jittering the camera for a few times using accPerspective.</p>
<h2>Anti-Aliasing Textures</h2>
<p>A texel is a texture pixel whereas a pixel in this context refers to a pixel in the final rendered image.</p>
<p>When magnifying the image can use bilinear filtering (linear interpolation) to fill the gaps.</p>
<h3>Mip Mapping</h3>
<p>Storing scaled down images and choose closes and also interpolate between levels where needed. Called trilinear filtering.</p>
<p>Rip Mapping helps with non uniform scaling of textures. Anisotropic filtering is more general and deals with any non-linear transformation applied to the texture</p>
<h3>Double Buffering</h3>
<p>We can animate graphics by simply changing the framebuffer, however if we start changing the framebuffer and we cannot change it faster than the rate the screen will display the contents of the frame buffer, it gets drawn when we have only changed part of the framebuffer. To prevent this, we render the image to an off screen buffer and when we finish we tell the hardware to switch buffers.</p>
<p>Can do on-demand rendering (only refill framebuffer when need to) or continuois rendeing (draw method is called at a fixed rate and the image is redrawn regardless of whether the image needs to be updated.)</p>
<h3>LOD</h3>
<p>Mip Mapping for models. Can have some low poly models that we use when far away, and use the high res ones when close up.</p>
<h2>Animation</h2>
<p>Key-frames and tween between them to fill up the frames.</p>
<p>===============</p>
<h1>Shaders</h1>
<p>OpenGL 2.0 using GLSL will let us implement out own programs for parts of the graphics pipeline particularly the vertex transformation stage and fragment texturing and colouring stage.</p>
<p>Fragments are like pixels except they may not appear on the screen if they are discarded by the Z-buffer.</p>
<h2>Vertex Shaders</h2>
<ul>
<li>position tranformation and projection (set gl_Position), and</li>
<li>lighting calculation (set gl_FrontColor)</li>
</ul>
<h2>Fragment Shaders</h2>
<ul>
<li>interpolate vertex colours for each fragment</li>
<li>apply textures</li>
<li>etc.</li>
</ul>
<p>set gl_FragColor.</p>
COMP3421 - Lec 2 - Transformations
/blog/archive/2009/08/comp3421___lec_2___transformations.html
/blog/archive/2009/08/comp3421___lec_2___transformations.htmlSun, 23 Aug 2009 16:10:53 +1000<h2>Homogeneous Coordinates</h2>
<p>Interestingly we can use the extra dimension in homogeneous coordinates to distinguish a point from a vector. A point will have a 1 in the last component, and a vector will have a 0. The difference between a point and a vector is a bit wish washy in my mind so I'm not sure why this distinction helps.</p>
<h2>Transforming a Point</h2>
<p>Say we have the 2D point $latex (x, y)$. This point as a column vector in homogeneous coordinates is $latex \begin{pmatrix} x \ y \ 1 \end{pmatrix}$. For a multiplication between this vector and a transformation matrix (3 by 3) to work we need to do the matrix times the vector (in that order) to give the translated vector, $latex Av = v'$.</p>
<h2>Combining Transformations</h2>
<p>Say we want to do a translation then a rotation (A then B) on the point x. First we must do $latex Ax = x'$, then $latex B(x')$. That is $latex BAx$. The order is important as matrix multiplication in not commutative, ie. $latex AB \ne BA$ (just think a translation then a rotation is not necessarily the same as a rotate then a move (by the same amounts)). If we do lots of transformations we may get something like $latex DCBAx$, this is in effect doing transformation A then B then C then D. (Remember matrix multiplication is associative, i.e. $latex (AB)C = A(BC)$).</p>
<p>As a side note, if you express your point as a row vector (eg. $latex \begin{pmatrix} x & y & z & 1\end{pmatrix}$), then to do a transformation you must do $latex xA$ (where x is the point/row vector). In this case $latex xABC$ is equivalent to doing transformation A on point x, then transformation B then C (apparently this is how DirectX works).</p>
<h2>Affine Transformations</h2>
<p>Affine transformations are a special kind of transformation. They have a matrix form where the last row is [0 ... 0 1]. An affine transformation is equivalent to a linear transformation followed by a translation. That is, $latex \begin{bmatrix} \vec{y} \ 1 \end{bmatrix} = \begin{bmatrix} A & \vec{b} \ \ 0, \ldots, 0 & 1 \end{bmatrix} \begin{bmatrix} \vec{x} \ 1 \end{bmatrix}$ is the same as $latex \vec{y} = A \vec{x} + \vec{b}$.</p>
<p>Something interesting to note is, the inverse transformation of an affine transformation is another affine transformation, whose matrix is the inverse matrix of the original. Also an affine transformation in 2D is uniquely defined by its action on three points.</p>
<p>From page 209 of the text (Hill, 2006), affine transformations have some very useful properties.</p>
<h3>1. Affine Transformations Preserve Affine Combinations of Points</h3>
<p>For some affine transformation T, points P<sub>1</sub> and P<sub>2</sub>, and real's a<sub>1</sub> and b<sub>1</sub> where a<sub>1</sub> + b<sub>1</sub> = 1,</p>
<p>$latex T(a_1P_1 + a_2P_2) = a_1T(P_1)+a_2T(P_2)$</p>
<h3>2. Affine Transformations Preserve Lines and Planes</h3>
<p>That is under any affine transformation lines transformed are still lines (they don't suddenly become curved), similarly planes that are transformed are still planes.</p>
<h3>3. Parallelism of Lines and Planes is Preserved</h3>
<p>"If two lines or planes are parallel, their images under an affine transformation are also parallel." The explanation that Hill uses is rather good,</p>
<p>Take an arbitrary line A + <strong>b</strong>t having direction <strong>b</strong>. It transforms to the line given in homogeneous coordinates by M(A + <strong>b</strong>t) = MA + (M<strong>b</strong>)t, this transformed line has direction vector M<strong>b</strong>. This new direction does not depend on point A. Thus two different lines $latex A_1 + \mathbf{b}t$ and $latex A_2 + \mathbf{b}t$ that have the same direction will transform into two lines both having the direction $latex M\mathbf{b}$, so they are parallel. The same argument can be applied to planes and beyond.</p>
<h3>4. The Columns of the Matrix Reveal the Transformed Coordinate Frame</h3>
<p>Take a generic affine transformation matrix for 2D,</p>
<p>$latex M = \begin{pmatrix}a & b & c\ d & e & f\ 0 & 0 & 1 \end{pmatrix}$</p>
<p>The first two columns, $latex \mathbf{m_1} = \begin{pmatrix}a \ d\ 0\end{pmatrix}$ and $latex \mathbf{m_2} = \begin{pmatrix}b \ e\ 0\end{pmatrix}$, are vectors (last component is 0). The last column $latex \begin{pmatrix}c \ f\ 1\end{pmatrix}$ is a point (last component is a 1).</p>
<p>Using the standard basis vectors $latex \mathbf{i} = \begin{pmatrix}1 \ 0\ 0\end{pmatrix}$, $latex \mathbf{j} = \begin{pmatrix}0 \ 1\ 0\end{pmatrix}$ with origin $latex \phi = \begin{pmatrix}0 \ 0\ 1\end{pmatrix}$, notice that <strong>i</strong> transforms to the vector $latex \mathbf{m_1}$. $latex \mathbf{m_1} = M\mathbf{i}$. Similarily for $latex \mathbf{j}$ and $latex \phi$.</p>
<h3>5. Relative Ratios are Preserved</h3>
<h3>6. Area's Under an Affine Transformation</h3>
<p>Given an affine transformation as a matrix M,</p>
<p>$latex \frac{\mbox{area after transformation}}{\mbox{area before transformation}} = |\mbox{det} M|$</p>
<h3>7. Every Affine Transformation is Composed of Elementary Operations</h3>
<p>Every affine transformation can be constructed by a composition of elementary operations (see below). That is,</p>
<p>$latex M = (\mbox{shear})(\mbox{scale})(\mbox{rotation})(\mbox{translation})$</p>
<p>For a 2D affine transformation M. In 3D,</p>
<p>$latex M = (\mbox{scale})(\mbox{rotation})(\mbox{shear}<em>1)(\mbox{shear}</em>2)(\mbox{translation})$</p>
<h2>Rotations</h2>
<p>Euler's theorem: Any rotation (or sequence of rotations) about a point is equivalent to a single rotation about some coordinate axis through that point. Pages 221-223 of Hill give a detailed explanation of this, as well as the equations to go from one form to the other.</p>
<h2>W2V (Window to Viewport Mapping)</h2>
<p>A simplified OpenGL pipeline applies the modelview matrix, projection matrix, clipping, then the viewport matrix. The viewport matrix is the window to viewport map.</p>
<p>The window coordinate system is somewhere on the projection plane. These coordinates need to be mapped to the viewport (the area on the screen)</p>
<h2>References</h2>
<p>F.S. Hill, et al. (2006). Computer Graphics using OpenGL. Second Ed.</p>
<!-- p, li { white-space: pre-wrap; } -->
COMP3421 - Lec 1 - Colour
/blog/archive/2009/08/comp3421___lec_1___colour.html
/blog/archive/2009/08/comp3421___lec_1___colour.htmlSat, 22 Aug 2009 09:29:25 +1000<h2>Colour</h2>
<p>Pure spectral light, is where the light source has just one single wavelength. This forms monochromatic (or pure spectral) colours.</p>
<p><a href="/blog/attachments/2009/07/spectrum.png"><img class="aligncenter size-full wp-image-647" title="spectrum" src="/blog/attachments/2009/07/spectrum.png" alt="spectrum" width="450" height="51" /></a></p>
<p>However mostly light is made up of light of multiple wavelengths so you end up with a distribution of wavelengths. You could describe colour by this frequency distribution of wavelengths. For example brown is not in the spectrum, but we can get brown from this distribution of different light wavelengths,</p>
<p>[caption id="attachment_648" align="aligncenter" width="374" caption="Spectral Distribution for a Brown Colour (http://www.cs.rit.edu/~ncs/color/a_spectr.html)"]<a href="/blog/attachments/2009/07/brown_distribution.png"><img class="size-full wp-image-648" title="brown_distribution" src="/blog/attachments/2009/07/brown_distribution.png" alt="brown_distribution" width="374" height="224" /></a>[/caption]</p>
<p style="text-align:left;">We could describe colour like this (as opposed to RGB) but human eyes perceive many different distributions (spectral density functions) as the same colour (that is they are indistinguishable when placed side by side). The total power of the light is known as its luminance which is given by the area under the entire spectrum.</p>
<p style="text-align:left;">The human eye has three cones (these detect light), the short, medium and long cones (we have two kinds of receptors cones and rods, rods are good for detecting in low light but they cannot detect colour or fine detail). The graph below shows how these three cones respond to different wavelengths.</p>
<p>[caption id="attachment_649" align="aligncenter" width="300" caption="(Source: http://en.wikipedia.org/wiki/File:Cones_SMJ2_E.svg)"]<a href="/blog/attachments/2009/07/300px-cones_smj2_e-svg.png"><img class="size-full wp-image-649" title="300px-Cones_SMJ2_E.svg" src="/blog/attachments/2009/07/300px-cones_smj2_e-svg.png" alt="300px-Cones_SMJ2_E.svg" width="300" height="227" /></a>[/caption]</p>
<p style="text-align:left;">So the colour we see is the result of our cones relative responses to RGB light. Because of this the human eye cannot distinguish some distributions that are different, to the eye they appear as the same color, hence you don't need to recreate the exact spectrum to create the same sensation of colour. We can just describe the colour as a mixture of three colours.</p>
<p style="text-align:left;">There are three CIE standard primaries X, Y, Z. An XYZ colour has a one to one match to RGB colour. (See <a href="http://www.cs.rit.edu/~ncs/color/t_spectr.html">http://www.cs.rit.edu/~ncs/color/t_spectr.html</a> for the formulae.)</p>
<p style="text-align:left;">Not all visible colours can be produced using the RGB system.</p>
<p style="text-align:left;">=====</p>
<p style="text-align:left;">Where S, P, N are spectral functions,</p>
<p style="text-align:left;">if S = P then N + S = N + P (ie. we can add a colour to both sides and if they were perceived the same before, they will be percieved the same after)</p>
<p style="text-align:left;">On one side you project $latex S(\lambda)$ on the other you project combinations of A, B and C to give $latex aA(\lambda) + bB(\lambda) + cC(\lambda)$</p>
<p style="text-align:left;">By experimentation it was shown that to match any pure spectral colour $latex \lambda$ you needed the amounts of RGB shown,</p>
<p style="text-align:left;">=====</p>
<p style="text-align:left;">To detirmine the XYZ of a colour from its spectral distribution you need to use the following equations,</p>
<p style="text-align:left;">$latex X= \int_0^\infty I(\lambda)\,\overline{x}(\lambda)\,d\lambda$
$latex Y= \int_0^\infty I(\lambda)\,\overline{y}(\lambda)\,d\lambda$
$latex Z= \int_0^\infty I(\lambda)\,\overline{z}(\lambda)\,d\lambda$</p>
<p style="text-align:left;">Where the $latex \overline{x}$, $latex \overline{y}$ and $latex \overline{z}$ functions are defined as,</p>
<p style="text-align:left;"></p>
<p>[caption id="attachment_705" align="aligncenter" width="446" caption="The CIE 1931 XYZ colour matching functions. (Source: http://commons.wikimedia.org/wiki/File:CIE_1931_XYZ_Color_Matching_Functions.svg CC-BY-SA)"]<a href="/blog/attachments/2009/08/446px-cie_1931_xyz_color_matching_functions-svg.png"><img class="size-full wp-image-705" title="446px-CIE_1931_XYZ_Color_Matching_Functions.svg" src="/blog/attachments/2009/08/446px-cie_1931_xyz_color_matching_functions-svg.png" alt="The CIE 1931 XYZ color matching functions." width="446" height="271" /></a>[/caption]</p>
<h2>CIE Chromaticity Diagram</h2>
<p>We can take a slice of the CIE space to get the CIE chromaticity diagram.</p>
<p><a href="/blog/attachments/2009/08/cie3d.png"><img class="aligncenter size-full wp-image-903" title="cie3d" src="/blog/attachments/2009/08/cie3d.png" alt="(Source: Hill)" width="450" height="365" /></a><a href="/blog/attachments/2009/08/495px-cie1931xy_blank-svg.png"><img class="aligncenter size-full wp-image-904" title="495px-CIE1931xy_blank.svg" src="/blog/attachments/2009/08/495px-cie1931xy_blank-svg.png" alt="Source: http://en.wikipedia.org/wiki/File:CIE1931xy_blank.svg" width="450" height="478" /></a></p>
<h2>RGB</h2>
<p><a href="/blog/attachments/2009/08/fsc_stego_kessler_fig021.jpg"><img class="aligncenter size-full wp-image-711" title="fsc_stego_kessler_fig02" src="/blog/attachments/2009/08/fsc_stego_kessler_fig021.jpg" alt="fsc_stego_kessler_fig02" width="436" height="399" /></a>(r, g, b) is the amount of red, green and blue primaries.</p>
<h2>CMY</h2>
<p>CMY is a subtractive colour model (inks and paint works this way). (c,m,y) = (1,1,1) - (r,g,b).</p>
<p>But inks don't always subtract well so printers usually use a black ink as well using CMYK.</p>
<h2>HSV</h2>
<p>The HSV colour model is really good for allowing the user to select a colour as they choose the hue (colour), saturation (how rich the colour is) and value (how dark the colour is).</p>
<p>[caption id="attachment_712" align="aligncenter" width="450" caption="HSV Colour Cone"]<a href="/blog/attachments/2009/08/450px-hsv_color_cone.png"><img class="size-full wp-image-712" title="450px-HSV_Color_Cone" src="/blog/attachments/2009/08/450px-hsv_color_cone.png" alt="HSV Colour Cone" width="450" height="360" /></a>[/caption]</p>
<h2>Gamut</h2>
<p>Gamut is the range of colours available which is represented as a triangle in the CIE Chromacity diagram. Different devices have different gamuts (for instance the printer and LCD monitor).</p>
<ul>
<li>Gamut Clipping - A shading in one image becomes just a solid colour in the other.</li>
<li>Gamut Scaling - Shading looks the same but the size of the gamut is minimal.</li>
</ul>
<p style="text-align:left;"></p>
A problematic HSC ITG Question (2001 Q5a)
/blog/archive/2009/03/a_problematic_hsc_itg_question__2001_q5a_.html
/blog/archive/2009/03/a_problematic_hsc_itg_question__2001_q5a_.htmlWed, 11 Mar 2009 05:07:55 +1100<p>I discovered this back in 2007 when I was preparing for my HSC exams.</p>
<p>Here is the question (from the <a href="http://www.boardofstudies.nsw.edu.au/hsc_exams/hsc2001exams/pdf_doc/ind_tech_graphics_01.pdf">exam paper here</a>),</p>
<p>[caption id="attachment_310" align="aligncenter" width="450" caption="2001 HSC ITG Q5a"]<a href="/blog/attachments/2009/03/2001q5a.png"><img class="size-full wp-image-310" title="2001q5a" src="/blog/attachments/2009/03/2001q5a.png" alt="2001 HSC ITG Q5a" width="450" height="153" /></a>[/caption]</p>
<p>Firstly I think this question is beyond the scope of the syllabus. The only relevant dot point says,</p>
<blockquote>"Pictorial drawing
<ul>
<li>isometric</li>
<li>perspective (mechanical and measuring point)"</li>
</ul>
</blockquote>
<p>There is no reference to oblique drawing or oblique projection (this was the official answer).</p>
<p>Secondly, and more importantly the examiners say in their Notes from the Marking Centre, "This part was generally well answered; candidates had little trouble in identifying oblique and perspective projection."</p>
<p>They claim that the first one is oblique projection, yet with just the information given its impossible to determine the projection used. For example the drawing given could be of a cube drawn in oblique projection or it could be of another object (shown below) in isometric projection, or some other object in some other projection. There are infinity different projections that it could have been drawn in.</p>
<p>[caption id="attachment_311" align="aligncenter" width="450" caption="An object (I call a Vube) shown in 3rd angle orthogonal which when drawn in isometric looks like a cube in oblique."]<a href="/blog/attachments/2009/03/vube_ortho.png"><img class="size-full wp-image-311" title="vube_ortho" src="/blog/attachments/2009/03/vube_ortho.png" alt="An object (I call a Vube) shown in 3rd angle orthogonal which when drawn in isometric looks like a cube in oblique." width="450" height="431" /></a>[/caption]</p>
<p>[caption id="attachment_312" align="aligncenter" width="450" caption="Vube shown in perspective."]<a href="/blog/attachments/2009/03/vube_persp.png"><img class="size-full wp-image-312" title="vube_persp" src="/blog/attachments/2009/03/vube_persp.png" alt="Vube shown in perspective." width="450" height="430" /></a>[/caption]</p>
<p>The exam paper should have specified that the object in question is a cube.</p>
The Mathematics Behind Graphical Drawing Projections in Technical Drawing
/blog/archive/2008/11/the_mathematics_behind_graphical_drawing_projections_in_technical_drawing.html
/blog/archive/2008/11/the_mathematics_behind_graphical_drawing_projections_in_technical_drawing.htmlSat, 15 Nov 2008 10:48:55 +1100<p><em>In the field of technical drawing, projection methods such as isometric, orthogonal, perspective are used to project three dimensional objects onto a two dimensional plane so that three dimensional objects can be viewed on paper or a computer screen. In this article I examine the different methods of projection and their mathematical roots (in an applied sense).</em></p>
<p>The approach that seems to be used by Technical Drawing syllabuses in NSW to draw simple 3D objects in 2D is almost entirely graphical. I don't think you can say this is a bad thing because you don't always want or need to know the mathematics behind the process, you just want to be able to draw without thinking about this. However to have an appreciation of what's really happening the mathematical understanding is a great thing to learn.</p>
<p>Many 3D CAD/CAM packages available on the market today (such as AutoCAD, Inventor, Solidworks, CATIA, Rhinoceros) can generate isometric, three point perspective or orthogonal drawings from 3D geometry, however from what I've seen they can't seem do other projections such as dimetric, trimetric, oblique, planometric, one and two point perspective. Admittedly I don't think these projections are any use or even needed, but when your at high school and you have to show that you know how do to oblique, et al. it can be a problem when the software cannot do it for you from your 3D model. (So I actually wrote a small piece of software to help with this in <a href="http://andrewharvey4.wordpress.com/2008/11/29/a-custom-drawing-projections-tool/">this article</a>). But to do so, I needed to understand the mathematics behind these graphical projections. So I will try to explain that here.</p>
<p>The key idea is to think of everything having coordinates in a coordinate system (I will use the Cartesian system for simplicity). We can then express all these projections as mathematical transformations or maps. Like a function, you feed in the 3D point, and then you get out the projected 2D point. Things get a bit arbitrary here because an isometric view is essentially exactly the same as a front view. So we keep to the convention that when we assign the axis of the coordinate system we try to keep the three planes of the axis parallel to the three main planes of the object.</p>
<p>[caption id="attachment_107" align="aligncenter" width="450" caption="The three "main" planes of the object are placed parallel to the three planes of the axis. This is how we will choose our axis in relation to the object."]<a href="/blog/attachments/2008/11/model-axis-1.png"><img class="size-full wp-image-107" title="model-axis-1" src="/blog/attachments/2008/11/model-axis-1.png" alt="The three "main" planes of the object are placed parallel to the three planes of the axis. This is how we will choose our axis in relation to the object." width="450" height="416" /></a>[/caption]</p>
<p>We will not do this though,</p>
<p>[caption id="attachment_108" align="aligncenter" width="450" caption="We will not choose it like this..."]<a href="/blog/attachments/2008/11/model-axis-2.png"><img class="size-full wp-image-108" title="model-axis-2" src="/blog/attachments/2008/11/model-axis-2.png" alt="We will not choose it like this..." width="450" height="416" /></a>[/caption]</p>
<p>[caption id="attachment_109" align="aligncenter" width="450" caption="...or this."]<a href="/blog/attachments/2008/11/model-axis-3.png"><img class="size-full wp-image-109" title="model-axis-3" src="/blog/attachments/2008/11/model-axis-3.png" alt="...or this." width="450" height="416" /></a>[/caption]</p>
<p>In fact doing something like that shown just above with the object rotated is how we get projections like isometric.</p>
<p>Now what we do is take the coordinates of each point and "transform" them to get the projected coordinates, and join these points with lines where they originally were. However we can only do this for some kinds of projections, indeed for all the ones I have mentioned in this post this will do but only because these projections have a special property. They are linear maps (affine maps also hold this property and are a superset of the set of linear maps) which means that straight lines in 3D project to straight lines in 2D.</p>
<p>For curves we can just project a lot of points on the curve (subdivide it) and then join them up after they are projected. It all depends what our purpose is and if we are applying it practically. We can generate equations of the projected curves if we know the equation of the original curve but it won't always be as simple. For example circles in 3D under isometric projection become ellipses on the projection plane.</p>
<p>Going back to the process of the projection, we can use matrices to represent these projections where</p>
<p style="text-align:center;">$latex \begin{pmatrix}x'\\ y'\\ z'\end{pmatrix} = \begin{pmatrix}a&b&c\\ d&e&f\\ g&h&i\end{pmatrix}\begin{pmatrix}x\\ y\\ z\end{pmatrix}$</p>
<p>is the same as,</p>
<p style="text-align:center;">$latex x' = ax+by+cz\\ y' = dx+ey+fz\\ z' = gx+hy+iz.$</p>
<p>We call the 3 by 3 matrix above as the matrix of the projection.</p>
<p>Knowing all this, we can easily define orthogonal projection as you just take two of the dimensions and cull the third. So for say an orthographic top view the projection matrix is simply,</p>
<p style="text-align:center;">$latex \begin{pmatrix}1&0&0\\ 0&1&0\\ 0&0&0\end{pmatrix}.$</p>
<p>Now we want a projection matrix for isometric. One way would be to do the appropriate rotations on the object then do an orthographic projection, we can get the projection matrix by multiplying the matrices for the rotations and orthographic projection together. However I will not detail that here. Instead I will show you another method that I used to describe most of the projections that I learnt from high school (almost all except perspectives).</p>
<p>I can describe them as well as many "custom" projections in terms of what the three projected axis look like on the projection plane. I described them all in terms of a scale on each of the three axis, as well as the angle two of the axis make with the projection plane's horizontal.</p>
<p>[caption id="attachment_112" align="aligncenter" width="151" caption="Projection attributes described in terms of the projected axis."]<a href="/blog/attachments/2008/11/pp-description.png"><img class="size-full wp-image-112" title="pp-description" src="/blog/attachments/2008/11/pp-description.png" alt="Projection attributes described in terms of the projected axis." width="151" height="154" /></a>[/caption]</p>
<p style="text-align:left;">Using this approach we can think of the problem back in a graphical perspective of what the final projected drawing will look like rather than looking at the mathematics of how the object gets rotated prior to taking an orthographic projection or what angle do the projection lines need to be at in relation to the projection plane to get oblique, etc. Note also that the <em>x</em>, <em>y</em>, <em>z</em> in the above diagram are the scales of the <em>x</em>, <em>y</em>, <em>z</em> axis respectively. So we can see in the table below that we can now describe these projections in terms of a graphical approach that I was first taught.</p>
<table style="height:183px;border-style:solid;border-width:1px;" border="0" width="289">
<tbody>
<tr>
<td style="width:100px;text-align:center;border-style:solid;border-width:1px;"><strong>Projection</strong></td>
<td style="width:100px;text-align:center;border-style:solid;border-width:1px;"><strong>α (alpha)</strong></td>
<td style="width:100px;text-align:center;border-style:solid;border-width:1px;"><strong>β (beta)</strong></td>
<td style="width:60px;text-align:center;border-style:solid;border-width:1px;"><em><strong>S</strong></em><sub><strong>x</strong></sub></td>
<td style="width:60px;text-align:center;border-style:solid;border-width:1px;"><em><strong>S</strong></em><sub><strong>y</strong></sub></td>
<td style="width:60px;text-align:center;border-style:solid;border-width:1px;"><em><strong>S</strong></em><sub><strong>z</strong></sub></td>
</tr>
<tr>
<td style="width:100px;text-align:center;border-style:solid;border-width:1px;">Isometric</td>
<td style="width:100px;text-align:center;border-style:solid;border-width:1px;">30°</td>
<td style="width:100px;text-align:center;border-style:solid;border-width:1px;">30°</td>
<td style="width:60px;text-align:center;border-style:solid;border-width:1px;">1</td>
<td style="width:60px;text-align:center;border-style:solid;border-width:1px;">1</td>
<td style="width:60px;text-align:center;border-style:solid;border-width:1px;">1</td>
</tr>
<tr>
<td style="width:101px;text-align:center;border-style:solid;border-width:1px;">Cabinet Oblique</td>
<td style="width:100px;text-align:center;border-style:solid;border-width:1px;">45°</td>
<td style="width:100px;text-align:center;border-style:solid;border-width:1px;">0°</td>
<td style="width:60px;text-align:center;border-style:solid;border-width:1px;">0.5</td>
<td style="width:60px;text-align:center;border-style:solid;border-width:1px;">1</td>
<td style="width:60px;text-align:center;border-style:solid;border-width:1px;">1</td>
</tr>
<tr>
<td style="width:101px;text-align:center;border-style:solid;border-width:1px;">Cavalier Oblique</td>
<td style="width:100px;text-align:center;border-style:solid;border-width:1px;">45°</td>
<td style="width:100px;text-align:center;border-style:solid;border-width:1px;">0°</td>
<td style="width:60px;text-align:center;border-style:solid;border-width:1px;">1</td>
<td style="width:60px;text-align:center;border-style:solid;border-width:1px;">1</td>
<td style="width:60px;text-align:center;border-style:solid;border-width:1px;">1</td>
</tr>
<tr>
<td style="width:101px;text-align:center;border-style:solid;border-width:1px;">Planometric</td>
<td style="width:100px;text-align:center;border-style:solid;border-width:1px;">45°</td>
<td style="width:100px;text-align:center;border-style:solid;border-width:1px;">45°</td>
<td style="width:60px;text-align:center;border-style:solid;border-width:1px;">1</td>
<td style="width:60px;text-align:center;border-style:solid;border-width:1px;">1</td>
<td style="width:60px;text-align:center;border-style:solid;border-width:1px;">1</td>
</tr>
</tbody>
</table>
<p style="text-align:left;">Now all we need is a projection matrix that takes in alpha, beta and the three axes scale's and does the correct transformation to give the projection. The matrix is,</p>
<p style="text-align:center;">$latex \begin{bmatrix}x'\\y'\\z'\\1\end{bmatrix}=\begin{bmatrix}S_x\cos\alpha&-S_y\cos\beta&0&0\\ S_x\sin\alpha&S_y\sin\beta&S_z&0\\ 0&0&0&0\\ 0&0&0&1\end{bmatrix}\begin{bmatrix}x\\y\\z\\1\end{bmatrix}$</p>
<p style="text-align:left;">Now for the derivation. First we pick a 3D Cartesian coordinate system to work with. I choose the Z-up Left Hand Coordinate System, shown below and we imagine a rectangular prism in the 3D coordinate system.</p>
<p style="text-align:left;"></p>
<p>[caption id="attachment_114" align="aligncenter" width="450" caption="Block in 3D coordinate system."]<a href="/blog/attachments/2008/11/block-3d.png"><img class="size-full wp-image-114" title="block-3d" src="/blog/attachments/2008/11/block-3d.png" alt="Block in 3D coordinate system." width="450" height="253" /></a>[/caption]</p>
<p style="text-align:left;">Now we imagine what it would look like in a 2D coordinate system using isometric projection.</p>
<p style="text-align:left;"></p>
<p>[caption id="attachment_115" align="aligncenter" width="450" caption="Block in 2D coordinate system (isometric)."]<a href="/blog/attachments/2008/11/block-2d.png"><img class="size-full wp-image-115" title="block-2d" src="/blog/attachments/2008/11/block-2d.png" alt="Block in 2D coordinate system (isometric)." width="450" height="245" /></a>[/caption]</p>
<p style="text-align:left;">As the alpha and beta angles (shown below) can change, and therefore not limited to a specific projection, we need to use alpha and beta in the derivation.</p>
<p style="text-align:center;"><a href="/blog/attachments/2008/11/pp-description.png"><img class="size-full wp-image-112 aligncenter" title="pp-description" src="/blog/attachments/2008/11/pp-description.png" alt="pp-description" width="151" height="154" /></a></p>
<p style="text-align:left;">Now using these simple trig equations below we can deduce the following.</p>
<p style="text-align:center;"><a href="/blog/attachments/2008/11/polar.png"><img class="alignnone size-full wp-image-116" title="polar" src="/blog/attachments/2008/11/polar.png" alt="polar" width="203" height="100" /></a></p>
<p style="text-align:left;">All the points on the <em>xz</em> plane have <em>y</em> = 0. Therefore the <em>x</em>’ and <em>y</em>’ values on the 2D plane will follow the trig property shown above, so:</p>
<p style="text-align:center;">$latex x'=x\cos\alpha$
$latex y' = z + y\sin\alpha$</p>
<p style="text-align:left;">However not all the points lie on the <em>xz</em> plane, <em>y</em> is not always equal to zero. By visualising a point with a fixed <em>x </em>and <em>z </em>value but growing larger in <em>y </em>value, its <em>x</em>’ will become lower, and <em>y</em>’ will become larger. The extent of the <em>x</em>’ and <em>y</em>’ growth can again be expressed with the trig property shown, and this value can be added in the respective sense to obtain the final combined <em>x</em>’ and <em>y</em>’ (separately).</p>
<p style="text-align:center;">$latex x'=x\cos\alpha -y\cos\beta$
$latex y' = z + x \sin \alpha + y \sin \beta$</p>
<p style="text-align:left;">If <em>y</em> is in the negative direction then the sign will automatically change accordingly. The next step is to incorporate the scaling of the axes. This was done by replacing the <em>x</em>, <em>y</em> & <em>z</em> with a the scale factor as a multiple of the <em>x</em>, <em>y</em> & <em>z</em>. Hence,</p>
<p style="text-align:center;">$latex x'=S_x x\cos\alpha -S_y y\cos\beta$
$latex y' = S_z z + S_x x\sin\alpha + S_y y \sin \beta$</p>
<p style="text-align:left;">This can now easily be transferred into matrix form as shown at the start of this derivation or left as is.</p>
<p style="text-align:left;"><strong>References:
</strong>Harvey, A. (2007). <em>Industrial Technology - Graphics Industries 2007
HSC Major Project Management Folio</em>. (<a
href="//tianjara.net/hsc/itg-major-work/ITG_MajorProject_2007_ManagementFolio_Jul09.pdf">Link</a>)</p>
The New Industrial Technology Syllabus (HSC 2010)
/blog/archive/2008/10/the_new_industrial_technology_syllabus__hsc_2010_.html
/blog/archive/2008/10/the_new_industrial_technology_syllabus__hsc_2010_.htmlSat, 18 Oct 2008 06:19:47 +1100<p>Only a couple of days ago the new <a href="http://www.boardofstudies.nsw.edu.au/syllabus_hsc/pdf_doc/ind-tech-st6-syll-untracked.pdf">Industrial Technology Syllabus</a> to be implemented for the HSC in 2010 was released. It appears they finally weaved out a lot of the bugs making it much clearer and much less ambiguous. You wouldn't think it would take them six years to do this, but turns out it did. The syllabus was not redone, rather just amended.</p>
<p>As for the changes... Well I guess the biggest change is the removal the Building and Construction, and Plastics Industries. I can understand the removal of Building and Construction as there is already a Construction VET course available, it's always a shame to see a subject go so bad news for plastics enthusiasts, although it's understandable when it gathers next to zero candidates each year.</p>
<p>The four sections of the course,
<p style="padding-left:30px;">A. Industry study
B. Design and management
C. Workplace communication
D. Industry-specific content and production</p>
<p>have been changed to,
<p style="padding-left:30px;">A. Industry Study
B. Design, Management and Communication
C. Production
D. Industry Related Manufacturing Technology.</p>
<p>They have also separated a lot of the preliminary content from the HSC content. This makes a lot of sense previously it appeared that you were supposed to learn the exact same content in both years. Also they have listed "Students learn about" and "Students learn to" dot points for the Major Work.</p>
<p>The most interesting (to me at least) changes were to that of the Graphics Industries specific content (note that they are now called technologies (collectively as focus areas) rather than industries e.g. you would now say the focus area Graphics Technologies). I support many, if not all of these changes although you get the feeling that this is what the original syllabus writers meant to be in the syllabus but simply forgot about and only now noticed that it was missing. I say this because much of the content from the previous HSC exams was based on material and content that was absent from the syllabus but has now been placed in the 2010 one. The order and categorising of this material has been redone and is much cleaner and nicer now.</p>
<p>For instance we now have oblique drawings (with references to cabinet and cavalier) mentioned in the syllabus along with,</p>
<ul>
<li>A mention of architectural drawings including plans, elevations, sections, footing details, plumbing, electrical and roofing details, council requirements, site plans, set backs, shadow diagrams, landscape plans and colour palette and material selection. Previously they just said we need to know architectural styles and details without any elaboration.</li>
<li>axonometric projection</li>
<li>presentation techniques now include 'fly-thoughs' and prototypes</li>
<li>and equipment includes, both computer software packages AND mechanical drafting equipment rather than just either, scanners, electronic storage mediums such as external hard drives and flash drives (although they could have mentioned the common practice of storing files centrally on a file server in one place for many people to access, which is the much more common practice in the workplace), display folders, appropriate sized paper and stationary.</li>
</ul>
<p>The Multimedia Technologies section also is much better now. It now contains the study of different types of fonts, formatting features, page layout elements for publications, features of graphics such as file formats and resolution, methods of obtaining images, image manipulation and editing, audio features such as sampling rate, file formats, analogue vs. digital, video features like frame rate compression, editing, compositing, animation techniques both 2D and 3D with references to motion capture, virtual reality, along with the world wide web, intellectual property, and the list goes on and on... Don't just go by my description here go read the syllabus document, you will be very pleased with the changes or should I say additions.</p>
<p>If I were doing my HSC again, I know for sure I would have a very hard time choosing between multimedia and graphics technologies. They used to be together as one industry back pre 1999, although I must admit it is too much for someone who has done neither before to master both as one 2U subject. I wish you could do both, but they can't allow that because the industry study, design and communication parts would be too common.</p>
<p>As for the common sections (Industry Study, Design and Management and Communication) the improvements here were good too with much more detail. But it's not just the fact that the document is more detailed, but these details are what you would expect. They are in the right direction and are things that should be included. The Design section reinforces that the major project is not just about production of something, but the design aspects that go into it. The only problem I currently have is where is this design meant to be applied. It should be in the most obvious place, but the way the syllabus refers to production makes this slightly unclear. Timber Products and Furniture Technologies would look at the design aspects of the timber products or furniture product that they were producing. But if you were doing Graphics Technologies, your product is a series of drawings and perhaps related media such as flythoughs, etc. Do you look at the design of these drawings, I would say not, rather you should apply design techniques to the thing you are drawing, whether that be a product, building or a mechanical system. I don't think this has been cleared up.</p>
<p>I haven't been up to date with all things related here, so I may have missed some things. But one thing is for sure that I congratulate the Board for their work on this, and I'm sure many HSC students will benefit immensely from this revised syllabus. The syllabus is in much better shape now. As for the content, well I could argue that the material from the stage 5 graphics technology syllabus is more advanced than that of the stage 6 syllabus, and this should not happen. But as long as the stage 5 course is not a prerequisite, and as long as you have less time to cover industry specific content from the stage 6 course than that of the stage 5 course, there is little that can be done.</p>
<p>(PS. As a self advertisment, my 2007 HSC Industrial Technology Graphics Industries Major Work in its entirety can be downloaded from my site here, <a href="http://andrew.harvey4.googlepages.com/">http://andrew.harvey4.googlepages.com/</a>)</p>
(x,y,z,w) in OpenGL/Direct3D (Homogeneous Coordinates)
/blog/archive/2008/09/_x_y_z_w__in_opengl_direct3d__homogeneous_coordinates_.html
/blog/archive/2008/09/_x_y_z_w__in_opengl_direct3d__homogeneous_coordinates_.htmlMon, 29 Sep 2008 09:33:12 +1000<p>I always wondered why 3D points in OpenGL, Direct3D and in general computer graphics were always represented as (<span style="font-style:italic;">x</span>,<span style="font-style:italic;">y</span>,<span style="font-style:italic;">z</span>,<span style="font-style:italic;">w</span>) (i.e. why do we use four dimensions to represent a 3D point, what's the <span style="font-style:italic;">w</span> for?). This representation of coordinates with the extra dimension is know as homogeneous coordinates. Now after finally getting formally taught linear algebra I know the answer, and its rather simple, but I'll start from the basics.</p>
<p>Points can be represented as vectors, eg. (1,1,1). Now a common thing we want to do in computer graphics is to move this point (translation). So we can do this by simply adding two vectors together,</p>
<p style="text-align:center;">$latex \begin{pmatrix}x'\\y'\\z'\end{pmatrix} = \begin{pmatrix}x\\y\\z\end{pmatrix} + \begin{pmatrix}a\\b\\c\end{pmatrix} = \begin{pmatrix}x + a\\y + b\\z + c\end{pmatrix}.$</p>
<p style="text-align:left;">If we wanted do some kind of linear transformation such as rotate about the origin, scale about the origin, etc, then we could just multiply a certain matrix with the point vector to obtain the image of the vector under that transformation. For example,</p>
<p style="text-align:center;">$latex \begin{pmatrix}x'\\ y'\\ z' \end{pmatrix} = \begin{pmatrix}\cos \theta &-\sin \theta &0\\ \sin \theta &\cos \theta &0\\ 0&0&1\end{pmatrix} \begin{pmatrix}x\\ y\\ z\end{pmatrix}$</p>
<p style="text-align:left;"></p>
<p style="text-align:left;">will rotate the vector (<span style="font-style:italic;">x</span>,<span style="font-style:italic;">y</span>,<span style="font-style:italic;">z</span>) by angle theta about the <span style="font-style:italic;">z</span> axis.</p>
<p>However as you may have seen you cannot do a 3D translation on a 3D point by just multiplying a 3 by 3 matrix by the vector. To fix this problem and allow all affine transformations (linear transformation followed by a translation) to be done by matrix multiplication we introduce an extra dimension to the point (denoted <span style="font-style:italic;">w</span> in this blog). Now we can perform the translation,</p>
<p style="text-align:center;">$latex \mathbb{R}^2 : (x,y) \to (x+a, y+b)$</p>
<p>by a matrix multiplication,</p>
<p style="text-align:center;">$latex \begin{pmatrix}1 & 0 & a\\ 0 & 1 & b\\ 0 & 0 & 1\end{pmatrix} \begin{pmatrix}x\\ y\\ 1\end{pmatrix} = \begin{pmatrix}x + a\\ y + b\\ 1 \end{pmatrix}.$</p>
<p>We need this extra dimension for the multiplication to make sense, and it allows us to represent all affine transformations as matrix multiplication.</p>
<p><span style="font-size:85%;">REFERENCES:
Homogeneous coordinates. (2008, September 29). In <em>Wikipedia, The Free Encyclopedia</em>. Retrieved 04:33, September 29, 2008, from <a class="external free" title="http://en.wikipedia.org/w/index.php?title=Homogeneous_coordinates&oldid=241693659" rel="nofollow" href="http://en.wikipedia.org/w/index.php?title=Homogeneous_coordinates&oldid=241693659">http://en.wikipedia.org/w/index.php?title=Homogeneous_coordinates&oldid=241693659</a></span></p>