Visual Basic: ballistics

Slides:



Advertisements
Similar presentations
Motion in 2 Dimensions Projectile Motion
Advertisements

Section 3-5: Projectile Motion
IS660Z Programming Games Using Visual Basic Overview of Cannonball.
Agenda 1) Warm-Up 5 min 2) Vocab. Words 10 min 3) Projectile Motion Intro. 15 min 4) Pre-Lab Vectors 15 min 5) Vector Lab 30 min Spring scale.
Projectile Motion Neglecting air resistance, what happens when you throw a ball up from the back of a moving truck? Front? Behind? In?
Projectile Motion Notes
Projectile Motion. 2 components of all projectile motion: Horizontal component (vx) is constant. Vertical component (vy) is affected by gravity.
Motion in Two Dimensions
3-3 Projectile Motion Two Dimensional Motion of Objects  Projectile Motion – If air resistance is disregarded, projectiles follow parabolic trajectories.
Motion in 2-Dimensions. Projectile Motion A projectile is given an initial force and is then (assuming no air resistance) is only acted on by gravity.
Introduction to 2-Dimensional Motion. 2-Dimensional Motion Definition: motion that occurs with both x and y components. Each dimension of the motion can.
AIM: How can we describe the path of an object fired horizontally from a height above the ground? DO NOW: A ball rolls off a table top with an initial.
SACE Stage 2 Physics Motion in 2 Dimensions.
Projectile Motion Neglecting air resistance, what happens when you throw a ball up from the back of a moving truck? Front? Behind? In? GBS Physics Demo.
Kinematics in 2-Dimensional Motions. 2-Dimensional Motion Definition: motion that occurs with both x and y components. Example: Playing pool. Throwing.
Projectile Motion Horizontally Launched Projectiles Projectiles Launched at an Angle A.S – Due Friday, 11/14 Text Reference: chapter 3.
Programming games Show your version of Bo the dog. Start cannonball Preview: video, audio work session (cannonball) Homework: Cannonball with ball in a.
Projectile Motion Projectile Fired Horizontally. A cannonball shot from a cannon, a stone thrown into then air, a ball rolling off the edge of table,
Projectile motion.
Projectile Motion Previously, we studied motion in one direction (linear motion) Projectiles follow a curved path (nonlinear motion) The velocity of a.
Chapter 7.2 – Projectile Motion
Ch 3 – Two-Dimensional Motion and Vectors. Scalars vs. Vectors ► Scalar – a measurement that has a magnitude (value or number) only  Ex: # of students,
PHYS 20 LESSONS Unit 2: 2-D Kinematics Projectiles Lesson 5: 2-D Projectiles.
Projectile Motion The motion of an object that is thrown and moves along a curved path through the influence of gravity, only.
Projectiles (2D) A projectile is any object that is in a state of freefall, or in other words an object that is only acted upon by the force of gravity.
Goal: To projectile motions Objectives: 1)To understand freefall motions in 1 D 2)To understand freefall motions in 2D 3)To understand air drag and terminal.
Two-Dimensional Motion and Vectors CP: 6.1 A gun with a muzzle velocity of 1000 ft/sec is shot horizontally. At the same time an identical bullet is.
B2.2.  Projectiles follow curved (parabolic) paths know as trajectories  These paths are the result of two, independent motions  Horizontally, the.
Chapter 3 Kinematics in Two Dimensions. 3.1 – d, v, & a A bullet is fired horizontally. A second bullet is dropped at the same time and at from the same.
PROJECTILE MOTION. Relevant Physics: The Independence of the Vertical and Horizontal directions means that a projectile motion problem consists of two.
CHAPTER 6 MOTION IN 2 DIMENSIONS.
[My] Experiences building games in Visual Basic & Flash Focus on 'cannonball' Jeanine Meyer Math Senior Seminar.
Projectiles at an Angle Hardest thing yet.. A progression: A)Freefall Review: A ball drops for 3 s. How far does it fall? How fast is it going after 3.
CHAPTER 6 SECTION 1 Projectile Motion. Objects launched either horizontally or at an angle are considered to be projectiles. All motion can be analyzed.
To start Which hits the ground first? What assumptions are you making?
Projectiles IB Revision. Gravity does not act sideways gravity makes it accelerate downwards The ball moves with a constant horizontal velocity The ball.
Projectile Motion Chapter 5.4 – 5.6 Notes. Projectile Motion A projectile is any object that moves through the air or space, acted on only by gravity.
Unit 3: Projectile Motion
Physics Support Materials Higher Mechanics and Properties of Matter
(Constant acceleration)
Motion in Two Dimensions EQ: What is a projectile?
Physics Section 3.3 Properties of Projectile Motion
Physics Lesson 6 Projectile Motion
Projectile Motion Horizontal Angular.
3-7 Projectile Motion A projectile is an object moving in two dimensions under the influence of Earth's gravity; its path is a parabola. Figure Caption:
Projectile Motion Physics Honors.
Unit 3: Projectile Motion
Projectile motion.
Unit 3: Projectile & 2D Motion
Projectile Motion Part 2.
Projectile Motion Projectile motion is independent vertical and horizontal motion through the air only under the influence of gravity after a having an.
Unit 3: Projectile & 2D Motion
Projectile Motion.
Projectile Motion.
Chapter 5 Projectile Motion
Warm-Up 09/13/10 Please express the Graphic Vector Addition Sums in MAGNITUDE-ANGLE format (last two pages of PhyzJob packet)
The height of the building
MOTION OF A PROJECTILE Today’s Objectives: Students will be able to:
Demonstration: Projectile Motion
Bellringer What is the difference between the words vertical and horizontal? What does the word projectile mean? How is one dimensional (1D), two dimensional.
Projectile Motion.
Physics Support Materials Higher Mechanics and Properties of Matter
Motion in Two Dimensions EQ: What is a projectile?
MOTION OF A PROJECTILE Today’s Objectives: Students will be able to:
What do you think a “launch” looks like?
A projectile is any object that moves through
Projectile Motion With Air Resistance
Projectile Motion Chapter
In the previous chapter we studied simple straight-line motion—linear motion.
Presentation transcript:

