Skip to content

Instantly share code, notes, and snippets.

@sketchpunk
Last active March 21, 2019 15:05
Show Gist options
  • Save sketchpunk/3bd2d6a562c7e503aba0397bbf54fcf5 to your computer and use it in GitHub Desktop.
Save sketchpunk/3bd2d6a562c7e503aba0397bbf54fcf5 to your computer and use it in GitHub Desktop.
Programming Math Notes
Radius = ArcLength / Angle
ArcLength = Radius * Angle
Arc / Segment Height = Radius * ( 1 - cos(angle / 2) )
circleCenterPoint_fromCurve = Radius - Segment Height
chord length = 2 * Radius * sin( angle / 2 )
circumference = PI * diameter
circumference = PI * radius * 2;
arcLen / circumference = degree ratio (Meaing 10 degress over 360 degrees)
https://www.mathsisfun.com/calculus/derivatives-rules.html
Sum / Difference (+ or -) : treat each side as a function that you need to make a derivative of.
f + g -> f' + g'
constant = 0, variable = 1 :: x - 1 become 1 - 0
const * var : D(2x) -> 2 D(x) -> 2 * 1
sqrt(x) : 1 / (2 * sqrt(x))
function * variable = ax -> a
(-P0 + P2) * t -> (-P0 + P2)
Power Rule : x^2 = D( n*x^n-1 ) = 2x^1
example2: 3x^2 -> 3 * 2x^1 -> 6x^1
Product Rule : f() * g() = f() * g'() + g() * f'();
fg -> f g' + f' g
Chain Rule : f(g()) = f'( g() ) * g'();
Quatient Rule : f() / g() :: g()*f'() - f() * g'() / g() * g()
f/g -> (f' g - g' f) / g^2
Reciprocal Rule
1 / f -> -f' / f^2
inversCOT(x) = -1 / 1 + x^2
sin(x) = cos(x)
cos(x) = -sin(x)
tan(x) = sec^2( x )
----------------------------------------------
EXAMPLES
----------------------------------------------
(2t³ - 3t² + 1) * p0 +
(t³ - 2t² + t) * m0 +
(-2t³ + 3t²) * p1 +
(t³ - t²) * m1
(6t² - 6t)p0 +
(3t² - 4t + 1)m0 +
(-6t² + 6t)p1 +
(3t² - 2t)m1
----------------------------------------------
0.5 * (
(2 * P1) +
(-P0 + P2) * t +
(2*P0 - 5*P1 + 4*P2 - P3) * t² +
(-P0 + 3*P1- 3*P2 + P3) * t³
)
2 * P1 -> 0 * 1 = 0
(-P0 + P2) * t -> ax -> a --> (-P0 + P2 )
(2*P0 - 5*P1 + 4*P2 - P3) * t²
(2*P0 - 5*P1 + 4*P2 - P3) * 2t
(-P0 + 3*P1- 3*P2 + P3) * t³
0.5 *(
(-P0 + P2) +
2*(2*P0 - 5*P1 + 4*P2 - P3) * t +
3*(-P0 + 3*P1- 3*P2 + P3) * t²
)
----------------------------------------------
(s*P0 - s*P1) +
( (s - 2) * P0 + (3-2*s) * P1 + s*P2 ) * t +
( (2-z) * P0 + P3 ) * t^2 +
( -s * P0 + 2*s*P1-s * P2 ) * t^3
( (s-2) *P0 + (3-2*s)*P1 + s*P2 ) +
2 * ((2-s)*P0 + P3 ) * t
3 * (-s*P0 + 2*s*P1 -s*P2 ) * t^2
p1.x + d0x * t + (- 3 * p1.x + 3 * p2.x - 2 * d0x - d1x) * tt + ( 2 * p1.x - 2 * p2.x + d0x + d1x) * ttt
d0x + 2 * (- 3 * p1.x + 3 * p2.x - 2 * d0x - d1x) * t + 3 * ( 2 * p1.x - 2 * p2.x + d0x + d1x) * tt
https://www.youtube.com/watch?v=v1V3T5BPd7E
https://www.youtube.com/watch?v=phMZQNu0ZFM
https://www.youtube.com/watch?v=IvT8hjy6q4o
s = displacement (distance)
u = inital velocity
v = final velocity
a = acceleration
t = total time
1. s = (( u + v ) / 2) * t
Average Velocity = displacement / time
(inital v + final v) / 2 = displayment / time
2. v = u + a * t
a = (v - u) / t
t = (v - u) / a
Constant Accel = (change of velocity) / time
Constant Accel = (final vel - initial vel) / time
3. s = (u * t) + (( a * t^2 ) / 2)
4. s = v * t - ((a * t^2) / 2 )
5. v^2 = u^2 + 2 * a * s
u^2 = v^2 - 2 * a * s
6. s = (v^2 - u^2) / (2 * a)
(lowercase is length, Upper is Angle)
C
/\
b / \ a
A/____\ B
c
longer side is C
*when knowing 2 angles, subtract both from 180 to get remaining angle.
SSS : Solve only knowing sides Side-Side-Side
cos(C) = (a^2 + b^2 - c^2) / 2ab
cos(A) = (b^2 + c^2 - a^2) / 2bc
cos(B) = (c^2 + a^2 - b^2) / 2ca
SSA : Solve length if 2 sides and its angle is known
c^2 = a^2 + b^2 - 2ab cos(C)
a^2 = b^2 + c^2 - 2bc cos(A)
b^2 = c^2 + a^2 - 2ca cos(B)
Law of Sines
SSA : find Angle of C when knowning Length of A and B, angle of B.
sin(C) = (a * Math.sin(B)) / b
abs( fract( X - 0.5 ) - 0.5 )
Zero will Equal 1
Any Whole Number Will Equal 0
Any 0.5 number will Equal 0.5
Any Number over before or after 0.5 will be its opposite on the 0-1 range.
0 = 1 -> 0.2 = 0.8 -> 0.5 = 0.5 -> 0.7 = 0.3 -> 1.0 = 0
-----------------------------------------------
Javascript : 1.6 | 0 = 1.0 // Using Pipe works like Math.floor
-----------------------------------------------
Instead of using x % 2 = 0 or 1
Use bitwise operations x & 1 == 1
if the value is even, will equal 0
if the value is odd, will equal 1
Closet Point on a plane from a point.
p = point
v = p - planePoint //vector length from point to a plane's point.
n = the plane's unit length vector direction
len = v dot n
pos = p - (n * len)
Intersection Point between a Plane and a Ray
dot( planePos-rayOrigin, planeNorm ) / dot(rayVecLen, planeNorm);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment