There are three kinds of lies: lies, damned lies, and statistics. – Benjamin Disraeli (1804-1881), British politician

# [[Software]]

### TRIGONOMETRY

`sin = Op / Hyp`
`cos = Adj / Hyp`
`tan = Op / Adj`

Quaternions @ http://en.wikipedia.org/wiki/Quaternion

Rotation :

• Vector + angle { x y z a }
• Quaterion : { sin(a/2)* x , sin(a/2) * y , sin(a/2) * z , cos(a/2) }

### LINEAR ALEBRA

norm :

`|AB| = sqrt( X^2 + Y^2 + Z^2 )`

dot product (scalar) with a '.' :

```A . B = |A| * |B| * cos(A,B)
= Ax*Bx + Ay*By + Az*Bz```

props:

```X . Y = Y . X  # commutative
( a * X ) . Y  =  a * ( X . Y ) # associative
X . ( Y + Z ) = ( X . Y ) + ( Y . Z ) # distributive```

cross product (vect) with a 'x' : (result is called normal)

`A x B = ( Ay*Bz-By*Az , Az*Bx-Bz*Ax , Ax*By-Bx*Ay )`
`| A x B | = |A| * |B| * sin(a,b)  (which is the area of the paralellogram)`

props:

```A x A = 0
A x B = -(B x A),
r being a constant, (r * A) x B = r * ( A x B )
A x (B + C) = A x B + A x C,
( A x B = C ) and respectively ( C x A = B ) and ( B x C = A )```

### APPLICATIONS

angle (A,B) :

```acos ( A.B / |A|*|B| )
asin ( |AxB| / |A|*|B| )```

normal:

```A x B is the normal of the 2 vectors (2 rights angles)
order must be be anticlockwise for a (right hand direction)```

projection: (of unit vectors)

`A'  = A projected on B = (A . B) * B`

distance:

```within a Point P and a Unit Vector D staring in O :
d = D x ( P - O  ) # check it
= sqrt (
( Dy * ( Pz - Oz ) - Dz * ( Py - Oy ) )^2
+ ( Dz * ( Px - Ox ) - Dx * ( Pz - Oz ) )^2
+ ( Dx * ( Py - Oy ) - Dy x ( Px - Ox ) )^2
)
if we are in a 2D world :
d = abs ( Dx * ( Py - Oy ) - Dy x ( Px - Ox ) )```

#### OBJECTS

line:

`P = O + l * D`
```# l is the parametric factor & O origin
# D may be any vector including unit one or (M-O), M is anywhere on line```

plane:

```define it by ( O & N  ) or ( N & k )
N . P  = k # k is constant and N normal of plane
( Nx * Px ) + ( Ny * Py ) + ( Nz * Pz ) - k = 0```

sphere :

`| P - C | = r # C is Center and r radius`

distance point to plane : ( O is a Point of Plane)

```d = ( ( N . P ) - ( O . N ) ) / norm(N) # check it
= N . ( P - O ) / norm(N)  # check it```

intesection : line & plane

```[[ P.N = k
[[ P = O + l * D```
`l = ( k - ( O . N ) ) /  ( D . N )`

intersection : plane & plane & plane

```[[ P.N1 = k1
[[ P.N2 = k2
[[ P.N3 = k3
TODO, see matrix & inv mtx```

intersection : plane & plane

```[[ P.N1 = k1
[[ P.N2 = k2```

intersection : line & sphere

```[[ P = O + l * D
[[ | P - C | = r```
`TODO , see quadratic`

### ROTATIONS MATRIX

around X :

```x' =   x
y' =   (cos a * y) - (sin a * z)
z' =   (sin a * y) + (cos a * z)```

around Y :

```x' =   (cos a * x) + (sin a * z)
y' =   y
z' = - (sin a * x) + (cos a * z)```

around Z :

```x' =   (cos a * x) - (sin a * y)
y' =   (sin a * x) + (cos a * y)
z' =   z```

### MATHS

question : comment determiner (n) a partir de (x) sachant que :

`2^(n-1) < x << 2^n ?`
```(n-1) log 2 < log x << n log 2
(n-1) < log x/log 2 << n```
```double n = log ( x  ) * 1. / log (2.) ;
if ( n - ( (double) (int) n) ) n++;
int m = 1<<(int) n;```

Another solution is to use bitmask :

```1/ o = count '1' bits
2/ if o = 1 return o's bit position
3/ else shift right
4/ return 1st '1' bit'position from left```

## MORE 