Visual Basic: ballistics Review on timers, animation Resolve vectors Homework: Catch up on projects. Read chapter 6. Try cannonball. Recall bouncing ball demonstrations. Complete (memory), hangman.

Coordinate system Most Visual Basic controls are positioned in terms of Top and Left. Lines are positioned in terms of x1, y1, x2, y2 values. As in most computer systems, the Left/X values increase moving to the right the Top/Y values increase moving DOWN the screen The screen is two dimensional, that is, it takes two numbers to specify a position.

Timer control Properties: Interval and Enabled. If Enabled is True, the timer event happens if Interval is > 0 Interval is set in milliseconds If a timer named timFalling has Enabled set to True and Interval set to 500 then timFalling_Timer will happen every ½ second. Actually half a second is fairly slow for animation. You can use the values suggested in the chapter, but you should also experiment.

Sub timFalling_Timer shpBall.Top = shpBall.Top + shpBall.Height This causes the ball to drop its whole height every ‘interval’. shpBall.Top = shpBall.Top + delta * v_speed Assume delta represents the elapsed time and v_speed represents a speed, this causes the ball to drop an amount equal to time * speed. shpBall.Top = originalTop + T * v_speed This positions the ball each time based on a calculation from originalTop (presumably the starting position), T is the elapsed time. The text makes suggestions for cannonball, but in general, you need to decide if it is best to calculate changes or positions from starting positions.

Bouncing ball Recall that in the timer event, the object was moved horizontally (Left) and vertically (Top) Also, check was made if object struck sides of the form. Speed in each dimension was constant. Timer event had the code checking for going past the sides.

Ballistics Simulation of motion must take gravity into account. Horizontal motion continues with no acceleration (no change) Vertical motion is changed by gravity. “Physics” & computer graphics requires: when cannonball is shot out of cannon at an angle, your code must resolve the initial velocity vector into horizontal and vertical components Velocity is defined as speed and direction This is simplification. There is such a thing as air resistance.

Horizontal scroll bar for setting the velocity leaving the cannon. Command button captioned FIRE! fires the cannon.

Calculating the vectors Angle vx = v * Cos (Theta) vy = v * Sin (Theta) Where v is velocity coming out of cannon, theta is the angle. Angle (traditional name is theta) This is called ‘resolving the vectors’. The trig functions return the horizontal and vertical component of the vector. Think of the horizontal and vertical vectors as adding up to the original vector.

Equations of motion Constant velocity Distance traveled = velocity * time New_position = velocity*time + old_position Acceleration (let g=acceleration) New_velocity = g * time + old_velocity Average velocity = .5 * g*time+old_velocity New_position = .5*g*time*time+old_velocity*time+old_position (Independent of Visual Basic), these are the so-called equations of motion. Distance = speed times time. Change in velocity = acceleration times time. So new velocity is the formula shown. New position is average velocity times time. Average velocity (assuming constant acceleration) is one half the final velocity.

Horizontal and vertical velocities (switching to VB names for variables): X2,Y2 is endpoint of cannon Initial horizontal velocity remains the same: sngXX = sngVx * sngTT + X2 Vertical velocity changes: sngYY = .5 * g *(sngTT * sngTT) - sngVy * sngTT + Y2 This is a restatement of the equations of motion as they apply to the horizontal (constant velocity) and the vertical (constant acceleration) in VB using variable names used in the text. Y2 is the vertical component of the tip of the cannon. The last line of code also takes into account the fact that the vertical goes up moving down the screen.

Overview of cannonball Note: read chapter 6! Command button with caption FIRE! will calculate initial horizontal and vertical velocity from the scroll bar for the speed and the angle of the line representing the cannon Timer event will increment variable for time and apply the equations of motion to the cannonball (a shape control object) Timer event also does calculation to determine if cannonball has hit the ground or hit the target. Mouse events used to drag cannon tip and target. Horizontal scroll bar used for speed. Finish old projects first. I want to see them this lab session or next week.

Staged implementation Cannonball moves through the air. No checks to stop it! Stop execution by clicking on stop button on toolbar. Check for hitting ground or hitting target. Implement event handlers for changing speed, moving tip of cannon. Staged implementation is highly recommended for all but the smallest of projects. This is how we divided the implementation: how I really worked on it, not just saying it for you to do. The professional way is to divide the work. It goes faster!