Guest User

math q

a guest
Aug 7th, 2011
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1. //Goal: Spawn a sinuate laser from the boss's location moving
  2. //at constant angular velocity through a circle with increasing
  3. //radius.
  4.  
  5. //Just setup for the laser
  6. let obj=Obj_Create(OBJ_SINUATE_LASER);
  7. ObjShot_SetGraphic(obj,7);
  8. Obj_SetPosition(obj,GetX,GetY);
  9. ObjSinuateLaser_SetLength(obj,40);
  10. ObjSinuateLaser_SetWidth(obj,10);
  11.  
  12. ascent(t in 0..T){
  13. //Ok, now for the motion. Pretty easy when expressed in terms of
  14. //position relative to time:
  15.  
  16. //x_pos=GetX+R*t/T*cos(W*t);
  17. //y_pos=GetY+R*t/T*sin(W*t);
  18.  
  19. //where R is the maxiumum radius, T is the time for the circle
  20. //to expand to it, and W is an arbitrary angular velocity
  21.  
  22. //As sinuate lasers must be controlled with speed & angle, this
  23. //isn't enough. The strategy is to convert the position functions
  24. //into velocity functions and generate an angle and velocity from
  25. //these.
  26.  
  27. //Differentiating the above equations with respect to t.
  28.  
  29. x_vel=R/T*cos(W*t)-W*R*t/T*sin(W*t);
  30. y_vel=R/T*sin(W*t)+W*R*t/T*cos(W*t);
  31.  
  32. //From here it's just converting the two velocities into a speed
  33. //and angle.
  34.  
  35. Obj_SetSpeed(obj,(x_vel^2+y_vel^2)^0.5);
  36. Obj_SetAngle(obj,atan2(y_vel,x_vel));
  37. yield;
  38. }
Advertisement
Add Comment
Please, Sign In to add comment