CMSC 425: Lecture 7 Geometric Programming: Sample Solutions

Similar documents
CMSC 425: Lecture 4 Geometry and Geometric Programming

Chapter 6. Phillip Hall - Room 537, Huxley

Planar Transformations and Displacements

When solving problems involving changing momentum in a system, we shall employ our general problem solving strategy involving four basic steps:

Lecture 1.2 Pose in 2D and 3D. Thomas Opsahl

Math 323 Exam 2 - Practice Problem Solutions. 2. Given the vectors a = 1,2,0, b = 1,0,2, and c = 0,1,1, compute the following:

Micro I. Lesson 5 : Consumer Equilibrium

John Weatherwax. Analysis of Parallel Depth First Search Algorithms

Session 5: Review of Classical Astrodynamics

Calculating the force exerted by the photon on the elementary particle

Use of Transformations and the Repeated Statement in PROC GLM in SAS Ed Stanek

University of Alabama Department of Physics and Astronomy. PH 105 LeClair Summer Problem Set 3 Solutions

MATH 2710: NOTES FOR ANALYSIS

Review! Kinematics: Free Fall, A Special Case. Review! A Few Facts About! Physics 101 Lecture 3 Kinematics: Vectors and Motion in 1 Dimension

Lecture 1.2 Units, Dimensions, Estimations 1. Units To measure a quantity in physics means to compare it with a standard. Since there are many

Chapter 3 2-D Motion

Chapter 3 Kinematics in Two Dimensions; Vectors

Today. CS-184: Computer Graphics. Introduction. Some Examples. 2D Transformations

Approximating min-max k-clustering

Round-off Errors and Computer Arithmetic - (1.2)

(IV.D) PELL S EQUATION AND RELATED PROBLEMS

8 STOCHASTIC PROCESSES

Math 4400/6400 Homework #8 solutions. 1. Let P be an odd integer (not necessarily prime). Show that modulo 2,

Numerical Linear Algebra

Linear diophantine equations for discrete tomography

Elementary Analysis in Q p

0.1 Practical Guide - Surface Integrals. C (0,0,c) A (0,b,0) A (a,0,0)

Projectile Motion: Vectors

ALTERNATIVE SOLUTION TO THE QUARTIC EQUATION by Farid A. Chouery 1, P.E. 2006, All rights reserved

Strong Matching of Points with Geometric Shapes

arxiv: v1 [physics.data-an] 26 Oct 2012

MATH 250: THE DISTRIBUTION OF PRIMES. ζ(s) = n s,

Uniform Law on the Unit Sphere of a Banach Space

Projectile Motion. Chin- Sung Lin STEM GARAGE SCIENCE PHYSICS

1-D and 2-D Motion Test Friday 9/8

Complex Analysis Homework 1

8.7 Associated and Non-associated Flow Rules

Lecture 6. 2 Recurrence/transience, harmonic functions and martingales

Extension of Minimax to Infinite Matrices

DIFFERENTIAL GEOMETRY. LECTURES 9-10,

Solutions to Assignment #02 MATH u v p 59. p 72. h 3; 1; 2i h4; 2; 5i p 14. p 45. = cos 1 2 p!

Economics 101. Lecture 7 - Monopoly and Oligopoly

A Solution for the Dark Matter Mystery based on Euclidean Relativity

10.2 The Unit Circle: Cosine and Sine

Find the equation of a plane perpendicular to the line x = 2t + 1, y = 3t + 4, z = t 1 and passing through the point (2, 1, 3).

Chapter 7 Rational and Irrational Numbers

DUAL NUMBERS, WEIGHTED QUIVERS, AND EXTENDED SOMOS AND GALE-ROBINSON SEQUENCES. To Alexandre Alexandrovich Kirillov on his 3 4 th anniversary

PHYS 301 HOMEWORK #9-- SOLUTIONS

Optimization of Gear Design and Manufacture. Vilmos SIMON *

