Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "fbgfx.bi"
- type coord
- x as integer
- y as integer
- end type
- function dotProduct(u as coord, v as coord) as double
- return (u.x * v.x) + (u.y * v.y)
- end function
- function norm(u as coord) as double
- return sqr((u.x*u.x) + (u.y*u.y))
- end function
- dim as coord a = type(260, 50)
- dim as coord b = type(160, 100)
- screenres 640, 480, 8
- dim as coord c = type(1, 0) ' C is the unit vector pointing left
- ' Make b into a vector where the origin is at 'a', not (0, 0)
- b.x = a.x-b.x
- b.y = a.y-b.y
- ' Find the angle between b and c
- dim as double angle = acos(dotProduct(c, b)/(norm(c)*norm(b)))
- const PI = atn(1)/45
- #define RadToAng( _R ) (_R)/PI
- do
- if multikey(fb.SC_LEFT) then
- b.x -= 1
- end if
- if multikey(fb.SC_RIGHT) then
- b.x += 1
- end if
- if multikey(fb.SC_UP) then
- b.y -= 1
- end if
- if multikey(fb.SC_DOWN) then
- b.y += 1
- end if
- screenlock
- cls
- angle = acos(dotProduct(c, b)/(norm(c)*norm(b)))
- locate(0, 0)
- print "a = (";a.x;",";a.y;")"
- print "b = (";b.x;",";b.y;")"
- print "c = (";c.x;",";c.y;")"
- print "angle =";RadToAng(angle);" degrees"
- ' Line from origin pointing to other point
- if b.y > 0 then
- line(a.x, a.y)-step(10*cos(angle), 10*sin(angle)), &H8
- else
- line(a.x, a.y)-step(10*cos(angle), -10*sin(angle)), &H8
- end if
- pset(a.x, a.y), &HF ' Origin (where we rotate from)
- pset(a.x+b.x, a.y+b.y), &HE ' Point we're pointing to
- screenunlock
- sleep 10,1
- loop until multikey(1)
- sleep
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement