Jump to content

  • Log In with Google      Sign In   
  • Create Account


noobnerd

Member Since 08 Nov 2011
Offline Last Active Feb 05 2013 07:07 AM

#4883829 Advanced motion prediction ( 2D ) help

Posted by noobnerd on 14 November 2011 - 10:52 AM

Wooohoo it works!

mostly...Posted Image

i managed to code it down, and just as you said, IT WORKS!
but sometimes it will give me negative values which obviously dont work. Also sometimes it gives me quite normal values which dont work???

i dont seem to be allowed to attach .exes nor .rar files?

well here is a download link for a .rar containing a test app that i made. HERE

leftclick to place the shooter, press space to "drive" the target forward, press enter to shoot and press space to return from shooting.

the value in the topleft corner is the value of t after 25 iterations of the Newton rahson method. i tried others but 25 seemed to be fine and very accurate for this quick test. ( 4 wasnt accurate enough)

oh and the litle white dot is where you should aim ( with the mouse)


the code of the newton calculation :


a# = rx#-x2# : b# = ry#-y2# : p# = pi()
v1# = 2*a#*h#*r# : v2# = 2*b#*h#*r# : v3# = -2*v#^2 : v4# = r#^2+a#^2+b#^2 : v5# = r#*2*b# : v6# = r#*2*a# : t0# = sqrt((x1#-x2#)^2+(y1#-y2#)^2)/v#
for i = 1 to 25
t0# = t0# - (v4#-t0#^2*v#^2+v5#*cos(h#*t0#+g#)+v6#*sin(h#*t0#+g#))/(v1#*cos(h#*t0#+g#)-v2#*sin(h#*t0#+g#)-v3#*t0#)
next

its DarkBasic code. might be quite unclear as it is so stacked.

rx#,ry# = coordinates of the center of the targets "circle"
x2#,y2# = coordinates of the shooter
h# = turnrate of target
r# = radius
v# = velocity
x1#,y1# = coordinates of target
g# = radiuss initial angle
t0# = the value of t#

any ideas of how to avoid negative and wrong values? i would rather it gave a blank than giving wrongs ...


#4882147 Advanced motion prediction ( 2D ) help

Posted by noobnerd on 09 November 2011 - 09:39 AM

Wow thanks for a fast reply!
yes that is what i did in the case without turning, but i cant seem to find a way to get this done numerically. My problem is, that the only way i manage to describe the motion of the target is with a function containin Sin and Cos both with an unkown inside... i dont know how to extract those :(

Could you possibly help me with this?


PARTNERS