Central Force Motion Challenge Problems

AP Calculus Testbank (Chapter 10) (Mr. Surowski)

Advanced Cryptography Midterm Exam

6.2 Trigonometric Functions: Unit Circle Approach

CHAPTER 3: TANGENT SPACE

Inverting: Representing rotations and translations between coordinate frames of reference. z B. x B x. y B. v = [ x y z ] v = R v B A. y B.

Quadratic Reciprocity

In this activity, we explore the application of differential equations to the real world as applied to projectile motion.

Projectile Motion trajectory Projectile motion

Math 104B: Number Theory II (Winter 2012)

SYMPLECTIC STRUCTURES: AT THE INTERFACE OF ANALYSIS, GEOMETRY, AND TOPOLOGY

9 The Theory of Special Relativity

Computer arithmetic. Intensive Computation. Annalisa Massini 2017/2018

Mathematics 309 Conic sections and their applicationsn. Chapter 2. Quadric figures. ai,j x i x j + b i x i + c =0. 1. Coordinate changes

Code_Aster. Connection Harlequin 3D Beam

1 Gambler s Ruin Problem

The. Consortium. Continuum Mechanics. Original notes by Professor Mike Gunn, South Bank University, London, UK Produced by the CRISP Consortium Ltd

Solution Week 75 (2/16/04) Hanging chain

Sharp gradient estimate and spectral rigidity for p-laplacian

Game Physics: Basic Concepts

Further differentiation and integration

LAB 05 Projectile Motion

Notes on pressure coordinates Robert Lindsay Korty October 1, 2002

Unit 1, Lessons 2-5: Vectors in Two Dimensions

SECTION 5: FIBRATIONS AND HOMOTOPY FIBERS

Kinematics. Vector solutions. Vectors

CSE 599d - Quantum Computing When Quantum Computers Fall Apart

Chapter 1: PROBABILITY BASICS

PHY 1114: Physics I. Quick Question 1. Quick Question 2. Quick Question 3. Quick Question 4. Lecture 5: Motion in 2D

MATH 6210: SOLUTIONS TO PROBLEM SET #3

Relative Velocity. Exercise

2 Asymptotic density and Dirichlet density

Polar Coordinates; Vectors

2 Asymptotic density and Dirichlet density

Announcements. Unit 1 homework due tomorrow 11:59 PM Quiz 1 on 3:00P Unit 1. Units 2 & 3 homework sets due 11:59 PM

Projectile Motion. v a = -9.8 m/s 2. Good practice problems in book: 3.23, 3.25, 3.27, 3.29, 3.31, 3.33, 3.43, 3.47, 3.51, 3.53, 3.

PHYS-2010: General Physics I Course Lecture Notes Section IV

MATH 361: NUMBER THEORY EIGHTH LECTURE

Chapter 4 MOTION IN TWO AND THREE DIMENSIONS

6 Stationary Distributions

ATM The thermal wind Fall, 2016 Fovell

On the Field of a Stationary Charged Spherical Source

216 S. Chandrasearan and I.C.F. Isen Our results dier from those of Sun [14] in two asects: we assume that comuted eigenvalues or singular values are

AM 221: Advanced Optimization Spring Prof. Yaron Singer Lecture 6 February 12th, 2014

jf 00 (x)j ds (x) = [1 + (f 0 (x)) 2 ] 3=2 (t) = jjr0 (t) r 00 (t)jj jjr 0 (t)jj 3

Physics Chapter 3 Notes. Section 3-1: Introduction to Vectors (pages 80-83)

EXERCISES Practice and Problem Solving

Introduction to 2-Dimensional Motion

Feedback-error control

The centripetal acceleration for a particle moving in a circle is a c = v 2 /r, where v is its speed and r is its instantaneous radius of rotation.

Lab 5: Two-Dimensional Motion. To understand the independence of motion in the x- and y- directions

Transcription:

