topical media & game development

talk show tell print

math -- animation 3

math(s) / tutorial(s)

basic trigonometric functions



  sine of angle = opposite / hypotenuse
  cosine of angle = adjacent / hypotenuse
  tangent of angle = opposite / adjacent
  

convert radians to degrees



  radians = degrees * Math.PI / 180
  degrees = radians * 180 / Math.PI
  

rotate to mouse



  dx = mouseX - sprite.x
  dy = mouseY - sprite.y
  sprite.rotation = Math.atan2(dy,dx) * 180 / Math.PI
  

create wave(s)



  public function frame(event:Event) {
  value = center + Math.sin(angle) * range;
  angle += speed;
  }
  

create circle(s)



  public function frame(event:Event) {
  x = centerX + Math.cos(angle) * radius;
  y = centerY + Math.sin(angle) * radius;
  angle += speed;
  }
  

create oval(s)



  public function frame(event:Event) {
  x = centerX + Math.cos(angle) * radiusX;
  y = centerY + Math.sin(angle) * radiusY;
  angle += speed;
  }
  

distance between point(s)



  dx = x2 - x1;
  dy = y2 - y1;
  distance = Math.sqrt(dx*dx + dy*dy);
  


(C) Æliens 04/09/2009

You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.