[ create a new paste ] login | about

Link: http://codepad.org/tjaijHpT    [ raw code | output | fork ]

hurracane - Scheme, pasted on Mar 24:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
    ;http://en.wikipedia.org/wiki/Atan2
    (define (atan2 x y)
      (* 2 (atan (/ (- (sqrt (+ (expt x 2)
                                (expt y 2)))
                       x)
                    y))))
    ;Orig is a position (vector), speed is a number. Function returns the speedvec required to move to this direction
    (define (vectorToAngles orig speed)
      (let* ((to_x (orig 'getX))
             (to_y (orig 'getY))
             (from_x (getX vector))
             (from_y (getY vector)))
        (println "from = " vector " -- to = " orig)
        (define angle (atan2 (- to_x from_y) (- to_x from_y)))
        (((makeVector (cos angle) (sin angle)) 'vec*) speed)))


Output:
1
Line 14:8: define: not allowed in an expression context in: (define angle (atan2 (- to_x from_y) (- to_x from_y)))


Create a new paste based on this one


Comments: