Dark Bit Factory & Gravity
PROGRAMMING => Other languages => Yabasic => Topic started by: slinks on August 16, 2011
-
Well, after a full morning of struggling, time to admit, I need help! Just fired up yabasic for the first time in a good few years, and already managed to get myself stuck!
Currently what i have is as follows
variable= (anything betwen 0 and 360)
sin(variable)=a
sin(variable+90)=b
sin(variable+180)=c
sin(variable+270)=d
assuming that the variable is zero, the answers I would expect would of course be 0,1,0 and -1. But yabasic is quite helpfully giving me the answers in radians, so instead of a rotating square, I now have a rather odd looking trapezium :(
Any idea where I'm getting this wrong?
-
variable= (anything betwen 0 and 2*pi)
sin((variable)*pi/180)=a
sin((variable+90)*pi/180)=b
sin((variable+180)*pi/180)=c
sin((variable+270)*pi/180)=d
It's the input that is expected in radians the output is the y component of a unit vector
-
This still doesn't seem to be giving me values that are right? Increasing the 180 to 360 brings it a little closer but still off the mark. Is there an easier way of grabbing the values of a sine curve at exactly 90 degrees apart?
-
cos(angle+pi*0/2), sin(angle+pi*0/2) // forward
cos(angle+pi*1/2), sin(angle+pi*1/2) // right
cos(angle+pi*2/2), sin(angle+pi*2/2) // backward
cos(angle+pi*3/2), sin(angle+pi*3/2) // left
pi = 180 degrees, that means that pi/180 = 1 degree expressed in radians, if you wish to stick with degrees it requires expensive multiplications (by preprocessing the conversion ration pi/180). If you keep the angles in radians then its simply additions (by preprocessing pi/2)
open window 640, 512
window origin "cc"
repeat
setdispbuf draw
draw = 1 - draw
setdrawbuf draw
clear window
c = peek("port1")
if (and(c, 32) > 0) angle = angle + pi/64
if (and(c,128) > 0) angle = angle - pi/64
line 0,0 to 64*cos(angle+pi*0/2), 64*sin(angle+pi*0/2)
line 0,0 to 64*cos(angle+pi*1/2), 64*sin(angle+pi*1/2)
line 0,0 to 64*cos(angle+pi*2/2), 64*sin(angle+pi*2/2)
line 0,0 to 64*cos(angle+pi*3/2), 64*sin(angle+pi*3/2)
until (0 = 1)
open window 640, 512
window origin "cc"
repeat
setdispbuf draw
draw = 1 - draw
setdrawbuf draw
clear window
c = peek("port1")
if (and(c, 32) > 0) angle = angle + 1
if (and(c,128) > 0) angle = angle - 1
line 0,0 to 64*cos((angle+000)*pi/180), 64*sin((angle+000)*pi/180)
line 0,0 to 64*cos((angle+090)*pi/180), 64*sin((angle+090)*pi/180)
line 0,0 to 64*cos((angle+180)*pi/180), 64*sin((angle+180)*pi/180)
line 0,0 to 64*cos((angle+270)*pi/180), 64*sin((angle+270)*pi/180)
until (0 = 1)
-
Perfect, that's exactly what I was looking for, thank you! K+
Wish I'd have done radians in school