+ All Categories
Home > Documents > Year Googol Formula Document - University Of Maryland€¦ · Year Googol Formula Document July 27,...

Year Googol Formula Document - University Of Maryland€¦ · Year Googol Formula Document July 27,...

Date post: 04-Jun-2018
Category:
Upload: phungque
View: 214 times
Download: 0 times
Share this document with a friend
9
Year Googol Formula Document July 27, 2013 1 Matrix operations The graphics and physics engine of Year Googol rely heavily on matrix com- putation. Your implementations in the Matrix class will involve the following operations. 1.1 Entry-wise Matrix Arithmetic 1 2 3 4 .times(3) 3 6 9 12 1 2 3 4 .plus 5 6 7 8 6 8 10 12 1 2 3 4 .plus 5 7 throws IncompatibleMatrixSizeException 1 2 3 4 .minus 4 3 2 1 -3 -1 1 3 12 -7 .mod 5 5 2 3 1 0 2 .dot 4 1 2 1 · 4+0 · 1+2 · 2=8 1
Transcript

Year Googol Formula Document

July 27, 2013

1 Matrix operations

The graphics and physics engine of Year Googol rely heavily on matrix com-putation. Your implementations in the Matrix class will involve the followingoperations.

1.1 Entry-wise Matrix Arithmetic

[1 23 4

].times(3)→

[3 69 12

][1 23 4

].plus

([5 67 8

])→[

6 810 12

][1 23 4

].plus

([57

])→ throws IncompatibleMatrixSizeException

[1 23 4

].minus

([4 32 1

])→[−3 −11 3

][

12−7

].mod

([55

])→[23

]

[1 0 2

].dot

412

→ 1 · 4 + 0 · 1 + 2 · 2 = 8

1

1.2 Sub-matrices1 0 2 00 3 0 45 0 6 00 7 0 8

.subMatrix(1, 0, 2, 3)→[0 3 05 0 6

]

1 0 2 00 3 0 45 0 6 00 7 0 8

.subMatrix(1, 0, 2, 5)→ throws

MatrixOutOfBoundsException(1,4,this)

or

MatrixOutOfBoundsException(2,4,this)

1.3 Matrix Multiplication

Entry (i, j) of the matrix product A×B is the dot-product of the ith row of Aand the jth column of B. The number of columns in A must equal the numberof rows in B. For example:

[1 0 20 2 3

].times

1 00 23 1

→ [1 · 1 + 0 · 0 + 2 · 3 1 · 0 + 0 · 2 + 2 · 10 · 1 + 2 · 0 + 3 · 3 0 · 0 + 2 · 2 + 3 · 1

]=

[7 29 7

][1 0 20 2 3

].times

([1 00 2

])→ throws IncompatibleMatrixSizeException

1.4 Matrix Equality

The limited precision of floating-point CPU arithmetic leads to small roundingerrors that can accumulate over multiple operations. Two matrices should stillbe considered equal even if there are small deviations in their correspondingentries: Deviations less than YearGoogol.PRECISION are allowed. For example,if YearGoogol.PRECISION=0.01:[

0.001 0.505].equals

([−0.001 0.507

])→ true

[0.001 0.505

].equals

([−0.001 0.515

])→ false

2

1.5 Plane Rotations

A matrix can be used to represent rotation of points in a plane. A plane rotationmatrix contains 1 in each diagonal entry, and 0 everywhere else, except at fourspecial entries. If the plane corresponds to the ath1 coordinate axis and ath2coordinate axis, and the angle of rotation is θ, then:

• entry (a1, a1) = cos θ

• entry (a1, a2) = − sin θ

• entry (a2, a1) = sin θ

• entry (a2, a2) = cos θ

For example, in 3D space, the 0th axis corresponds to x, and the 1st axis corre-sponds to y. So a rotation of θ in the xy plane is given by:

Matrix.planeRotation(3,0,1,θ)→

cos θ − sin θ 0sin θ cos θ 0

0 0 1

In 4D space, a rotation of θ in the xz plane (0th and 2nd axes) is given by:

Matrix.planeRotation(4,0,2,θ)→

cos θ 0 − sin θ 0

0 1 0 0sin θ 0 cos θ 0

0 0 0 1

1.6 Unit hyper-cubes

Unit hyper-cubes are used to render the Exoverse. The n-dimensional unithyper-cube has 2n vertices. The vertex coordinates are precisely the bits ofthe binary numbers 0 through 2n − 1. This is illustrated in Figure 1. Thevertices can be organized as the columns of a matrix, where entry (i, j) containsthe ith bit of the binary number j (ordered from least significant bit to mostsignificant). For example, the 3D cube has associated matrix:0 1 0 1 0 1 0 1

0 0 1 1 0 0 1 10 0 0 0 1 1 1 1

The ith bit of j can be found via the formula

j

2imod 2

or equivalently with the bit-shift operators.

3

(0,0,0) (1,0,0)

(1,1,0) (0,1,0)

(0,0,1) (1,0,1)

(1,1,1) (0,1,1)

x

y

z

Figure 1: The 3-dimensional unit “hyper”-cube. Vertex coordinates are pre-cisely the bits of the binary numbers 0 through 23 − 1 = 7.

1.7 2D Vectors

