Pythagorus n Stuff

part of 3d tech for the web course

Aims and Objectives

coordinates and triangles

some trigonometry

pythagorus

code

Pythagorus

Triangles and Coordinates

Sphere Distance

Sphere Collision

Distance

Collision Code

Goal: To Tell if two Object Have Collided

Collided Means: When their centres are closer than the sum of their sizes

Centres: position coordinates

Sizes: a number representing radius (say)

Collision Code

  // PSEUDOCODE
    if ( distance_between(object_a, object_b) < size(object_a) + size(object_b))
    {
        output ("COLLISION");
        // DO SOMETHING
    }
  

Collision Code

    distance = Math.sqrt(
              ((firstBall.x - secondBall.x) * (firstBall.x – secondBall.x))
            + ((firstBall.y - secondBall.y) * (firstBall.y – secondBall.y))
             );
  
      if (distance < firstBall.radius + secondBall.radius)
      {
          //balls have collided
      }
  

Further Reading

https://www.slideshare.net/mobart02/rectangular-coordinate-system-graphs

Thanks