Author Topic: are trig finctions available on the current DB ?  (Read 3950 times)

Offline d-EVO

  • Bot Destroyer
  • ***
  • Posts: 125
    • View Profile
are trig finctions available on the current DB ?
« on: November 02, 2008, 04:41:00 PM »
are trig finctions available on the current DB ?
I read somewere that sin and atan will be suported on v3 bt are they available now.
 and how do you get cos. Is it simething like cos = sine(Pi/2 - theta)
It would be much easier if tan and cos were suported as well and Equations would be simpler.

and is the function used like this
10 60 sin to find oposit side

working on a gene that aims ahead using trig
this is it

Code: [Select]
cond
start
 *.refxpos *.refypos angle .setaim store
 1000
 1000
 *.refvel 40 mult *.refaim 10 mult 35 div sin mult
 *.refvel 40 mult 16 10 *.refaim sub 10 div sin 2 pow
 *.refvel 40 add 2 pow add
 2
 *.refvel 40 mult 16 10 *.refaim sub 10 div sin mult
 *.refvel 40 mult
 16 10 *.refaim sub 10 div sin mult
 sqrt
 sin
 mult
 .aimshoot store
 -6 .shoot store
stop

end

used the 1000 instead of 1 to get higher degree of accuracy.
am I on the right track?
   trig gives me headach so explain how to get it in simple terms
1:      2 is true
2:      1 is false

Offline Peter

  • Bot God
  • *****
  • Posts: 1177
    • View Profile
are trig finctions available on the current DB ?
« Reply #1 on: November 02, 2008, 04:55:30 PM »
As far I know, they aren't supported. Haven't hearn anything about them using anywhere. Could maybe make some sitiations simpler. You could post it as a suggestion.
Oh my god, who the hell cares.

Offline Welwordion

  • Bot Destroyer
  • ***
  • Posts: 325
    • View Profile
are trig finctions available on the current DB ?
« Reply #2 on: November 02, 2008, 05:40:31 PM »
When I last checked the were not availabe , thats also when I made a code to approximate sine and cosine for the purpose of movement
http://en.wikipedia.org/wiki/Sine <---used the series approximation of sine

[div class=\'codetop\']CODE[div class=\'codemain\' style=\'height:200px;white-space:pre;overflow:auto\']
'the input angle

*.refxpos *.refypos angle -1 mult *.aim add

'make sure the angle is within the right range

1256 add 1256 mod

'forgot which one was sin and which cos, the ceil and floor are used for the purpose of improving precision, as its easier to do values in a certain area
' and since sin and cos is a symetric function we used this to our advantage   I also used only sine and just changed the input value by 314  '90 degree

dup dup dup dup dup 314 ceil swapint
314 floor 942 ceil 314 sub sub swapint
942 floor 942 sub add 2 div
dup  0 swapint 3 pow 600 div 100 div sub add

2 div *.veldx sub .dx store

628 ceil -1 mult 314 add swapint
628 floor 628 sub add 2 div
dup 0 swapint 3 pow 600 div 100 div sub add

2 div *.velup sub .up store
« Last Edit: November 02, 2008, 05:46:14 PM by Welwordion »

Offline d-EVO

  • Bot Destroyer
  • ***
  • Posts: 125
    • View Profile
are trig finctions available on the current DB ?
« Reply #3 on: November 03, 2008, 03:27:44 PM »
It is actualy realy simple

sin x =  x - x^3/6 + x^5/120 - x^7/5040 +...

therefore

*.50 *.50 3 pow 6 div sub *.50 5 pow 120 div add *.50 store

where *.50 is x and *.51 is the value of sin x

you could continue this equation but you would not get much more acuracy considering DB does not suport decimals

since DB measures angles in radians * 200. it is not neccissary to convert it.

Like I said trig gives me head ache so if I am wrong correct me

Quote from: Peter
As far I know, they aren't supported. Haven't hearn anything about them using anywhere. Could maybe make some sitiations simpler. You could post it as a suggestion.

it is in suggestions

read the [a href=\'index.php?showtopic=2207\']command list[/a]
1:      2 is true
2:      1 is false

Offline Welwordion

  • Bot Destroyer
  • ***
  • Posts: 325
    • View Profile
are trig finctions available on the current DB ?
« Reply #4 on: November 03, 2008, 08:31:00 PM »
Actually I am using that part:  x - x^3/6  of the formula, but you are forgetting some stuff having mostly nothing to do with trigonometric function but darwinbots design.
90° is pi/2  in radian and 314 in darwinbots measurement which is circa 200 times the radian value if you use x^3, x^5, x^n this factor 200 will also get multiplied with itself so have do divide trough 200^n-1 to make the result stay correct and you have to do this at the right point as darwinbots does not use any floating numbers but just integers(whole numbers not ones with komma).
Also  the stack is limited to numbers of +-2000000000 which, when 1256^3( the highest angle )is done, is almost reached so higher ^n are highly likely to not fit in if you do not perform some tricks, however the higher the angle the more important are higher orders of ^n for accuracy.
Well my code could possibly still be  from back when stack values  could not be larger than 32000
that part  ---> 600 div 100 div makes me believe that, but I solved the problem by only using input values from (0 - 314) /2 or (-314 - 0)/2  so I just use the symmetry of sin to my advantage manipulating the input values properly by making a chainsaw function out of them.
(0)->(314)->(0)->(-314)->(0)

Also those suggestions are for darwinbots3 I think
« Last Edit: November 03, 2008, 08:36:26 PM by Welwordion »

Offline Peter

  • Bot God
  • *****
  • Posts: 1177
    • View Profile
are trig finctions available on the current DB ?
« Reply #5 on: November 04, 2008, 04:29:46 AM »
Quote from: d-EVO
it is in suggestions

read the [a href=\'index.php?showtopic=2207\']command list[/a]
That is DB3, I meant DB2.

Another bunch of calculations. I doubt my bots(me) are smart enough to use them. Who needs precision anyway.
Oh my god, who the hell cares.

Offline d-EVO

  • Bot Destroyer
  • ***
  • Posts: 125
    • View Profile
are trig finctions available on the current DB ?
« Reply #6 on: November 04, 2008, 03:51:28 PM »
Ya. I knew the angles in darwin bot ar rad * 200. but I didnt think about it enough to relize that the result would not be sin * 100. thought that it would be and I didnt bothere to change it because a rad * 200 result would be more usefull than a norm radiant. but I was wrong. If any one thinks of any ideas to use this method simply on DB but more acuratly thun the current method, post here
1:      2 is true
2:      1 is false