Wednesday, February 11, 2009

COMPUTER GRAPHICS

1. Introduction and Applications 3 Hrs
History (From simple picture to photo realism), What is CG, GUI
Applications: Presentation graphics, painting and drawing, photo editing, scientific visualization, image processing, digital art, education and training, entertainment, CAD in architecture, mechanical engineering, aeronautical and automobile industry, simulation, animation, video games
2. Graphic Devices 3 Hrs
Display devices: Random-scan and Raster scan monitors, Color CRT, Plasma panel displays, LCD Panels,
Plotters, Film recorders,Graphics workstations, Display processors, Graphics software, Input/Output Devices,touch panels, light pens, graphics tablets,
3. 2D Drawing Geometry 10 Hrs
MathemAtics for computer graphics: A brief concept of Trigonometry, Polar coordinates Parametric Functions, Vectors (scalar product, cross product), Matrices (scalar multiplication, matrix addition and multiplication, matrix inverse)
2D transformation: Use of homogeneous coordinate systems, Translation, scaling, rotation, mirror reflection, Rotation about an arbitrary point, Zooming and panning, Rubber band methods, dragging, Parametric representation of a line segment
5. 2D & 3D Transformations
Brock University
COSC 3P98 Computer Graphics
Instructor: Brian Ross
________________________________________
________________________________________
2d transform composition
• the order we perform multiple transforms can matter
o eg. translate + scale can differ from scale + translate
o eg. rotate + translate can differ from translate + rotate
o eg. rotate + scale can differ from scale + rotate (when scale_x differs from scale_y)
• When does M1 + M2 = M2 + M1?
M1 M2
translate translate
scale scale
rotate rotate
scale (sx = sy) rotate
• To prove commutativity (or lack thereof), show that the composed transformation matrices are the same (or different).
________________________________________
Combined form for 2d Transforms
| r11 r12 tx |
M = | r21 r22 ty |
| 0 0 1 |
• upper 2 by 2 submatrix is a composite rotation & scale matrix;
o t1 and t2 are composed translations
• precise form of matrix expressions depends upon order of transforms
________________________________________
Coordinate systems: Local and Global
• With no transformations, there is one global coordinate system in which objects are drawn.
• When you apply any transformation, this is equivalent to changing the coordinate system. You are defining a local coordinate system within the global system.
• For example, if you set the scale to 0.5, and then draw a box, that box's coordinate system is 0.5 relative to the global coordinate system.
• Thinking of transformations as changing the coordinate systems is very useful conceptually, since in most scenes, objects transforms are defined relative to one, but the objects themselves are drawn without regard to the transforms applied to them. This is most easily imagined as if they had differing coordinate systems.
________________________________________
2d transforms: OpenGL implementation
• OpenGL is immediate mode: graphics operations are applied 'instantly'
o in terms of transformations, the user gives a rotate, translate, or scale command, and the matrix multiplication represented by that transform is immediately applied to a global transformation matrix
o In other words, a 4 by 4 matrix of floating point values is maintained. It changes each time a single transformation is done. However, all the individual transformations used to derive these numeric values are not retained.
________________________________________
2d transforms: OpenGL
• OpenGL transformation commands set up a 4 by 4 transformation matrix, in the way shown on previous overheads
o Can use glGet(GL_MODELVIEW_MATRIX) to retrieve this matrix, and glLoadMatrix to replace it with your own matrix.
• we haven't talked about 3d transforms; however, note that homogeneous 3d transformation matrix is 4 by 4; 2D uses subset of it.
• glRotate{fd} (TYPE angle, TYPE x, TYPE y, TYPE z)
o TYPE is f or d
o rotates the current transformation matrix counterclockwise 'angle' degrees about a ray from the origin through the point (x, y, z)
o eg. glRotatef(45.0, 0.0, 0.0, 1.0) rotates 45 degrees about the z-axis
• glTranslate {fd} (TYPE x, y, z)
o translates by the amounts x, y, z
o note: glTranslatef(): empty argument is the identity matrix
• glScale {fd} (TYPE x, y, z)
o applies x, y, z scaling factors
o eg. glScalef(2.0, -0.5, 1.0)
________________________________________
OpenGL: Order of transformation operations
• When giving OpenGLtransformation commands, they are applied in the inverse order you give them.
glScaled(1.0, 1.0, 3.0);
glRotatef(45.0, 0.0, 1.0, 0.0);
glTranslatef(3.0, 2.0, 0.0);
draw_my_triangle();
• the transformations occur in the reverse order
o This is done to reflect the algebraic order of the matrix transforms:
S * R * T * P = S * (R * (T * P) )
________________________________________
2D Transformation inversions
T(dx, dy) * T(-dx, -dy) = 1
R( A) * R(- A) = 1
S(sx, sy) * S( 1/sx, 1/sy) = 1
To invert a sequence of transforms P' = M * P = (Tr1 * Tr2 * ... * TrK) * P
M^(-1) * P = (Tr1 * Tr2 * ... * TrK)^(-1) * P = TrK^(-1) * ... * Tr2^(-1) * Tr1^(-1) * P
• note how matrix/vector notation is useful here!
________________________________________
OpenGL: Saving and restoring contexts
• Previously mentioned that OpenGL does not save individual transformations.
o Implies that application program must retain all the individual transformations, if one ever wants to "undo" them!
• glPushmatrix(), glPopmatrix(): save and restore transformation matrices
o you essentially modify & use top matrix on the stack
o initialize to identity matrix with: glLoadIdentity()
o Using glPushmatrix() lets you save your current local coordinate system, by copying top (current) transformation matrix onto top of stack.
o Subsequent transformations manipulate top matrix in stack.
--> Transformations compound and accumulate into one general transformation.
o glPopmatrix() then reverts back to previous local coordinate system.
 Equivalent to applying the inversions of all the transforms done in the meantime.
