Author Topic: Moving without Turning  (Read 2443 times)

Offline Welwordion

  • Bot Destroyer
  • ***
  • Posts: 325
    • View Profile
Moving without Turning
« on: December 13, 2007, 09:59:06 AM »
This gene enables you to  move towards an object without rotating, combine this with an .aimshoot gene and you can actually face in any direction to do other stuff like tieing or repro.

For test reasons you can use:
1221 .eye5width store *.refxpos *.refypos angle -1 mult *.aim add
In the place where  'Insert angle here * is written.
Remember this gene worls only in fields smaller than 32000
(refvar can not store numbers greater than that)


cond
start
'Insert angle here *
1256 add 1256 mod

dup dup dup dup dup 314 ceil swapint
314 floor 942 ceil 314 sub sub swapint
942 floor 942 sub add 2 div *.veldx sub .dx store


628 ceil -1 mult 314 add swapint
628 floor 628 sub add 2 div *.velup sub .up store
stop


Note1: originally I wanted to make sine and cosine curves and this was only part of the formula, but the result was terrible compared to the zigzag functions this gene uses.

Note2: I developed this gene for my Beholder project and I use
*.focuseye 9 mod 140 mult
70 500 *.focuseye 4 add 9 mod add * *.eyef sub abs sgn 1 sub abs mult add
70 500 *.focuseye 6 add 9 mod add * *.eyef sub abs sgn 1 sub abs mult sub
in the insert place, which with my eye geometry works even in fields larger then 3200
compared to the refeye formulas

Offline Numsgil

  • Administrator
  • Bot God
  • *****
  • Posts: 7718
    • View Profile
Moving without Turning
« Reply #1 on: December 13, 2007, 11:42:45 AM »
Back in the day I wrote a small function in the DNA to compute the sine for angles in the range [0, pi/2].  Since then a lot of restrictions have been lifted, so you could probably do a taylor expansion of sine to an arbitrary precision level.

Offline Welwordion

  • Bot Destroyer
  • ***
  • Posts: 325
    • View Profile
Moving without Turning
« Reply #2 on: December 13, 2007, 12:07:22 PM »
I tried to do the row for cos: 1 + x^2/2! +x^4/4! +....
I only used these first 3 parts of the sum due to the fact that large potencies have to be divided to fit in the number range , nevertheless it complained and I had to use 2 pow 100 2 pow instead of 4 pow 10000 div
even though the wiki claims:
As of 2.4, you are allowed to place numbers as large as +/-2000000000

The zigzag function was used to keep the absolute of x small so that the error from abandoning larger potencies would be small( y! grows faster than x^y when x<y)
However what was retuned for some reason was rougher and more abrupt than the zigzag, and I can not afford using larger potencies due to rounding mistakes.

Offline Numsgil

  • Administrator
  • Bot God
  • *****
  • Posts: 7718
    • View Profile
Moving without Turning
« Reply #3 on: December 13, 2007, 12:24:09 PM »
Values on the stack can grow as large as +- 2 billion, but the values that you can put as constants need to be in the range +- 32000 because they're part of the DNA.

You might need to find another taylor expansion, or expand a different expansion depending on the quadrant, to compensate for numerical issues.  It should be pretty challenging, but I'm sure it's doable.  You only really need a value in the range +- 1000, so I think it should be possible.

Offline Welwordion

  • Bot Destroyer
  • ***
  • Posts: 325
    • View Profile
Moving without Turning
« Reply #4 on: December 13, 2007, 01:25:29 PM »
Well first I also had tried this  once before back in the day, and it was the number limitation that made me stop it then, second I known that the stack is meant with the 2 billion range I had divided numbers after calculation but like I tried to say darwinbots gave me an error message nevertheless.
(maybe something was wrong wih the input mechansim  that was supposed to produced input values between -157 and 157 ? ...However I had test stored the numbers to chack this and nothing seemed wrong)
Well I will take alook into it again but do not promise yourself to much.

Edited: ok found out what was wrong the I divided trough 120000 seems I am not allowed to write numbers in the code that are larger than 32000 so I have to write 120 1000 mult now lets  see If this increases the precision a little.
Hm something still is wrong I will continue tommorow to search for mistakes.
« Last Edit: December 13, 2007, 03:10:31 PM by Welwordion »

Offline Numsgil

  • Administrator
  • Bot God
  • *****
  • Posts: 7718
    • View Profile
Moving without Turning
« Reply #5 on: December 14, 2007, 11:11:21 AM »
Check out this page, about halfway down, under Hardy's approximation.  It's only for the range [0, pi/2], but the approximation is pretty solid, and wouldn't be hard to implement in DNA.

Offline Numsgil

  • Administrator
  • Bot God
  • *****
  • Posts: 7718
    • View Profile
Moving without Turning
« Reply #6 on: December 14, 2007, 12:12:16 PM »

Offline Welwordion

  • Bot Destroyer
  • ***
  • Posts: 325
    • View Profile
Moving without Turning
« Reply #7 on: December 15, 2007, 09:11:07 AM »
Hit me I just used to many "dup" and at the wrong places.
So the first correction is hereby

cond
start
1221 .eye5width store *.refxpos *.refypos angle -1 mult *.aim add
1256 add 1256 mod

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

stop
« Last Edit: December 16, 2007, 05:53:40 PM by Welwordion »

Offline rsucoop

  • Bot Destroyer
  • ***
  • Posts: 166
    • View Profile
Moving without Turning
« Reply #8 on: February 09, 2008, 10:44:59 PM »
Quote from: Numsgil
Values on the stack can grow as large as +- 2 billion, but the values that you can put as constants need to be in the range +- 32000 because they're part of the DNA.

You might need to find another taylor expansion, or expand a different expansion depending on the quadrant, to compensate for numerical issues.  It should be pretty challenging, but I'm sure it's doable.  You only really need a value in the range +- 1000, so I think it should be possible.

You would have to perform a module function on each value in the stack to wrap around the magic number. That shouldn't be too hard, since the math involved is simple division.
 [code]
Example
`2@ 0' 0" mod 24' would be interpreted as two degrees modulo 24 radians. So you take your results and make them run mod to say 32000 to prevent any errors that might befall your design. Oddly enough, this would create an Eliptical Curve.
So I say post your original Sine Curves and wrap them around 32000 parts of a circle instead of just 360.