CGS 3032 CGS 3032
Popular in Course
Popular in Computer General Studies
This 25 page Class Notes was uploaded by Dr. Fermin Kilback on Friday September 18, 2015. The Class Notes belongs to CGS 3032 at University of Florida taught by Staff in Fall. Since its upload, it has received 22 views. For similar materials see /class/206544/cgs-3032-university-of-florida in Computer General Studies at University of Florida.
Reviews for CGS 3032
Report this Material
What is Karma?
Karma is the currency of StudySoup.
Date Created: 09/18/15
CGS 3032 Interactive Modeling and Animation Feburary 2nd 2007 popMatrix Today switch Examples Outline Processing function learnt pushMatrix The switch Statement v When to use 7 The value at a wrlable successively compared against dlllerenl values Formal pmgramslalammz aeak base value It program statement n EEK detautt pmgrams atemem m aeak N statement mi Example 1 Examples char letter 39Nquot switchletter case 39A39 println Alpha break case 39B println Bravo break default printlnquotNone break Example 2 change canvas code using switch Array What is an array Data structure that holds a group of homogenous elements of a specific type Associate a set of numbers with a single variable name All of these numbers must be of the same data type Similar to vector How to Define Declaration type ltvar7namegt new typesize Example To define an integer array called numbers of size lm numbers new lm5 numbers n How to Use for loop How to refer to an 39 Format individual element of an array Accessed by their position in the array eg numbers1 2 Operation on element in an array Same as normal variable lor lnlliexpresslon loopicondlllon loopiexpression program statement Flow Examples lniiiai Expression loop expression Program statement Example Sine wave Storing input httpwwwprocessingorgIearningexamples storin in uthtml CGS 3032 Interactive Modeling and Animation January 26th 2007 Today Simple nonlinear motion Moving on curve Swing Translation and Rotation Review Animation Linear motion Control Relational operators Logical operators Conditionals if else statement Moving on curve Moving on curve Constant speed in x direction Nonlinear speed in y direction Motion is constraint by the shape of curve Steps Define curve In draw function Drawthe curve Draw the object at current position Swing Pendulum motion Func on a ACOSltwt t Angleofpendulum Pimwm f LCosa with venicala 3 Length 0 yt Lsina wier Am altitude Weight or bob Motion of pendulum F rce of gravity Translate Specifies an amount to displace objects within the display window Syntax translatex y Example fi125 o 0 rect26 26 52 52 translatewidth2 height2 fi0 1250 rect26 26 52 52 Rotation Rotate objects around origin Suppose the origin locates at rotation the center of the image 2D Rotation X y x y 9 y sin9 2D Rotation x rcos f y rsin f x rcosf6 y rsin f6gt Trig Identity x r oosf cos6 r sinf sine y r sinf sine r oosf cos6 Substitute x x cos6 y sine y x sine y cos6 2D Rotation This is easy to capture in matrix form x39 0086 sin6 x y39 sin6 0086 y H R Even though sinq and oosq are nonlinear functions of q x is a linear combination of x and y y is a linear combination of x and y Syntax Rotation rotateiangle rotates object the amount specified by the angle parameter Example Rotate square agaig Changing color CGS 3032 Interactive Modeling and Anhna onl January 12th 2007 Review What is a programming language What is processing How to download install processing How to run publish the code More about of homework 0 Submit all files under applet directory Today Announcement Homework 0 is on WebCT and due on Jan 17 Outline Digital image representation Color representation Draw rectangles using Processing Digital Image Digitalized natural image Representation of a twodimensional image as a finite set of digital values pixels Rectangular grid Digital Image Cont A digital image is a 2 dimensional array of numbers Each number represents the amount of light collected at one location First Processing Function size To define the dimension of the display window in units of pixels For 2D image sizewidth height width integer for the width of the display window in units of pixels height integer For the height of the display window in units of pixels Coordinate System Draw Rectangle Processing uses a Cartesian coordinate system Draws a rectangle to the screen The origin in the upper left FGCKX y width height the x axis extending to the right Paramemrs the y axis extending downwards x integer or float xcoordinate of the rectangle 2 y integer or float ycoordinate of the rectangle width integer or float width of the rectangle mg m height integer or float height of the rectangle Example rect30 20 55 55 Color Representation RGB Color Model Continuous optical spectrum mug 001 Image from httpenwikipediaorg Color models available in processing t ff 12 COIOr mOdel Ry 6d WW Images from digital image processing 2nd ed Three primary colors red green and blue I I Different from the primary colors in the art world 39 By defaUIt 39n process39ng COIQrS are set by HSB color model valchjels between 0 and 255 usrng the RGB color HueSaturationBrightness mo 6 RGB Color Model Cont HSB Color Model Hhueorthecolortype Ssaturationorthe l quotvibrancyquot of the color mi lj tslometimes called the The lower the saturation of a color the more B quotgraynessquot is present and e the more faded the color will appear B the brightness of the color Also represented as V value RD 60 130 Images from httpenwikipediaorg Images from digital image processing 2nd ed Advanced material To change the way Processing interprets color data colorMode method httpwwwprocessingorgreferencecolorMod e htm For more information about these two color models httpenwikipediaorgwikiRGB color model httpenwikipediaorgwikiHSV color space Coloring in Processing Use color and fill color Data type for storing color values Examples 7 colorcl color2041530 7 color 02 FFCCUU fi Sets the color used to fill shapes Exam ple Example 1 Example 3 fill153 color c1 color204 153 0 rect30 20 55 55 color 22 FFCCOO Example 2 fi204 102 o rect30 20 55 55 o 25 50 rect30 20 55 55 CGS 3032 Interactive Modeling and Animation Feburary 9 2007 Outline Review 7 Translation 7 Rotation r Scalin Project submission guideline r Nameyour proiect with tollowing lorrriat ltlastnamegt7ltllrsmamegt ltproiect name 7 One zipped lile lor the project lolder o ay 7 Mechanical Systems 7 Kinematics v Proiectile Motion 7 Linear Kinetics Mechanical Systems What is the mechanical system Certain portion a part or the whole of the object of interest Different types of mechanical systems Particle A system of particles A rigid body A system of linked rigid bodies or an articulated object Kinematics Location r Position of a particle at a given time instance Velocity v The rate of change in position or the rate of displacement dr Acceleration 1 The rate of change in velocity a dt Example Calculate new speed vtAt vtaAt Calculate new location rt At rt vtAt aAt2 Projectile Motion Two dimensional motion Only force the force due to gravity The magnitude of the acceleration g 98 ms2 av g and a e o Do not consider the rotation of the earth Suppose initial location x0 yo velocity vxo vW VXU iXO Xt X0 vxot Example Linear Kinetics Force 0 Equals to the product of its mass and acceleration f 2 ma Two kinds of forces Contact Forces Field forces Linear Kinetics cont Momentum p The amount of motion the particle possesses Equals to the product of its mass and velocity p mv Kinetic energy Energy due to the motion of the particle 1 2 1 Tz mv v 2 P Momentum Conservation Momentum is conserved for any isolated collision For a collision occurring between two objects the total momentum of the two objects before the collision is equal to the total momentum of the two objects after the collision The momentum lost by object 1 is equal to the momentum gained by object 2 Collision Action of objects striking or coming together Involve forces change in velocity Conserve momentum and maybe energy Example Types of Collision Inelastic collision Example rubber ball on a hard surface Conserve momentum but not energy Perfectly inelastic collision Example two lumps of clay Conserve momentum and the two objects stick together Elastic collision Example two billiard balls with no deformations Conserve energy and momentum Example The Three Laws of Motion Law of inertia No velocity change if no external force Law of acceleration I f 2 ma Law of reciprocal actions All forces occur in pairs which are equal in magnitude and opposite in direction Collision of Billiards Reading If assuming no spin httpwwwglenbrookk12ilusgbssciths Conserve energy ClassBBoardhtml Conserve linear momentum httgwwwlightandmattercomhtml bOOkS Procedure 20lCh01ch01html httQtheoryuwinnigegcaghysicsindexht ml Details CGS 3032 Interactive Modeling and Animation l January 24th 2007 Review What we have learnt Variable Scope of variable Functions Processing functions setup draw Today Examples Function Variable Scope Animation Linear motion Control Relational operators Logical operators Conditionals Example Function Draw a set of circles given the center location of these circles the radius of the largest circle and number of Circles void drawitargetint xloc int yloc int size int num float grayvalues 255num float steps sizehum forint i0 iltnum i filligrayvalues ellipsexloc yloc sizei steps sizeisteps Example Function Call drawtarget68 34 200 10 drawtarget152 16 100 3 drawtarget100 144 80 5 Example Variable Scope int a 20 void drawYetAnotherLine void draw strokeO 205 205 a 20 inea O a height stroke155 linea O a height void drawAnotherLine a a 20 drawAnotherLine int a 85 drawYetAnotherLine stroke205 O O inea O a height Animation As simple as it sounds First define the change of the position of objects during time Then write code in draw function to draw objects at position of current time As difficult as it is Hard to define the change of position to make it look real especially for animals Linear Motion Moving at constant speed New location old location speed time interva Example A moving ball Special handling Moving out of image 7 Need to use relatlonal operators loglcal operators and condlllonals ln the code Relational Operators Operator Meaning Example Equal to Count 10 Not equal to Count 10 lt Less than Count lt 10 lt Less than or equal to Count lt 10 gt Greater than Count gt 10 gt Greater than or equal to Count gt 10 Logical Operators Why Make a decision based on multiple conditions What are they Returns false only if both expressions are false Logical OR A B A H B Example True True True True False True False True True False False False for int i5 ilt95 i5 ifi lt 35 ii i gt 60 ine30 i 80 i Logical AND Returns true only if both expressions are true Example for int i5 ilt95 i5 A B AampampB True True True True False False magt35ampampilt60 ine30 i 80 I False True False False False False Logical NOT Conditionals Inverts the Boolean value Select different sets of statements according to of a pression E ex different conditions A IA xampe Making decisions boolean a lalse if US How True False recl30 20 50 50 if else switch False True j me l llne20109080 llne20809010 The if Statement Example Format Calculating the absolute value of an If piggalgnjrstgtement39 integer Condition Ol satis ed if condition ll number lt 0 program statements number inumber statement number 7 number Flow The ifelse Statement The else if Statement Format if condition program statement 1 Format if conditionl program statement 1 else else if condition2 program statement 2 rogram statement 2 l is Slalemel ll 2 Flow Flow One example M condmom program s a emem 1 e se H condmonzj rogram s a emem 2 e se Condmon 2 sans edv res Program S a emem 2 program s a emem 3 No Program s a emem T Program S a emem 3 CGS 3032 Interactive Modeling and Animation January 17th 2007 Review What we have learnt Digital image representation twodimensional 2D discrete signal Color representation RGB RedGreenBlue HSB HueSaturationBrightness Draw rectangles using Processing Processing functions size rect color fi noStrokeO Today Homework 0 is due Outline More about color More about rectangle Draw different 2D shapes using Processing Draw curves using Processing More on Color Movie Changing RGB to HSB Other functions using Processing background 39 lendColor 39 alpha 39 alpha value from a color defines the transparency of a color Others see Color session Small Questions What is the RGB value for rectMode Modifies the location from which rectangles will be drawn rectx y wi height i odel rectModeCDRNERdetault v xy represent the upperlett corner v Width height iepiesentthe Width and height 7 it in mode ll rectMode CORNERS v xy repre ent the upperlett corner v Width height iepiesentthe the opposite corner 7 liih modelll rectModeCENTER v x y representt ecenter v Width height iepiesentthe Width and height Note 7 the mode is in UPPERCASE letters 7 Set the mode betore calling rect tunctlon 2D Shape Primitives elligse1x 1 width height IliQseMode 39 goint X 1 line X1 1x2 239 triangle x1 11 x2 12 x3 13 guad1x1 11 X2 12 x3 13 x4 14 arcx 1 width height start stop CGS 3032 Interactive Modeling and Animation January 29th 2007 Outline Review Simple nonlinear motion Moving on curve Swing Translation and Rotation r more examples see Translorm in processing webpage Today Print out Interaction Mouse location status and motion Output print println Writes to the console area of the Processing environment Helpful for looking at the value of variables Syntax printdata individual eiements can be separated with ioined with the addition operator a can be ct any type number characters etc Exam ie printlndata quotes J and ame as print tunction except curser moves to a new line at the end Example Special Character To print special character n new line t tab back slash double quotation park Interactive Animation Why add Interactivity to Animation Animation changes according to user39s command Not passive Interactive Animation Decision making at playback time Responsive motion The interface to control the playback process Input amp Interaction How to input data amp interact with the computer Mouse Keyboard Microphone Camera Other sensors Information for Mouse Location Position of mouse Motion Moving Dragged Status Pressed Released Mouse Location o Current position is recorded in two variables 7 mouseX 7 mouseY o revious position is recorded in two variables 7 pmouseX 7 pmouseY Example Mouse Status Variables mo usePresse Variable storing it a mouse button is pressed mouseButton Variable indicating which button is pressed EFI39 RIGHT CENTER Mouse Status cont Functions mousePressed Called once after every time a mouse button is pressed mouseReIeased Called every time a mouse button is released Mouse Motion Moving around Moving with no button being pressed v void mouseMoved v Write code in mouseMoved lunction to take actions according to mouse 3 movement Moving with one button being pressed Drag v void mouseDraggedU v Write code in mouseDragged lunction to take actio according to mouse 3 movement while one button is being Example CGS 3032 Interactive Modeling and Animation l Feburary 26 2007 Today Other ways of objects motion animation Key frames Motion Path Constraint motion Other methods normally used in animation software Key frames Predefine the complete positions for certain time frames Motion Path Predefine the change of location rotation and or size of objects along time Only a predefined curve as the trajectory Key frames Animation What are key frames Drawings which are essential to define a movement Contains location of objects at certain time How to complete animation The remaining frames are filled with more drawings called inbetweens Example j if li i H r http wwwcadtutor net Key frames Animation cont Advantage Work with clearly visualized units How to calculate the object s position in the intermediate frames Interpolation Usage e r ai 1 71 Interpolation Constructing new data points from a discrete set of known data points 1 l u l 2 3X7 l 2 3v 7 1 Linear interpolation Polynomial interpolation Spline interpolation l 2 3 4 5 6 http enwikipediaorgwikilnterpolation Readings Motion Path with Time Linear interpolation Motion is specified precisely along time httpenwikipediaorgwikiLinear interpolatio Example Moving object along curve defined by mouse Polynomial interpolation Advantage 3penwikipediaorqwikiPolynomial interpo Iation Precise control over the movement Spline interpolation httpenwikipediaorgwikiNatural cubic spli E Motion Path Object following a predefined curve Additional constraint need to be specified Most time Speed information Others Constant speed need curve length calculation Curvature Examples CGS 3032 Interactive Modeling and Animation Feburary 14 2007 Outline Review More on the elastic collision Equations and calculation Multiple examples Today Multiple Objects Motion Animation Collision detection posteriori methods priorimethods Multiple Objects Motion Animation Calculate following Trajectories Precise motion Resting places of all objects Precise impacts between objects collision Special for animation Real time computation Compromises allowed Collision Detection What is collision detection Algorithms checking for collision When to use Physical simulations Video games Computational geometry How to detect collision posteriort39 methods prI39orI39 methods posteriori methods How Simulation is done by a small time step Each time check if any objects are intersecting Pros No time variable involved No need to be aware of the physical variables such as friction elastic collisions etc Cons Need to correct when objects intersect each other Algorithm for posteriori methods In the drawfunction Update the new location for each object For each pair of objects in scene Check whether objects are intersecting 7 Adjust the location ot these objects it so Draw the scene Note Should set frame rate large enough Some Examples Forcollision between balls Collision happens when diszc1cz S I rz Forcollision between rectangle shapes Collision happens when one corner is inside of the other object Example For Arbitrary Shapes Speedup tordetecting collision between irregular shapes Use bounding box When bounding boxes intersect Precise calculation Approximation pproximate each object as a series of line segments Exam le htpwwwkevlindevcomblogE15