EGR 115 Introduction to Computing for Engineers 3D animation in MATLAB Monday 17 Nov 2014 EGR 115 Introduction to Computing for Engineers.

Slides:



Advertisements
Similar presentations
Getting Started with PowerPoint
Advertisements

Breakout in Greenfoot Barb Ericson
Samuel Lerman Computer Assignment #1 Problem
Force Scenario Solutions
Flash animation For beginners. Lesson objectives To understand how to animate a ball To understand how to loop animations To learn how to use animation.
Microsoft® Small Basic Advanced Games Estimated time to complete this lesson: 1 hour.
Lesson 6: basic plots. Lesson 6 Outline: Plot 1-basic plot commands 1) Figure Line style Marker style Labels and Titles Axes Matlab help LineSpec (colors,
CSC 160 Computer Programming for Non-Majors Lecture #8: Animations I Prof. Adam M. Wittenstein
1 Flash Actionscript Animation. 2 Introduction to Sprites We will now look at implementing Sprites in Flash. We should know enough after this to create.
Insight Through Computing 8. More Practice with Iteration and Conditionals Through Graphics For-Loop Problems Introduce While-Loops.
Physics 151 Week 5 Day 1 Topics Area under a velocity graph
Physics Simple – Pong Medium – Rigid bodies F = ma Circles, spheres, rectangles for collisions Complex – Fluids, clothings, explosions, hair.
Created in 2011 at Liberty High School. Getting Started Overview on Magnet Tool – Graphics – Text – Image – Video – Sound – Wall A Sample Glog How to.
SolidWorks: Extruded Cuts, Fillets, and Patterns Introduction to Robotics.
Animations Flash ActionScript Introduction to Thomas Lövgren
1 Ch5 Circular Motion and Force. 2 Centripetal Force - Swinging Ball Any body rotating about a fixed point will experience a centripetal (center seeking)
Solidworks Lesson 5 - Assembly Configurations and Motion
Click your mouse for next slide Flash – Introduction and Startup Many times on websites you will see animations of various sorts Many of these are created.
Locally Edited Animations We will need 3 files to help get us started at
VIDEO GAME PROGRAMMING Video Game Programming Junior – DigiPutt INSTRUCTOR TEACHER’S ASSISTANT.
Click your mouse for next slide Flash - Motion Tweening Creating a movie frame by frame would be very time consuming It would also be very jerky unless.
Programming games Show your version of Bo the dog. Start cannonball Preview: video, audio work session (cannonball) Homework: Cannonball with ball in a.
Getting Started with MATLAB 1. Fundamentals of MATLAB 2. Different Windows of MATLAB 1.
Project 6 Tumbling Cube Fri, Nov 21, 2003 Due Mon, Dec 8, 2003.
This is what we want to draw Extrude Mirror Round Edges.
Introduction to Matlab & Data Analysis 2015 In this tutorial we will: Build a practical application using GUIDE Learn more about graphical user interface.
Histograms Lecture 14 Sec Tue, Sep 26, 2006.
Ch5 Circular Motion and Force
EGR 115 Introduction to Computing for Engineers Loops and Vectorization – Part 2 Wednesday 15 Oct 2014 EGR 115 Introduction to Computing for Engineers.
EGR 115 Introduction to Computing for Engineers MATLAB Basics 3: Array Operations Monday 08 Sept 2014 EGR 115 Introduction to Computing for Engineers.
Histograms Lecture 14 Sec Fri, Feb 8, 2008.
CS123 Engineering Computation Lab Lab 4 Bruce Char Department of Computer Science Drexel University Spring 2012.
Flash animation For beginners. homework Your homework is over two weeks so please write in each week of your planner for the next two weeks For homework.
Art for New Media TO DO today: 1 - Fireworks Introduction continued - Finish remote rollovers - Rollovers with multiple states (over and hit.
EGR 115 Introduction to Computing for Engineers MATLAB Basics 5: Applications – Vector Math Friday 12 Sept 2014 EGR 115 Introduction to Computing for Engineers.
Game Project 1 Homage to Pong. Project Rules: The primary project is Pong, the design and development of which will be discussed in detail here. If you.
EGR 115 Introduction to Computing for Engineers
EGR 115 Introduction to Computing for Engineers 2D Plotting – Part II Friday 19 Sept 2014 EGR 115 Introduction to Computing for Engineers.
EGR 115 Introduction to Computing for Engineers Graphical User Interface Design in MATLAB - Part 2 Monday 24 Nov 2014 EGR 115 Introduction to Computing.
Histograms Lecture 18 Sec Tue, Feb 17, 2004.
EGR 115 Introduction to Computing for Engineers Loops and Vectorization – Part 1 Monday 13 Oct 2014 EGR 115 Introduction to Computing for Engineers.
EGR 115 Introduction to Computing for Engineers Complex Numbers & 3D Plots – Part 3 Monday 10 Nov 2014 EGR 115 Introduction to Computing for Engineers.
L8. Iteration and Graphics Introduce Matlab Graphics More practice with iteration and boolean-type thinking Warm-up for functions and arrays.
TOOLBOX. The Toolbox Intrinsic Controls - always included in the Toolbox ActiveX Controls - separate files with ocx file extension Insertable Objects.
Histograms Lecture 14 Sec Wed, Sep 29, 2004.
MATLAB Lab Simulating Billiard Game Modify hitball.m and myball.m to simulate 3-cushion billiard game. Rules: –two players –three balls.
GAME:IT Paddle Ball Objectives: Review skills from Introduction Create a background Add simple object control (up and down) Add how to create a simple.
This is what we want to produce Import sketch dimensions Label angles Set the scale Add linear dimensions.
In the last several lessons, you have described translations using coordinates. You have also developed strategies for determining where an object started.
Creating your own Handheld Games Console
Introducing Scratch Learning resources for the implementation of the scenario
Game Maker Tutorials Introduction Clickball IntroductionClickball Where is it? Shooting Where is it?Shooting.
5. Animation Let’s Learn Saengthong School, June – August 2016 Teacher: Aj. Andrew Davison, CoE, PSU Hat Yai Campus
Written by: Itzik Ben Shabat Technion - Israel Institute of Technology Faculty of Mechanical Engineering Laboratory for CAD & Lifecycle Engineering Lab.
Breakout 3D Jeremy Quick.
MOM! Phineas and Ferb are … Aims:
EGR 115 Introduction to Computing for Engineers
Barb Ericson Georgia Institute of Technology June 2007
EEL 3705 / 3705L Digital Logic Design
Drawing Two-Dimensional Shapes with Digital Technology
Flash animation For beginners.
The One Where You Scratch
Go to =>
Breakout in Greenfoot Barb Ericson
Introduction to PowerPoint
Lecture 7: Introduction to Processing
Plotting Signals in MATLAB
Goto “\\ \utilities\Virus_Sfw\Patches”
Providing an area on a PowerPoint slide that users can write into.
Finding the Epicenter.
Presentation transcript:

EGR 115 Introduction to Computing for Engineers 3D animation in MATLAB Monday 17 Nov 2014 EGR 115 Introduction to Computing for Engineers

Lecture Outline Monday 17 Nov 2014 EGR 115 Introduction to Computing for Engineers 3D animation in MATLAB Slide 2 of 14

3D animation in MATLAB Monday 17 Nov 2014 EGR 115 Introduction to Computing for Engineers 3D animation in MATLAB  Let’s animate a pool ball on a frictionless table.  Define the Problem in more detail: o Define the ball as a red unit disk o Define the size of the table as a 10x10 square o Provide a random initial velocity o Provide a random initial position o Ball will bounce if it touches a wall  If it hits a horizantal wall the y-velocity changes sign  If it hits a vertical wall the x-velocity changes sign Slide 3 of 14

3D animation in MATLAB Monday 17 Nov 2014 EGR 115 Introduction to Computing for Engineers  Define the ball as a red unit disk o Use rectangle(…) graphic object to draw the red ball  Define the size of the table as a 10x10 square o Use axis([xmin xmax ymin ymax]) to define the axis limits o Could also use xlim(…) and ylim(…)  Provide a random initial velocity rectangle('Position',[??, ??, 1, 1], 'Curvature',[1,1], 'FaceColor','r'); axis([ ]); % Set the initial velocity vel.x = 5*(rand - 0.5); % X & Y initial velocity (m/sec) vel.y = 5*(rand - 0.5); Slide 4 of 14 Diameter = 1

3D animation in MATLAB Monday 17 Nov 2014 EGR 115 Introduction to Computing for Engineers  Provide a random initial position o Make sure that the ball is on the table!!!  Set an animation time step  Update the position at each time step % Set the initial position (center of the ball) pos.x = 0.5+9*rand; % X & Y initial position (m) pos.y = 0.5+9*rand; dT = 0.1; % Animation time step (sec) pos.x = pos.x + vel.x * dT; % X position update pos.y = pos.y + vel.y * dT; % Y position update Slide 5 of 14

3D animation in MATLAB Monday 17 Nov 2014 EGR 115 Introduction to Computing for Engineers  Ball will bounce if it touches a wall o If it hits a horizantal wall the y-velocity changes sign o If it hits a vertical wall the x-velocity changes sign  Radius of ball is 0.5 !! % Check for bouncing off a wall if pos.y > 9.5 % Hit the top wall vel.y = -vel.y; elseif pos.y < 0.5 % Hit the bottom wall vel.y = -vel.y; end if pos.x > 9.5 % Hit the right wall vel.x = -vel.x; elseif pos.x < 0.5 % Hit the left wall vel.x = -vel.x; end Slide 6 of 14

3D animation in MATLAB First Attempt Monday 17 Nov 2014 EGR 115 Introduction to Computing for Engineers % Set the initial velocity vel.x = 5*(rand - 0.5); % X & Y initial velocity (m/sec) vel.y = 5*(rand - 0.5); % Set the initial position (center of the ball) pos.x = 0.5+9*rand; % X & Y initial position (m) pos.y = 0.5+9*rand; dT = 0.1; % Animation time step (sec) % Animate the pool ball moving while 1 % Run forever % create a circle using rectangle function & handle to object rectangle('Position',[pos.x-0.5, pos.y-0.5, 1, 1],'Curvature',[1,1], 'FaceColor','r'); axis([ ]); pause(dT); % Pause for dT seconds pos.x = pos.x + vel.x * dT; % X position update pos.y = pos.y + vel.y * dT; % Y position update % Check for bouncing off a wall if pos.y > 9.5 % Hit the top wall vel.y = -vel.y; elseif pos.y < 0.5 % Hit the bottom wall vel.y = -vel.y; end if pos.x > 9.5 % Hit the right wall vel.x = -vel.x; elseif pos.x < 0.5 % Hit the left wall vel.x = -vel.x; end Slide 7 of 14 Why not use else here?

3D animation in MATLAB Monday 17 Nov 2014 EGR 115 Introduction to Computing for Engineers Result Slide 8 of 14

3D animation in MATLAB Monday 17 Nov 2014 EGR 115 Introduction to Computing for Engineers Updates:  Only plot the current ball o METHOD#1: Call rectangle once and update the [x, y] position data of the rectangle, or o METHOD#2: Turn the visibility on and off  Reduce the speed with each bounce (simulate friction) o vel = 0.9 * vel;  Exit when the speed drops too low o While |vel| > 0.5, continue Slide 9 of 14

3D animation in MATLAB METHOD#1 – Update ‘Position’ Monday 17 Nov 2014 EGR 115 Introduction to Computing for Engineers % Set the initial velocity vel.x = 5*(rand - 0.5); % X & Y initial velocity (m/sec) vel.y = 5*(rand - 0.5); % Set the initial position (center of the ball) pos.x = 0.5+9*rand; % X & Y initial position (m) pos.y = 0.5+9*rand; dT = 0.1; % Animation time step (sec) h_rect = rectangle('Position',[pos.x-0.5, pos.y-0.5, 1, 1],'Curvature',[1,1], 'FaceColor','r'); axis([ ]); % Animate the pool ball moving while (vel.x^2 + vel.y^2) > 0.5 % Exit when the speed drops too low % create a circle using rectangle function & handle to object pause(dT); % Pause for dT seconds pos.x = pos.x + vel.x * dT; % X position update pos.y = pos.y + vel.y * dT; % Y position update % Check for bouncing off a wall if (pos.y > 9.5) | (pos.y < 0.5) % Hit the top or bottom wall vel.y = -vel.y*0.9; end if (pos.x > 9.5) | (pos.x < 0.5) % Hit the right or left wall vel.x = -vel.x*0.9; end set(h_rect, 'Position', [pos.x-0.5, pos.y-0.5, 1, 1]); end Slide 10 of 14

3D animation in MATLAB METHOD#2 – Update ‘Visibility’ Monday 17 Nov 2014 EGR 115 Introduction to Computing for Engineers Slide 11 of 14 % Set the initial velocity vel.x = 5*(rand - 0.5); % X & Y initial velocity (m/sec) vel.y = 5*(rand - 0.5); % Set the initial position (center of the ball) pos.x = 0.5+9*rand; % X & Y initial position (m) pos.y = 0.5+9*rand; dT = 0.1; % Animation time step (sec) % Animate the pool ball moving while (vel.x^2 + vel.y^2) > 0.5 % Exit when the speed drops too low % create a circle using rectangle function & handle to object h_rect = rectangle('Position',[pos.x-0.5, pos.y-0.5, 1, 1],'Curvature',[1,1],'FaceColor','r'); axis([ ]); pause(dT); % Pause for dT seconds pos.x = pos.x + vel.x * dT; % X position update pos.y = pos.y + vel.y * dT; % Y position update % Check for bouncing off a wall if (pos.y > 9.5) | (pos.y < 0.5) % Hit the top or bottom wall vel.y = -vel.y*0.9; end if (pos.x > 9.5) | (pos.x < 0.5) % Hit the right or left wall vel.x = -vel.x*0.9; end set(h_rect, 'Visible', 'off'); end

3D animation in MATLAB Save the animation to a movie Monday 17 Nov 2014 EGR 115 Introduction to Computing for Engineers Use the MATLAB VideoWriter to save frames to a movie  VideoWriter(filename, profile) 1.First create a writerObject and set file properties 2.Open the file 3.Capture the frames 4.Close the file % Create file to capture video & set file properties writerObj = VideoWriter('bouncing_ball.mp4','MPEG-4'); writerObj.Quality = 90; writerObj.FrameRate = 5; open(writerObj);... frame = getframe; writeVideo(writerObj,frame);... close(writerObj); % Close file after capturing video Slide 12 of 14

3D animation in MATLAB Save the animation to a movie Monday 17 Nov 2014 EGR 115 Introduction to Computing for Engineers Video: Slide 13 of 14 3D Version of the Bouncing ball

Next Lecture Monday 17 Nov 2014 EGR 115 Introduction to Computing for Engineers Graphical User Interface (GUI) Design in MATLAB Slide 14 of 14