## 3D Graphics

**Now at www.breakingwave.co.nr – the home of trevorpythag**

This is a brief explanation of how to create basic 3D graphics. There are many different packages that will allow you to program using pre written 3D graphics library’s, such as Java 3D but this is aimed at using and understanding the actual formula that can be used to draw the graphics yourself.

This assumes you are looking straight ahead from a single point and will map points in the 3D space in front of you onto a single plane at a fixed distance in front of you, probably 1 unit to keep it simple.

First of all consider the vertical direction, y axis. If we consider the right angled triangle formed by taking the line from you eye to the point, the line from your eye to beneath the point (ie the line where y =0) and the final verical equal to the y cordinate, we can use trigonometry to work out the height that need to be displayed.

From this we can work out the angle at your eye would be tan^{-1}(y/(x^{2}+z^{2}))

This is because the length of the “opposite” is equal to the y co-ordinate and the adjacent can be found using pythagoras from the x and z co-ordinates.

We now can use the angle we have found to work out where the point needs to be displayed in our plane. Again we need to form a triangle similar to the first one but where the top corner is the final position of the point when it is projected. Ie the opposite is the y co-ordinate we need.

therefore,

y = tan(t)((x/z)^{2}+1)

y=y((x/z)^{2}+1)

(x^{2}+z^{2})

## MySQL: mysql dump > using to upload database

I recently created a website in PHP, with page details stored in a database using MySQL and then came acorss a problem when trying to upload it.

Basically mysqldump is a command that allows creates a file which contains all the sql statements required to rebuild the database or table you want. This is usefull for creating backups or allowing you to upload your database to your host server.

The command to do this is as follows

**mysqldump –user=username –password=password databasename > locationofdump.sql**

Note this should be entered in the normal command prompt, cmd.exe on windows, not the mysql command line tool thingy else it wont work. You can then use this to import the database on your host using phpmyadmin.

## Basic Arithmatic in Binary

This is a simple guide in using binary and performing simple arithmetic like addition and subtraction

**What is Binary**

Binary is an alternative number system that uses base 2, opposed to our normal system that uses base 1. Binary is used extensively in computers as it allows numbers to be represented by a current being on or off and therefore allowing them to do calculations.

**Counting in binary**

In base 10, our usual number system, we have 10 characters (0,1,2,…,9), and when we want to add 1 to our last character, 9, we have to move across to the next colloum, ie 9 + 1 = 0 carry 1. In binary we have 2 characters (0 and 1) and when we want to add one to one we move to the next colloum, so 1+1=0 carry 1.

so how do we read the binary number. Well on the far right we have our units (1’s) the same as in bas 10, however the next colloum across we have our 2’s instead of tens. Then we have 4’s instead of 100’s. So each collum is the next power of 2 across.

here are some numbers in binary and decimal(base 10):

decimal:binary

1 = 1

2 = 10 * 2^{1}

3 = 11

4 =100 * 2^{2}

5 = 101

6=110

7 = 111

8=1000 * 2^{3}

9=1001

10=1010 *10^{1}

15=1111

16=10000 * 2^{4}

20=10100

100=1100100 * 10^{2}

**Adding in binary**

In binary each number is either a 1 or 0, so if we have a 1 and we want to add 1 we have to put 0 and carry 1 to the next colloum.

eg 1+ 1 = 0 carry 1 = 10

eg 11011+10010 = 101101

In binary there are four combinations of digits that can be added

0+0 = 0

1+0=1

0+1=1

1+1=0 carry 1

You can add binary numbers in collums like you do with decimals, only it so much easier cos its only 1 and 0.

**Subtraction**

Subtraction is just the reverse of addtion so:

1-0=1

1-1=0

0-1= 0 carry 1 (to the left this time)

0-0=0 (obviously)

## Comments