tricki path problem

Started by
10 comments, last by katanasi 21 years, 10 months ago
quote:Original post by Puzzler183
I may not be understanding this all so is he just try to move the line segements?


Sort of. He wants an object to follow a path that runs parallel to the wall segments.

Timkin
Advertisement
Well, here's the psuedocode for Timkin's wall following algorithm !!!

I've made a subtle change to my original idea which makes it code up slightly easier. The algorithm provides a circular path for convex corners and a sharp turn for concave corners. It should always stay a distance r from the wall... the only condition on this is the errors introduced by the linear interpolation function (LERP) which you can write yourself or get from online. If your frame rate is high enough, you should never notice this error. You'll need to provide your own frame rate estimation routine as well. I hope everything is self explanatory. If it's not, please let me know and I'll explain as best I can.

Known values (set all these to appropriate values)

x(0),x(1),y(0),y(1): endpoints for all line segments
x'(0),y'(0): starting coordinates of object
r: computed from known starting coordinates and equation of line.
V: speed of moving object


for i=1 to NumberOfLineSegments{   FPS = GetCurrentFramesPerSecond()   Li = sqrt( (xi(1)-xi(0))2 + (yi(1)-yi(0))2 )   stotal = Li/V   ds = 1/(stotal*FPS)   if (mi < mi+1)   {      theta=atan(mi)      s = 0      while(theta!=atan(mi+1))      {         ri+1 = sqrt( (xi(1)-x_curr)2 + (yi(1)-y_curr)2 )         if (ri+1==r)            m = LERP(m,mi+1,ds)         else            m = mi               Vx = sqrt(V2/(1+m2))         Vy = sqrt(m2V2/(1+m2))         x_curr = x_curr+ds*Vx         y_curr = y_curr+ds*Vy         s = s + ds         theta = atan(m)      }   }   else   {      ri+1 = sqrt((xi(1)-x_curr)2 + (yi(1)-y_curr)2 )      phi = atan(mi+1)-atan(mi)      r' = r/cos(phi/2)      m = mi      while (ri+1!=r')      {         Vx = sqrt(V2/(1+m2))         Vy = sqrt(m2V2/(1+m2))         x_curr = x_curr+ds*Vx         y_curr = y_curr+ds*Vy         ri+1 = sqrt((xi(1)-x_curr)2 + (yi(1)-y_curr)2 )      }   }}           


This code has only been tested on paper. It should work on your computer!!! Good luck and let me know how it goes please.

Cheers,

Timkin

[edited by - Timkin on June 4, 2002 1:38:51 AM]

This topic is closed to new replies.

Advertisement