Welcome To Darwinbots > Newbie

are trig finctions available on the current DB ?

(1/2) > >>

d-EVO:
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: ---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
--- End code ---

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

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.

Welwordion:
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

d-EVO:
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.
--- End quote ---

it is in suggestions

read the [a href=\'index.php?showtopic=2207\']command list[/a]

Welwordion:
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

Navigation

[0] Message Index

[#] Next page

Go to full version