• Extremely useful when rendering hierarchical scenes

________________________________________
OpenGL Matrix Modes
• OpenGL has separate transformation matrices for different graphics features
• glMatrixMode(GLenum mode), where mode is one of:
o GL_MODELVIEW - for manipulating model in scene (stack of them for glPushMatrix)
o GL_PROJECTION - perspective orientation
o GL_TEXTURE - texture map orientation
• Make sure you specify glMatrixMode(GL_MODELVIEW) before proceeding with model transformations
• Likewise, specify glMatrixMode(GL_PROJECTION) when you set up your perspective view (in later topic)
• glLoadIdentity(): loads a 4-by-4 identity matrix into the current matrix (whatever mode you're in)
o always initialize with the identity; don't presume it is loaded for you
• Example 2D OpenGL program: Sierpinski Triangles and example output (level=7).
• Here's the output when transformations in wrong order.
________________________________________
Properties of affine transformation matrix M
• lines are preserved (ie. lines remain lines after transform)
• parallelism is preserved
• proportional distances are preserved
o eg. if point P is a fraction F between points A and B before, it will remain so after the transform
• the change in area of any object transformed is:
o (area after transform) / (area before transform) = |determinant M |
________________________________________
2D transforms: Shear transformations ("shearing")

| 1 a 0 | | 1 0 0 |
SHx = | 0 1 0 | SHy = | b 1 0 |
| 0 0 1 | | 0 0 1 |

x' = x + ay x' = x
y' = y y' = bx + y
• ... a proportional change in x as a function of y (and vice versa)

________________________________________
3D Transforms
• 3D space: add a Z coordinate (X, Y, Z)
o 3D homogeneous coordinates: 4 dimensions
• Text and OpenGL use a Right-handed rotation system: grab the Z axis with right hand, and curl fingers from +ve X axis to +ve Y axis: thumb points out at you, which is direction of +ve Z axis
o implies that +ve Z axis points at you when facing the screen with +ve Y pointing up and +ve X pointing right

________________________________________
3D transforms
• All transformations directly extend to 3D
• Translation:
| 1 0 0 dx |
T(dx,dy,dz) = | 0 1 0 dy |
| 0 0 1 dz |
| 0 0 0 1 |
• Scaling:
| sx 0 0 0 |
S(sx,sy,sz) = | 0 sy 0 0 |
| 0 0 sz 0 |
| 0 0 0 1 |
• Rotation:
| 1 0 0 0 |
Rx(A) = | 0 cos A -sin A 0 |
| 0 sin A cos A 0 |
| 0 0 0 1 |

| cos A 0 sin A 0 |
Ry(A) = | 0 1 0 0 |
| -sin A 0 cos A 0 |
| 0 0 0 1 |

| cos A -sin A 0 0 |
Rz(A) = | sin A cos A 0 0 |
| 0 0 1 0 |
| 0 0 0 1 |
________________________________________
3d transforms
• 2D rotations is given by Z axis rotation matrix
• Note that rotation matrix about Y axis uses "different' signs
o reason: when you look down Y axis, you have this:

z' = z cos A - x sin A
x' = z sin A + x cos A (as before)
--> but when you put these in matrix form, the X and Z are in reversed order, hence the sign change
• All these transformation matrices have inverses similar to 2D case
________________________________________
3D transforms
• composing 3D transforms works same as 2D: write each transformation matrix in the order the transformation sequence is done
o translation & rotations on same axes are additive, while scaling is multiplicative
o however, note that rotations on different axis are NOT commutative!
• general transform:
| r11 r12 r13 tx |
M = | r21 r22 r23 ty |
| r31 r32 r33 tz |
| 0 0 0 1 |
• one trick: inverse of the top-left 3 x 3 submatrix: transpose it
| r11 r12 r13 |
R = | r21 r22 r23 |
| r31 r32 r33 |

| r11 -r21 r13 |
R^(-1) = (1/Det R)* | -r12 r22 -r32 |
| r31 -r23 r33 |
________________________________________
3D transform properties
• lines are preserved
• parallelism is preserved
• proportional distances are preserved
• (volume after transformation) / (volume before) = | det M |
• Example 3D Opengl program:Sierpinski Pyramids and example output
________________________________________
Non-affine transform: Fish-eye (angle halver)
• entire X-Y plane mapped to a circle
o phi = tan^(-1)(|P|)
o convert P to Q: Q = s * P (s = scaling factor)
o where s = tan(tan^(-1)(|P|)/2)/(|P|) = |Q|/|P| = tan(phi/2)/|P|
• Fish eye transformation setup(from [Hill 1990])
• Example transformation (from [Hill 1990])
________________________________________
Non-affine transforms: inversion in a unit circle
• Map point P to inverse of its distance from origin
• circles and lines that do not pass through origin map into circles
• Derivation:
o sin(A) = X/(|P|)
o so: X' = 1/(|P|) sin(A) = (1/(|P|))*(X/(|P|)) = X / (|P|^2)
o Q = 1/(|P|^2) * P
o X' = 1/(|P|^2) * X
o Y' = 1/(|P|^2) * Y

• Example unit circle inversions.(from [Hill 1990])
• Circle inversion of a map of the world(from [Hill 1990])
This is Google's cache of http://www.piccolo2d.org/learn/graphics.html. It is a snapshot of the page as it appeared on 8 Sep 2008 02:22:57 GMT. The current page could have changed in the meantime. Learn more
Text-only version
These search terms are highlighted: 2d transformation use homogeneous coordinate systems

• Piccolo2D Home
o Play
o Learn
 About Piccolo2D
 Piccolo2D Patterns
 Getting Started
 API Documentation
 Piccolo2D in Comparison
 Publications
 Developer FAQ
 Graphics Primer
 Basics
 Drawing Abstraction
 Coordinates
 Description Models
 Drawing Shapes
 Rendering
 Text
 Color
 Clipping
 Efficiency
 Geometric Equations
 Implicit Forms
 Explicit Forms
 Parametric Forms
 Control Points
 Geometric Transformations
 Matrix Transformations
 Scaling
 Rotation
 Translation
 Homogeneous Coordinates
 Affine Transformations
 Matrix Composition
 Coordinate Systems
 Piccolo2D
o Download
o Community
o Applications
o Press
o Sponsors


I found an error!
2D Graphics Primer
This section contains an overview of various 2D graphics concepts related to Piccolo2D. This is a huge topic which cannot be covered in depth here. But the basics are presented below. In many cases these lower level details are handled for you by Piccolo2D. But, understanding them will help you to use the framework more efficiently, especially when extending functionality and creating your own types.
Basics
Everything on the screen is graphics. Toolkits, like Java Swing and the .NET Windows Forms library provide ready-made standard widgets, like scrollbars and buttons, that you can add to your GUI. But, if you want to create a custom component, you have to do your own drawing!



Drawing Abstraction
Every computer graphics system (i.e., operating system) offers some notion of a canvas to draw onto.
Usually, the canvases are separated into windows that are distinct from each other, which provide a relative coordinate system and isolation. This abstraction allows the same binary-level application to render onto different kinds of surfaces such as screens, off-screen buffers (i.e., clipboards), and printers, plotters, and direct neural implants...
Most current systems offer a a resolution-independent (or device-independent) API. This is crucial. If all rendering was done in pixels, a 100 pixel rectangle would be about an inch big on most displays, but would be less than 1/10th of an inch big on some printers.
Java offers the Graphics/Graphics2D classes that present this abstraction, and C# offers the System.Drawing.Graphics class.
Coordinates
Device coordinates
Coordinates of the physical device:
• Usually has origin (0, 0) at upper left
• X increases to the right
• Y increases down
• Integral coordinates always has X in [0, width] and Y in [0, height]
• Coordinates correspond to pixels
• Need to know pixel density (DPI - dots per inch) to create a specific-sized object
Window coordinates
Coordinates within an operating system window
• Similar to device coordinates
• Can have out of bounds coordinates which are clipped by the OS
• If there is a frame around the window ("window dressing"), that is outside the dimensions of the window
Physical coordinates
("device-independent coordinates") - correspond to physical measurements
• Defined in universal measurements - inches, millimeters, points (1/72 of an inch)
• Necessary to make graphics the same size independent of device
Model ("local") coordinates
correspond to the object you are defining
• You may want to define an application-specific coordinate system
(i.e. Origin at the center of screen with one "unit" per inch)
• Need to convert between coordinate systems
Transformations
• A "transform" object encapsulates a coordinate system
• A sequence of transforms can efficiently switch coordinate systems
Graphics Description Models
Stroke Model
describes images with strokes of specified color and thickness. There are also several other parameters, such as how the line segments are connected, and whether the line is drawn solid, or with dashes. In addition, strokes can be anti-aliased.
Line from (4,5) to (9,7) in red with a thickness of 5
Circle centered at (19,8) in blue with a radius of 8 and a thickness of 3
...

Dash Styles
End Cap Styles

Miter Join
Round Join
Bevel Join

Unantialiased Line
Antialiased Line
Region Model
describes images with filled areas such as arcs, text, splines, and other shapes - often other stroke objects. The area may be filled with a color, or a more complex fill such as a gradient or texture (known as a paint in Java or a Brush in C#).
Polygon filling (0, 0)-(10, 5)-(5, 10) with yellow
...

Solid Fill
Gradient Fill
Pixel Model
describes images as a discrete number of pixels. Each pixel is specified by a color from one of several possible color models.

NOTE: In practice, graphics are described with a combination of stroke, region, and pixel descriptions.
Drawing Shapes
Java has a generic Shape class with g2.draw() and g2.fill() methods. See java.awt.geom. Including GeneralPath which connects points with lines or curves. It can be rendered resolution-independent, or can be flattened with FlatteningPathIterator
C# has fixed shapes rather than a generic Shape class. See Graphics.DrawEllipse, DrawBezier, DrawCurve, etc. C# also has a generic path called Drawing2D.GraphicsPath, rendered with Graphics.DrawPath.
Rendering Damage/Redraw
In most graphics systems, you override a window's paint method and put all your rendering code there, but you don't actually call that method directly. Instead you will request a render by telling the OS that a portion of the screen is "damaged." It is out of date and needs to be repainted. The OS will collect and merge all the damaged regions and at some point later it will call the window's paint method passing it the full region that needs to be repainted.
In java, you can request that a window be rendered with JComponent.repaint(). In C#, you would use Control.Invalidate. Or, you could just damage a portion of the canvas with repaint(x, y, w, h) in Java or Invalidate(Rectangle) in C#. Remember that these methods only request repaints to happen in the future, they do not happen immediately.
Text
Text is a special kind of graphics for both performance and human reasons. Characters in any font can be represented either as bitmaps or curves.
In some systems, characters are defined as the set of pixels (bitmap) that form each character. This approach is efficient since we need the set of pixels that make up the characters in order to draw them. But, for large font sizes the space required to store all the bitmaps becomes problematic.
Another approach is to store only the outlines of the characters as closed shapes. These character definitions can easily be scaled to any size and converted to bitmaps when necessary. Plus, drawing packages can treat characters as geometric shapes that can be manipulated like other graphical elements.
Typically you will allocate fonts up front, and then use them on demand. See the Font classes in Java and C#. Fonts get measured with Ascent, Descent, Height, Leading, Width, and Kerning. Higher quality text can be drawn with anti-aliasing or more recently, sub-pixel anti-aliasing (e.g., Microsoft Cleartype)
Color
There are various color models, which are not reflected in the API. Rather the API needs to support the color representation of the hardware. There are two basic kinds, Indexed Color (8 bit) and True Color (16, 24, 32 bit).
Indexed color uses an array of color values as a palette. An index into the color table is assigned to each pixel. Using 8 bits per pixel allows only 256 colors.
Models that can represent a large number of colors are called true color. Examples are RGB, HSV, and CMYK. The common 8-bit RGB model assigns a 3 byte value to each pixel, one byte per channel (red, green and blue). This model can represent up to 28 × 28 × 28 or 16,777,216 colors.
Clipping
Clipping, or limiting drawing to a particular area of the screen, is crucial for a window manager. Displayed objects need to be clipped to the bounds of the window in which they are displayed. But, clipping is also necessary for application efficiency and high-end graphics.
Regions, analytical descriptions of shape, are used for the basis of clipping. Regions include algebra for adding/subtracting, manipulating shape and there are various types (rectangular, rectilinear, rectilinear with holes).

Java has the Area class (made of Shapes) and C# has the Region class.
Efficiency
There are various efficiency considerations that must be made when working with 2D computer graphics. Some common mechanisms/considerations include region management (partial redraws), high-level descriptions for networked displays, display lists for complex objects that are redrawn many times, space-time trade-offs (i.e. pre-allocate thumb image and store it, or render it each time).
Geometric Equations
In a drawing program, there are some common problems such as determining what object a user clicked on, finding the nearest object to where the user clicked, or snapping a line to the nearest object. It turns out we can use a few simple geometric equations to aid with these tasks. And, there are different forms of these equations for different uses.
Implicit Forms: F(x, y) = 0
i.e.: Ax + By + c = 0
This type of equation defines a half-space. And, intersecting multiple half-spaces defines polygons. So, this kind of equation can be used to determining if a point is within a region or finding the distance from a line.
Explicit Forms: y = F(x)
i.e. y = Mx + B
Explicit functions are not good for graphics operations, since they don't plug a point in.
Parametric Forms: x = G(t), y = H(t)
i.e.: x = cos(t), y = sin(t) or,
x = x1 + t * (x2 - x1)
y = y1 + t * (y2 - y1)
Here, both x and y are functions of an independent variable. If you plug in some value for t, you can plot a point on the line. The functions x(t) and y(t) vary along the line, as t varies so you can interpolate along a line.
More generally, this is known in the computer graphics world as LERP (linear interpolation):
p = p1 + t * (p2 - p1)
The LERP equation bounds t between 0 and 1. It directly supports animation, computing intersections, scales to multiple dimensions and can be applied to many domains (points, colors, etc.).
Control Points
Used to specify geometry - often accessed through "handles" in an interface

Cubic Bezier Curve
Quad Bezier Curve
Geometric Transformations
Often an application will need to translate (move), scale, rotate, or shear it's graphical elements. This is necessary for almost any animation and many interactions. One way to achieve this would be to modify all of the points in the original object. For example, in a game of asteroids, to move the triangular ship down ten units, you could add 10 to each point in the triangle. The problem with this approach is that it forces you to modify your original object. You will no longer have a copy of the original to revert back to. And for some transformations, it's worse. What if you scale all the points by zero? Then you've lost your data altogether. A better approach would be to save your original object and somehow transform it when you render. This is commonly done in computer graphics with matrices.
Matrix Transformations
We can represent some transformations as 2x2 matrices of the following form.

We can then multiply the matrix by a column vector to apply the transformation to a point.

x′ = Ax + By
y′ = Cx + Dy
Matrices also allow as to represent a sequence of transformations.

Multiplying two matrices of the same size yields another matrix of the same size. So, the three transformations above can actually be represented as a single matrix. As long as we can represent transformations as 2x2 matrices, we can multiple them together to create one representative matrix.
Scaling
One common transformation involves scaling around the origin (0, 0). Here, we multiply all the x-coordinates by some scale factor Sx and we multiply the y-coordinates by some scale factor Sy.
x′ = x × Sx
y′ = y × Sy
If we define P as a point [x, y], we can combine the equations above to get the following representation.
P′ = S ∙ P or,

We can then represent the scale vector as 2x2 matrix.

Rotation
Another common type of transformation is rotation, where we rotate the points by some angle θ.
x′ = x × cos(θ) - y × sin(θ)
y′ = x × sin(θ) + y × cos(θ)
Again, we can represent rotation as a 2x2 matrix.
P′ = R ∙ P or,

Translation
A simple transformation involves adding some offset Tx to all the x-coordinates, and adding some offset Ty to all the y-coordinates. This is known as a translation.
x′ = x + Tx
y′ = y + Ty
If we define P as a point [x, y], we can combine the equations above to get the following representation:
P′ = P + T or,

But, we cannot represent translation as a 2x2 matrix! This means we won't be able to combine it with rotation and scaling transformations through matrix multiplication. The solution is to use homogeneous coordinates.
Homogeneous Coordinates
We can take a 2-dimensional point and represent it as a 3-vector.

We add a third coordinate h to every 2D point, where (x, y, h) represents the point at location (x/h, y/h). We can now represent translation as a 3x3 matrix of the following form.
P′ = T ∙ P or,

We can then change our scale and rotation matrices into 3x3 matrices as well.
P′ = S ∙ P or,

P′ = R ∙ P or,

This may not seem intuitive or exciting. But, it is quite useful for graphics operations because it allows us to combine translation, scale and rotation transformations, simply by using matrix multiplication.
Affine Transformations
The 3x3 matrix that we derived above is called an Affine Transform. It can encapsulate translate, rotate scale, shear and flip transformations. Affine Transformations have various properties.
• Origin may not map to the (0,0)
• Lines map to lines
• Parallell lines remain parallel
• Ratios are preserved
• Closed under composition
Matrix Composition
As we discussed above, we can multiply various matrices together, each of which represent a transformation, in order get one general representation. For example, if we scale, rotate and then translate, we will have done the following.
P′ = ( T ∙ (R ∙ (S ∙ P)))
We can then separate out our matrix.
P′ = ( T ∙ R ∙ S) ∙ P
M = TRS
However, matrix multiplication is not commutative.
M1 ∙ M2 != M2 ∙ M1
To apply a transformation after the current one, we post-multiply the matrix.
P′ = Mnew ∙ Mcurrent P
To apply a transformation first, we pre-multiply.
P′ = Mcurrent ∙ Mnew P
Coordinate Systems
Transforms can manipulate objects or views. If we transform, draw an object, and then transform back, we are manipulating objects. But, if we set a transform once at the beginning and then draw the whole model we are manipulating the view. Actually, we are defining a new coordinate system.
It turns out an affine transform actually defines a coordinate system. Imagine we apply a rotation, followed by a translation. We can think of this as creating a rotated, translated coordinate system, with a new origin.

We can now draw objects as normal using the local coordinates of this new coordinate system. So, if we draw an object a (0, 0), it will appear at the new origin of the new coordinate system. Thinking of things this way is often simpler than thinking about transforming individual objects.
What about Piccolo2D?
For the most part, Piccolo2D handles doing things efficiently for you. The framework implements region management (only repainting the part of the screen that has changed) as well as efficient picking (determining which object the mouse is over). Piccolo2D's activities make it very easy to implement interpolated animations. And, in many cases, you can use convenience methods to transform nodes rather than interacting directly with matrices.
Piccolo2D also has a higher-level model of drawing than the one described above. Rather than drawing lots of shapes to the screen in a one large paint method and then worrying about repainting and picking them, piccolo2d uses an object-oriented approach. You simply add nodes to the scene-graph. Each node knows how to render and pick itself. Instead of invalidating a rectangle and then drawing in the window's paint method, you will change the node's model. For example, you may change its fill color (paint in Java, Brush in C#). Then the node will handle repainting itself with the new color.
Each node also has an affine transform that defines a local coordinate system for that node. Nodes can be arranged hierarchically, where the local coordinate system of a node is product of all the matrices from the root to the given node. So, changing a parent node's transform, will affect the child as well. For more details about coordinate systems, see Piccolo2D Patterns.
Basic 2D Transformations
• Translation
o x’ = x + tx
o y’ = y + ty
• Scale
o x’ = x * sx
o y’ = y * sy
• Shear
o x’ = x + hx * y
o y’ = y + hy * x
• Rotation
o x’ = x * cosq - y * sinq
o y’ = x * sinq + y * cosq

rametric Equations and Polar Coordinates

Parametric Equations
So far, the graphs we have drawn are defined by one equation: a function with two variables, x and y. In some cases, though, it is useful to introduce a third variable, called a parameter, and express x and y in terms of the parameter. This results in two equations, called parametric equations.


Let f and g be continuous functions (functions whose graphs are unbroken curves) of the variable t. Let f (t) = x and g(t) = y. These equations are parametric equations, t is the parameter, and the points (f (t), g(t)) make up a plane curve. The parameter t must be restricted to a certain interval over which the functions f and g are defined.

The parameter can have positive and negative values. Usually a plane curve is drawn as the value of the parameter increases. The direction of the plane curve as the parameter increases is called the orientation of the curve. The orientation of a plane curve can be represented by arrows drawn along the curve. Examine the graph below. It is defined by the parametric equations x = cos(t), y = sin(t), 0≤t < 2Π.

Figure 1.1: A plane curve defined by the parametric equations x = cos(t), y = sin(t), 0 < t≤2Π.
The curve is the same one defined by the rectangular equation x2 + y2 = 1. It is the unit circle. Check the values of x and y at key points like t = , Π, and . Note the orientation of the curve: counterclockwise.

The unit circle is an example of a curve that can be easily drawn using parametric equations. One of the advantages of parametric equations is that they can be used to graph curves that are not functions, like the unit circle.

Another advantage of parametric equations is that the parameter can be used to represent something useful and therefore provide us with additional information about the graph. Often a plane curve is used to trace the motion of an object over a certain interval of time. Let's say that the position of a particle is given by the equations from above, x = cos(t), y = sin(t), 0 < t≤2Π, where t is time in seconds. The initial position of the particle (when t = 0)is (cos(0), sin(0)) = (1, 0). By plugging in the number of seconds for t, the position of the particle can be found at any time between 0 and 2Π seconds. Information like this could not be found if all that was known was the rectangular equation for the path of the particle, x2 + y2 = 1.

It is useful to be able to convert between rectangular equations and parametric equations. Converting from rectangular to parametric can be complicated, and requires some creativity. Here we'll discuss how to convert from parametric to rectangular equations.


The process for converting parametric equations to a rectangular equation is commonly called eliminating the parameter. First, you must solve for the parameter in one equation. Then, substitute the rectangular expression for the parameter in the other equation, and simplify. Study the example below, in which the parametric equations x = 2t - 4, y = t + 1, - âȞ < t < âȞ are converted into a rectangular equation.
parametric
x = 2t - 4, y = t + 1

t =

y = + 1

y = x + 3

By solving for the parameter in one parametric equation and substituting in the other parametric equation, the equivalent rectangular equation was found.

One thing to note about parametric equations is that more than one pair of parametric equations can represent the same plane curve. Sometimes the orientation is different, and sometimes the starting point is different, but the graph may remain the same. When the parameter is time, different parametric equations can be used to trace the same curve at different speeds, for example.
Problem 1.1: Is the following plane curve a function: y = 3t2, x = , 0≤t≤5?
Yes. By examining the graph, you can see that for every x, there is only one f (x).
Parametric Equations and Polar Coordinates


Polar Coordinates

The polar coordinate system consists of a pole and a polar axis. The pole is a fixed point, and the polar axis is a directed ray whose endpoint is the pole. Every point in the plane of the polar axis can be specified according to two coordinates: r, the distance between the point and the pole, and θ, the angle between the polar axis and the ray containing the point whose endpoint is also the pole.



Figure 2.1: The polar coordinate system
The distance r and the angle θ are both directed--meaning that they represent the distance and angle in a given direction. It is possible, therefore to have negative values for both r and θ. However, we typically avoid points with negative r, since they could just as easily be specified by adding Π (or 180o) to θ. Similarly, we typically ask that θ be in the range 0≤θ < 2Π, since there is always some θ in this range corresponding to our point. This doesn't eliminate all ambiguity, however; the pole can still be specified by (0, θ) for any angle θ. But it is true that any other point can be described uniquely with these conventions.

To convert equations between polar coordinates and rectangular coordinates, consider the following diagram:

Figure 2.2: The x and y coordinates in the polar coordinate system
See that sin(θ) = , and cos(θ) = .

To convert from rectangular to polar coordinates, use the following equations: x = r cos(θ), y = r sin(θ). To convert from polar to rectangular coordinates, use these equations: r = sqrtx2+y2, θ = arctan( ).


About Polar Coordinate
to plot data in the 2-dimensional polar coordinate.
In the polar coordinate the data to be plotted are similar to the rectangular coordinate -- (X,Y), but the data represent X="angle" and Y="radius". The data format is the same as the usual two-dim. data. The default unit of angle is radian and the range is 0 to 2*pi. If you want to use a degree unit, set angles degrees.
Let's think about the following two-dimensional data, which are shown in the rectangular coordinate, X range is 0 to 180 degrees, Y range is -1 to 1.

We plot this in the polar coordinate.
gnuplot> set polar

dummy variable is t for curves
gnuplot> set angles degrees
gnuplot> plot "datafile.dat" with lines

Now, adjust the ranges of X and Y, and make the graph square. This is a likely appearance for the polar coordinate plot.
gnuplot> set size square
gnuplot> set xrange [-1:1]
gnuplot> set yrange [-1:1]
gnuplot> replot


to draw lines from data-points to the origin.
In the above example, each (angle, radius) point is connected by a piecewise line. To draw lines from the origin to each data point, use with impules option.
gnuplot> plot "datafile.dat" with impulses


to draw grids.
There are two kinds of grid in the polar coordinate. The first one is to draw them at the major tics, which is controlled by the set grid command. This is the same as the usual rectangular coordinate plot. The other one is circles and radial lines which are drawn by the set grid polar angle command. The angle defines the radial lines interval (default 30 degrees).
gnuplot> set grid polar

The circular grids depend on both the major tics of X and Y axes. In the above figure tics for X and Y are 0.5, so that the circles are drawn at the interval of 0.5. If the major tics are changed as follows, the circular grids are drawn at 0.3,0.5,0.6,0.9, and 1.0.
gnuplot> set xtics 0.5
gnuplot> set ytics 0.3

About Parametric Functions
use of parameters
In the usual 2-dimensional plot of gnuplot, the Y coordinate is expressed by y=f(x), however you can also use a parametric expression which uses the parameter t,
x = f(t)
y = g(t)
With this expression, more complicated functions can be plotted with gnuplot. Note that the 3-dim. plot with two parameters u,v is given in the spherical harmonics section.
First of all, you need to use the command set parametric to tell gnuplot that the function is defined by a parameter. Then, the plot command followed by a function f(t) which is the X-coordinate and a function g(t) for Y-coordinate, is give like, plot f(t),g(t) .

to draw a vertical line
The most simple but it is impossible to express by the y=f(x) form is a vertical line which is x=const. This function can be written as:
x=const
y=t
with the parameter t, when t is varied. The range of t is controlled by the command set trange .
gnuplot> set parametric

dummy variable is t for curves, u/v for surfaces
gnuplot> const=3
gnuplot> set trange [1:4]
gnuplot> set xrange [0:5]
gnuplot> set yrange [0:5]
gnuplot> plot const,t
In this case the vertical line is draw at x=3. Since we used set trange [1:4] , the range of this truncated line is from 1 to 4. If trange not set, the vertical line is drawn from the bottom to top border lines.

to draw a circle, polygons
The parametric expression of a circle is
x=sin(t)
y=cos(t)
and the circle can be drawn if one changes the t parameter from 0 to 2pi. The graph is "squared" here, and the t range is given by an option of plot command.
gnuplot> set parametric

dummy variable is t for curves, u/v for surfaces
gnuplot> set size square
gnuplot> set xrange [-1:1]
gnuplot> set yrange [-1:1]
gnuplot> plot [0:2*pi] sin(t),cos(t)

The parameter t is not changing continuously, and actually this is controlled by the value which is set by the set samples command. The default value is 100. In the case of set samples 8 , gnuplot generates eight t values from zero to 2*pi, and the graph becomes a regular heptagon. If you need a regular N-gon, just type set samples N+1.


The 2-dim. parametric representation is convenient to draw a function which is in a polar coordinate. The 2-dim. polar coordinate has two variables which are radius r and angle theta. The gnuplot parameter t is for the theta, and the radius r is expressed by a function of angle, namely r(t). A (x,y) coordinate is given by
x=r(t)*cos(t)
y=r(t)*sin(t)
The circle is a special case of which r(t)=const. When the radius of circle is proportional to t, you get a spiral.
gnuplot> set xrange [-10*pi:10*pi]
gnuplot> set yrange [-10*pi:10*pi]
gnuplot> plot [0:10*pi] t*sin(t),t*cos(t)

The following example shows r(t)=const*(1+cos(t)), which is called Cardioid.
gnuplot> set parametric

dummy variable is t for curves, u/v for surfaces
gnuplot> r(t) = 1+cos(t)
gnuplot> plot [0:2*pi] r(t)*cos(t),r(t)*sin(t)


exchange X and Y-axes
Functions are normaly expressed by y=f(x), but the parametric expression allows us to make a graph of x=f(y). The y values are the same as t, and the x values are calculated with a function of f(t).
gnuplot> set parametric

dummy variable is t for curves, u/v for surfaces
gnuplot> c=2*pi
gnuplot> set size square
gnuplot> set trange [-c:c]
gnuplot> set xrange [-c:c]
gnuplot> set yrange [-c:c]
gnuplot> plot c*sin(t),t with lines, t,c*cos(t) with impulses
Two functions are shown, one (green stripe) is y=2pi*cos(x), and the other (red solid line) is x=f(t)=2pi*sin(y).
The option with impulse draws a vertical line from the Y=0 axis. If you use with impulses for the red curve which is x=2pi*sin(y), you still get a vertical stripe, not a horizontal one.
System Simulation is the mimicking of the operation of a real system, such as the day-to-day operation of a bank, or the value of a stock portfolio over a time period, or the running of an assembly line in a factory, or the staff assignment of a hospital or a security company, in a computer.

Simulations work by modeling and analyzing the operation of a real system. Instead of building extensive mathematical models by experts, using readily available simulation software non-experts, who are managers but not programmers, can study a system.

A simulation is the execution of a model, represented by a computer program that gives information about the system being investigated. The simulation approach of analyzing a model is opposed to the analytical approach, where the method of analyzing the system is purely theoretical. As this approach is more reliable, the simulation approach gives more flexibility and convenience. The activities of the model consist of events, which are activated at certain points in time and in this way affect the overall state of the system. The points in time that an event is activated are randomized, so no input from outside the system is required. Events exist autonomously and they are discrete so between the execution of two events nothing happens.

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.