CMSC 425: Lecture 7 Geometric Programming: Samle Solutions Samles: In the last few lectures, we have been discussing affine and Euclidean geometr, coordinate frames and affine transformations, and rotations. In this lecture, we work through a few examles of how to al these concets to solve a few concrete roblems that might arise in the context of game rogramming. Caveat: I have not tested the Unit code given here, so don t trust it! Shot-Gun Simulator: Problem: You have been asked to imlement a new weaon that behaves something like a shot gun. It has a wide ange of effectiveness, but it is onl effective at relativel small distances. Suose that the end of the mule of the gun is located at a oint (in 3-dimensional sace), and it has been aimed at a target oint t (see Fig. 1). The gun shoots a sra of ellets within angle θ the central axis between and t, but bullets are onl effective u to a distance of r from the end of the mule. (Let s assume that θ is given in degrees and is strictl smaller than 90.) Given a oint, write a rocedure to determine whether the oint will be hit when the gun is fired. r r û u θ t θ v t (b) Fig. 1: Shot gun. Solution: We need to determine (1) whether lies within the infinite cone about the central axis t and (2) whether is close enough to be hit. How do we determine the first condition? We can construct two vectors, one from to t and one from to, and determine whether the angle between them is at most θ degrees (see Fig. 1(b)). First, define a vector v to be the vector from to t, that is, v t. Next, define the vector u to be a vector that is directed from to, thus, u. Let us normalie these vectors to unit length, b defining û normalie( u) = u/l(u), where l(u) = u = u u. (Here we have used the roert of dot roduct, that the dot roduct of a vector with itself is the vector s suared length.) We can do the same for v. In order for to lie within the cone, we comute the angle between these vectors. Recall, that we can comute the cosine of two unit vectors b taking their dot roduct. Since the cosine is a monotonicall decreasing function (for the angles in the range from 0 to 180 ), this is euivalent to the condition û v cos θ. Lecture 7 1 Sring 2018

