Upgrade to Pro — share decks privately, control downloads, hide ads and more …

3D Math Intro

3D Math Intro

A super-quick primer to 3D math concepts. A talk I was going to give, but barely finished and never polished.

Avatar for Yaroslav Shirokov

Yaroslav Shirokov

January 07, 2015

Other Decks in Programming

Transcript

  1. Vector • A magnitude, or length, and a direction •

    Can be represented by its components • A = <AX,AY,AZ> • Can be added, multiplied, subtracted from other vectors • Can be multiplied or ‘scaled’ by real numbers. • Normalization divides each component by the magnitude, setting the magnitude to 1 while maintaining direction. <AX,AY,AZ> Normalized, where m = ||A|| <AX/m,AY/m,AZ/m>
  2. Vector Dot Product • A· B = c • A

    and B are vectors, c is scalar • A and B have the same number of components • A· B = ||A|| ||B|| cos(θ) • A· B = A1B1+A2B2+...+AnBn
  3. Vector Cross Product • A ⨯ B = C •

    C is perpendicular to A and B • In 3D • A ⨯ B = <A2B3-A3B2, A3B1-A1B3, A1B2-B2A1>
  4. Geometry • A list of polygons • I’ll use STL

    when we need examples because its simple
  5. Polygon • A list of vertices (x1,y1,z1)...(xn,yn,zn) • An orientation

    • Should exist in a plane. • Which side is the out side? What exact direction is it facing? • Vertex order can define face orientation • This is the ‘surface normal’ vector • A vector perpendicular to the surface of the polygon of magnitude 1 • If the vertex order is defined and right handed (as in .STL), face normal can be computed as a normalized (V1-V2)x(V1-V3), otherwise provided directly or as the average of vertex normals
  6. Scale Transform • Multiplication of each component by a scale

    factor • x = Sx • y = Sy • z = Sz
  7. Translation Transform • Add a vector to the current vector

    • P + T = P’ • Px = Px + Tx • Py = Py + Ty • Pz = Pz + Tz
  8. Rotation around Axis • Set of three sets of three

    equations, one for each axis • e.g. Around Z axis • x’ = x cos(θ) - y sin(θ) • y’ = x sin(θ) + y cos(θ) • z’ = z Systems for rotations around X and Y axis are similar. Easy to derive by rotating a point in a 2D plane defined by the set of axis you are not rotating around.
  9. Matrixes • Transformation equation systems can be thought of as

    a matrix. • Concatenated through multiplication • Applied through multiplication when a coordinate is considered a row or column matrix • Non commutative (order matters)
  10. All together • Compute final transformation matrix through multiplication •

    Scale, rotate, transform • Multiply transform matrix by every vertex