The Vec2D class is used to represent positions, velocities, forces, and paths inthe Year Googol plane. This class has been implemented for you. In fact,Vec2D is a sub-class of Matrix: A Vec2D object is a Matrix with 2 rows and 1column. It can do everything a matrix can do, including addition, scalar mul-tiplication, dot-product, and modulo. See Figure 2 for an illustration of vectorarithmetic. Vec2D also contains some additional functionality, documented inthe API, which will come in handy. For example:[

34

].dotSelf()→ 25[

34

].norm()→ 5[

34

].normalize(10)→

[68

][34

].normalize()→

[0.60.8

]The norm of a vector v is its length, denoted ‖v‖.

2 Year Googol Physics

Several formulae in this section involve a very short time interval, which is de-noted by ∆t. This time interval is a small fraction of a second. For your project,the value of ∆t is a constant, stored in the variable YearGoogol.DELTA T.

Particle positions, velocities, forces, and paths are 2-dimensional vectors,indicated in bold, and represented in your project by Vec2D objects.

4

𝒗1

𝒗2

(1,6)

(8,4)

(8-1,4-6)=(7,-2)

𝑥

𝑦

Figure 2: All vectors emanate from the origin, including v2 − v1. However thisdifference can also be thought of as the path from v1 to v2.

2.1 drift

Given:

• v: The current particle velocity

• p(orig): The initial particle position

The updated position is:

p(new) = p(orig) + v∆t

The expression v∆t means that the vector v is multiplied by the scalar ∆t.The Year Googol plane wraps around on itself: If a particle drifts off one

edge of the view, it reappears on the opposite side. The size of the Year Googolplane is stored in the variable YearGoogol.SIZE. This variable is a Vec2D object,whose first component is the width and whose second component is the height.See Figure 3 for an example of wrapping.

2.2 apply

Given:

• f : The applied force

• m: The particle mass

• v(orig): The initial particle velocity

The updated velocity is:

v(new) = v(orig) + f∆t

m

5

𝒑(𝑜𝑙𝑑) (600,50)

𝒑(𝑛𝑒𝑤) (50,400)

𝒑(𝑛𝑒𝑤) (850,-200)

𝒑(𝑜𝑙𝑑)

Figure 3: Wrapping. In this example, YearGoogol.SIZE is (800,600). If p(new)

is found to lie out of bounds, it must be replaced with the corresponding positionafter wrapping. The Vec2D mod(...) method is designed expressly for thispurpose.

6

A

B

B B

A

A A

B

𝒓𝐴𝐵

(100,50)

(750,400)

(-50,-200)

Figure 4: Shortest-path vectors. In this example, YearGoogol.SIZE is (800,600). The shortest path from a to b is not simply b − a=(650, 350). There isa shorter path if one moves up and to the left, and wraps around: (-150, -250).

2.3 Shortest-path vectors

In the ordinary cartesian plane, the shortest-path vector from position a to bis the vector difference:

b− a

However, this formula is not sufficient for the Year Googol plane, which wrapsaround on itself. The shortest-path vector must allow the possibility of movingoff one edge of the plane and reappearing on the other side. This is illustratedin Figure 4. The shortest-path vector from particle A to particle B is denotedrAB .

2.4 Gravitational force

For any pair of particles A and B, each exerts a gravitational force on theother. The strength of this force depends on a physical quantity called the“gravitational constant,” which is denoted by G. For your project, the value ofthis constant is stored in YearGoogol.G.

7

Given:

• mA and mB : The masses of A and B, respectively.

• rBA: The shortest-path vector from B to A.

The force that A exerts on B is calculated as follows:

1. Compute the magnitude of the gravitational force:

‖fAB‖ = GmAmB

‖rBA‖2

2. Normalize rBA to have the foregoing magnitude. The normalized versionis fAB .

The force that B exerts on A is equal and opposite to the force that A exertson B:

fBA = −fAB

2.5 Particle intersection

Two particles A and B intersect when the distance between them is shorter thantheir summed radii. In other words, intersections may be detected as follows:

1. Compute the shortest-path vector from B to A: rBA.

2. Compute the magnitude of this vector: ‖rBA‖

3. Compute the sum of particle radii: R = rA + rB .

4. If ‖rBA‖ < R, then the particles intersect.

This is illustrated in Figure 5.

2.6 Collision force

When two particles A and B collide, each exerts a very large force on the other,over a very short time interval.

Given:

• mA and mB : The masses of A and B, respectively.

• vA and vB : The velocities of A and B, respectively.

The force that A exerts on B can be calculated as follows:

1. Compute the “reduced mass” of the system:

µ =mAmB

mA +mB

8

𝒓𝐴𝐵

𝑟𝐴 𝑟𝐵

A B

Figure 5: Particle intersection. These particles do not intersect, since the sumof radii rA + rB is less than the length of the shortest-path vector: ‖rAB‖.

2. Compute the shortest-path vector from B to A: rBA.

3. Compute the “line of collision” cBA, which is the shortest-path vector,normalized to length 1.

4. Compute the “scalar velocities” along the line of collision:

uA = vA · cBA

uB = vB · cBA

Here · denotes dot-product.

5. The force that A exerts on B is given by:

fAB = cBA2µ(uA − uB)

∆t

The force that B exerts on A is equal and opposite to the force that A exertson B:

fBA = −fAB

9


Recommended