Author Topic: ID10T problem  (Read 4455 times)

0 Members and 1 Guest are viewing this topic.

Offline slinks

  • A little bit strange
  • DBF Aficionado
  • ******
  • Posts: 3963
  • Karma: 43
    • View Profile
ID10T problem
« 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

Code: [Select]
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?
I love semi-colons way too much ^^;
Challenge Trophies Won:

Offline rain_storm

  • Here comes the Rain
  • DBF Aficionado
  • ******
  • Posts: 3088
  • Karma: 182
  • Rain never hurt nobody
    • View Profile
    • org_100h
Re: ID10T problem
« Reply #1 on: August 16, 2011 »
Code: [Select]
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

Challenge Trophies Won:

Offline slinks

  • A little bit strange
  • DBF Aficionado
  • ******
  • Posts: 3963
  • Karma: 43
    • View Profile
Re: ID10T problem
« Reply #2 on: August 16, 2011 »
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?
I love semi-colons way too much ^^;
Challenge Trophies Won:

Offline rain_storm

  • Here comes the Rain
  • DBF Aficionado
  • ******
  • Posts: 3088
  • Karma: 182
  • Rain never hurt nobody
    • View Profile
    • org_100h
Re: ID10T problem
« Reply #3 on: August 16, 2011 »
Code: [Select]
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)

Code: [Select]
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)

Code: [Select]
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)
« Last Edit: August 16, 2011 by rain_storm »

Challenge Trophies Won:

Offline slinks

  • A little bit strange
  • DBF Aficionado
  • ******
  • Posts: 3963
  • Karma: 43
    • View Profile
Re: ID10T problem
« Reply #4 on: August 16, 2011 »
Perfect, that's exactly what I was looking for, thank you! K+

Wish I'd have done radians in school
I love semi-colons way too much ^^;
Challenge Trophies Won: