程序代写代做代考 chain c/c++ Java Squishy Maps for Soft Body Modelling Using Generalised Chain Mail

Squishy Maps for Soft Body Modelling Using Generalised Chain Mail

KIT308/408 (Advanced) Multicore Architecture and Programming

Revision / Crash Course
Dr. Ian Lewis
Discpline of ICT, School of TED
University of Tasmania, Australia
1

There are a number of concepts we use in this unit that it might be helpful to have a refresher of (or crash course in)
Number Systems
The Mandelbrot Set
C/C++
We’ll be using a variety of number systems in this unit
Decimal (I really hope you know this already), binary, octal (maybe), and hexadecimal
The tutorial work and assignments will be in C/C++
The major example we use in the tutorial work relies on code to calculate the Mandelbrot set

2
Lecture Content

Number Systems

3

3

Decimal
Uses ten digits (0..9), each column is ten times bigger
One hundred = 100 (or 10010)
Binary
Uses two digits (0 and 1), each column is two times bigger
One hundred = 11001002 (sometimes %1100100 or @1100100)
Octal
Uses eight digits (0..7), each column is eight times bigger
One hundred = 1448 (in C/C++/Java = 0144)
Hexadecimal
Uses sixteen digits (0..9, A..F), each column is 16 times bigger
One hundred = 6416 (in C/C++/Java = 0x64, elsewhere $64)

4
Number Systems Quick Revision
1. https://qph.ec.quoracdn.net/main-qimg-07dcea35d84e27fd59195718eac42443-c

Frink Rules!
4

… 27 26 25 24 23 22 21 20
… 128 64 32 16 8 4 2 1

0 = 0 0 0 0 0 0 0 0
45 = 0 0 1 0 1 1 0 1
159 = 1 0 0 1 1 1 1 1
255 = 1 1 1 1 1 1 1 1

Each column (from right to left) is two times as big
Numbers are represented as sums of these columns
Because we could get confused, we often write binary numbers followed by a subscript 2
e.g. 100111112 = 15910
Binary Representation
5

Base 8
Uses digits 0..7
Three binary digits are represented as one octal digit
Larger binary numbers can be split into three digit chunks to be written as octal
For example,
1102 → 68
1011110112 = 101111011 2 → 5738
10102 = 001010 2 → 128
Value Binary Octal
zero 000 0
one 001 1
two 010 2
three 011 3
four 100 4
five 101 5
six 110 6
seven 111 7

Octal
6

Base 16
Uses digits 0..9, A, B, C, D, E, F
four binary digits are represented as one hex digit
Larger binary numbers can be split into four digit chunks to be written as hex
For example,
10012 → 916
11012 → D16
11111011011111102 → FB7E16
1110102 = 001110102 → 3A16
You should be able to recognise hex when it appears
Value Binary Hex
zero 0000 0
one 0001 1
two 0010 2
three 0011 3
four 0100 4
five 0101 5
six 0110 6
seven 0111 7
eight 1000 8
nine 1001 9
ten 1010 A
eleven 1011 B
twelve 1100 C
thirteen 1101 D
fourteen 1110 E
fifteen 1111 F

Hexadecimal (Hex)
7

The Mandelbrot Set

8

The Mandelbrot Set is
A fractal
Basically this just means you can see little copies of it within itself
Infinitely complex
If you zoom in on an interesting part of it, you’ll see more detail
More chaotic the closer you look (i.e. the deeper you zoom)
1. http://distrustsimplicity.net/figures/mandelbrot_gray.png
2. https://thelongestthreads.files.wordpress.com/2015/09/seepferdseepferd.jpeg
9
The Mandelbrot Set

At the heart of the Mandelbrot calculation is the simple idea of repeating the same calculation over and over
(xn, yn) = MandelbrotFunction (xn-1, yn-1)
We’re not mathematicians and we don’t care about the sequence of numbers, so what we are doing is more like
(x, y) = MandelbrotFunction (x, y)
i.e. moving a point from one location to another via some calculation
1. http://distrustsimplicity.net/figures/mandelbrot_gray.png
10
Moving a Point Around

Different starting points lead to different kinds of behaviour, e.g.
Cycles (e.g. ↑)
Convergence (e.g. ↑ and ↑)
Getting further and further away from the origin (e.g. ↑ and ↑)
Apparently random movement (e.g. the previous slide)
Two points really close to each other might do vastly different things once they are iterated

11
Where Does the Point Go?

After repeated iterations of the Mandelbrot function, if the point:
Stays close to the origin (i.e. has a small magnitude)
It’s part of the Mandelbrot set
(This is kind of a guess, because we stop iterating it)
Colour it black
Goes away from the origin (i.e. has a big magnitude)
It’s not part of the Mandelbrot set
Colour it according to how many iterations it took to start getting big (anything over magnitude 2 is big enough)

12
Where Does the Point Go?

To generate a Mandelbrot image
Loop over all the points (x, y) contained within a rectangular region
For each point (x, y) do a number of iterations of the Mandelbrot function
Colour the point based on how fast it goes away from the origin, or if it doesn’t

13
Generating an Image

Just a matter of changing the coordinates of the rectangle you want to generate
Successive zooms
x: −2.25 … 0.75, y: −1.5 … 1.5
x: −0.8 … −0.3375, y: 0.3375 … 0.8
x: −0.5839322917 … −0.496484375
y: 0.482031250 … 0.54947917
etc.
From a programming perspective we change the coordinates we use for the Mandelbrot calculation, but still need to generate an image of the same size each time
1. http://www.atopon.org/mandel/#
14
Zooming

Points close to the edge of the Mandelbrot set (the black parts) can be misclassified (guessed wrongly to be in the set) if not enough iterations are used
Successive iteration count:
250
500
1000
2500
From a programming perspective we just loop more

1. http://math.hws.edu/eck/js/mandelbrot/MB.html
15
Mandelbrot Function Iterations

The Mandelbrot Function calculation
xn = (xn-1)2 − (yn-1)2 + x0
yn = 2*xn-1*yn-1 + y0
Pseudocode
x = x0
y = y0
while (x*x + y*y < 2*2) xtemp = x*x - y*y + x0 y = 2*x*y + y0 x = xtemp What’s missing here is: Setting up the value of x0 and y0 By looping over a square region specified by coordinates Keeping track of iterations i.e. don’t have an infinite loop for points that are in the Mandelbrot set Doing something with the result Which also requires keeping track of where in the image to write each generated pixel 16 The Mandelbrot Function Original equation is actually using so-called “imaginary” numbers z0 = c zn = (zn-1)2 + c where c = x + yi (i.e. a “complex” number) where i = √−1 (so i2 = −1) So the image is actually generated in a square region on the “complex” plane From a programming perspective we don’t need to care about this maths 1. https://cs.anu.edu.au/courses/comp4300/practicals/L6MaSe.gif 17 The “Imaginary” Mandelbrot Function /docProps/thumbnail.jpeg