Be careful! Remember that θ is given in degrees and the cosine function assumes that the argument is given in radians. To convert from degrees to radians we multil b π/180. So the correct exression is ( π ) û v cos θ. 180 To solve (2), it suffices to test whether If l(u) > r then is too far awa to be hit. To summarie, we have the following test. v t ; u l(v) v = v v; l(u) u = u u v normalie( v) = v/l(v); û normalie( u) = u/l(u) c 1 û v ( π ) c 2 cos θ 180 return true iff (c 1 c 2 and l(u) r). A Unit imlementation of this rocedure (which I haven t tested) can be found in the following code block. } Does a shot gun fired at toward t hit oint? bool HitMe ( Vector3, Vector3 t, float theta, float r, Vector3 ) { Vector3 v = t - ; // vector from mule end to target Vector3 u = - ; // vector from mule end to float lu = u. magnitude ; // distance to Vector3 vv = v. normalied ; // directional vector to t Vector3 uu = u. normalied ; // directional vector to float c1 = Vector3. Dot ( uu, vv); // cosine of angle between vectors float c2 = Mathf. Cos ( theta * Mathf. PI / 180) ; // cosine of hit cone return ( c1 >= c2) && ( lu <= r); // target within cone and distance Projectile Shooting: Your game involves a shooting an object (and arrow, rock, grenade, or other rojectile) in a certain direction. Your boss wants ou to write a rogram to determine where the rojectile will land, as art of an aiming tool for inexerienced laers. Suose that the rojectile is launched from a location that is h meters above the ground. Following Unit s convention the rojectile starts above on the vertical () axis, at coordinates (0, h, 0). Suose that the rojectile is launched with a velocit given b the vector v 0 = (v 0,x, v 0,, v 0, ). Let s assume that the arrow is shot uwards, that is, v 0, > 0. To simlif matters, let s assume that the rojectile is shot in the forward () direction. Thus v 0,x = 0 and v 0, > 0. We want to determine the distance l from the shooter where the rojectile hits the ground. Let t = 0 denote the time at which the object is shot. After consulting a standard textbook on Phsics, we are reminded that (on Earth at least) the force of gravit results in an acceleration of g 9.8m/s 2. Lecture 7 2 Sring 2018

v 0 = ( x, h, ) v 0 h h v 0, t x (b) Fig. 2: Projectile shooting After consulting our hsics text, ou find out that after t time units have elased, the osition of the rojectile is (t) = ((t), (t)), where (t) = v 0, t and (t) = h + v 0, t 1 2 gt2. (Assuming no wind resistance, the rojectile s motion with the -axis is constant over time as v 0,. It s motion with resect to the -axis follows a downward arabolic arc as a function of time t.) We are interested in the time t when the rojectile hits the ground, that is, (t) = 0. Time of Imact: Letting a = g/2, b = v 0,, and c = h, we seek the value of t such that at 2 + bt + c = 0. (We have intentionall negated the coefficients so that a > 0.) B the uadratic formula we have t = b ± b 2 4ac 2a = v 0, ± v0, 2 + 2gh. g Note that the uantit under the suare-root sign is ositive and is larger than v 0,, which imlies that both roots exist, one is ositive and one is negative. Clearl, we want the ositive root. (As an exercise, what does the negative root corresond to?) Thus, we take the + root from the ± otion, which ields t = ( v 0, + v 2 0, + 2gh ) /g. Location of Imact: We know that the rojectile moves at a rate of v 0, units er second horiontall. Therefore, at time t = t it has traveled a distance of v 0, t units. Since we started at the origin, the location we hit the ground is (x,, ) = (0, 0, v 0, t ). Generaliing this: We assumed that the rojectile was shot along the -axis. Note that the generaliation is ver eas. We comute t in the same manner as above, since it deends onl on the height and vertical velocit. Then we al the same reasoning for x as for. The rojectile travels a distance of v 0,x t units along the x-axis, so its final osition is (x,, ) = (v 0,x t, 0, v 0, t ). We also assumed that the rojective was shot from h units above the origin. If, instead it had been shot from some arbitrar oint ( x, h, ), then we would dislace the final location b this amount, as = ( x + v 0,x t, 0, + v 0, t ). This is where we would draw our sot for aiming tool (see Fig. 2(b)). Lecture 7 3 Sring 2018

Aiming Tool for Projectile Vector3 HitSot ( Vector3, Vector3 v) { float h =.; // height above ground float a = 9.8 f / 2. 0 f; // uadratic coefficients float b = -v.; float c = -h; float t = (-b + Math. Srt (b*b - 4*a*c)) / (2* a); // time in the air return new Vector3 (.x + v.x*t, 0,. + v.*t); // where we hit } Shooting and Arrow: Before leaving the toic of shooting the rojectile, it is worth observing that the Unit Phsics engine can simulate the motion of the rojectile. This will look fine if the rojectile is a ball. However, if the rojectile is an arrow, the arrow will not turn roerl in the air in the manner that arrows do. Unit will siml translate the arrow through sace, without rotating it (see Fig. 3). This raises the uestion, How can we rotate the arrow to oint in the direction it is traveling? (see Fig. 3(b)) (b) Fig. 3: Arrow shooting This ma seem to be a comlicated uestion. Clearl, this is not a rotation about the axes, and so Euler angles would not be the right aroach. We need to use uaternions. We want to secif a uaterion that will cause the arrow to rotate in the direction it is moving. Luckil for us, Unit rovides a function that does almost what we need. The Unit function Quaternion.LookRotation(Vector3 forward) generates a rotation (reresented as a uaternion) that aligns the forward () axis with the argument. Thus, to align the arrow with the direction it is heading, we can use the following Unit commands: RigidBod rb = getcomonent < RigidBod > (); transform. rotation = Quaternion. LookRotation ( rb. velocit ); This will rotate the object so its orientation matches its velocit, as desired. Evasive Action: Problem: In our latest game, ou are simulating the AI for some alien sace shis. Each sace shi is associated with its current osition, a oint, and two unit-length vectors. The first vector v indicates the direction in which the sace shi is fling. The second Lecture 7 4 Sring 2018

vector u is orthogonal to v and indicates the direction that is u relative to the ilot fling the sace shi (see Fig. 4). There are various obstacles to be avoided (asteroids, and such) and the AI sstem needs to issue turning commands to avoid these obstacles. Given an obstacle at some oint, the uestion that we want to determine is whether we should turn (aw) to the left or right and whether we should turn (itch) u or down to avoid the collision. (We won t worr about the actual number of degrees of rotation for now, just the direction.) u v r u ŵ v w Fig. 4: Evasive action. Solution: First observe that w defines a vector that is directed from the sace shi to the obstacle (see Fig. 4(b)). To convert this into a unit vector (since we just care about the direction), let us normalie it to unit length. (Recall that normaliing a vector involves dividing a vector b its length.) We can comute the length of a vector as the suare root of it dot roduct with itself. Thus, we have w ŵ normalie( w) = w w = w w w = w. wx 2 + w 2 + w 2 What we want to know is whether this vector is ointing to the sace-shi ilot s left or right (in which case we will turn the oosite direction), or is above or below (in which case we will itch in the oosite direction). Let s first tackle the roblem of whether to turn itch u or down. We can determine this b checking whether the angle between the u-vector u and ŵ. If this angle is smaller than 90, then the obstacle is above us and we should itch downward. Otherwise, we should itch uward. Given that both vectors have unit length, we can comute the cosine of the angle between them b the dot roduct. If the dot roduct is ositive, the angle is smaller than 90, thus the obstacle is above, and we turn down. Otherwise, we turn down. We have ŵ u 0 (obstacle above) itch downwards ŵ u < 0 (obstacle below) itch uwards. (B the wa, since we are onl checking the sign of this dot roduct, not its magnitude, it was not reall necessar to normalie w to unit length. We could have substituted w for ŵ above without affecting the correctness of the result.) Lecture 7 5 Sring 2018

Next, let s consider whether to turn left or right. We would like to erform a similar te of comutation, but to do so, we should generate a vector that indicates left and right relative to the ilot of the shi. Such a vector will be orthogonal both to the direction that we are fling and to the u direction. We can obtain such a vector using the cross-roduct. In articular, define a vector r v u. B the right-hand rule, this vector will oint to the ilot s right. B our assumtion that v and u are orthogonal to each other and of unit length, it follows from the definition of the cross roduct that r will also be of unit length. We reason in an analogous manner to the u-down case. If the angle between ŵ and r is smaller than 90, then the obstacle is to our right, and we turn left to avoid it. Otherwise, we turn right. This is euivalent to testing whether the cosine of the angle is ositive or negative. Thus, we have r v u ŵ r 0 (obstacle to the right) aw to the left ŵ r < 0 (obstacle to the left) aw to the right. A Unit imlementation of this rocedure (which I haven t tested) can be found in the following code block. Turning a shi at osition to avoid obstacle at void Evade ( Vector3, Vector3 v, Vector3 u, Vector3 ) { Vector3 w = - ; // vector from ilot to obstacle float l = w. magnitude ; // distance to obstacle Vector3 ww = w. normalied ; // directional vector to obstacle if ( Vector3. Dot ( ww, u) >= 0) // obstacle is above? PitchDown (); else PitchU (); Vector3 r = Vector3. Cross ( v, u); // vector to ilot s right if ( Vector3. Dot ( ww, r) >= 0) // obstacle is to the right YawToLeft (); else YawToRight (); } We have not discussed how to erform the itch or aw oerations. In Unit, these could be exressed as rotations about the vectors r and u, resectivel. Lecture 7 6 Sring 2018