distance between two points

42 views
Skip to first unread message

Suhad Faisal

unread,
Sep 26, 2014, 8:34:31 AM9/26/14
to
Hello 

please, I need to compute the speed via (euclidean distance/time), so I use the following code, Gama accept this code but in execution the result is division by zero , it seems that distance is not computed.

timings     <- init_data[8,i];                                       // the time value
oldtarget  <- point([posx, posy]) ;                           // first point
newtarget <- point([posx1,posy1]);                         //second point
distance   <- (oldtarget) distance_to (newtarget) ; // the distance between the two points
speedy     <- distance/timings ;                             // the speed of distance divided by speed 


thanks in advance for your recommendations 

cheers 
suhad

Arnaud Grignard

unread,
Sep 26, 2014, 8:49:18 AM9/26/14
to gama-platform
Hi,

As you seem to have a division by zero in your case it seems that the problem does not come from the distance but from timings.

Are you sure you have some data in the variable timings or maybe you simply have one of the value that is equal to 0? (You can check it by doing write timings in GAML)

Arnaud

On Fri, Sep 26, 2014 at 2:34 PM, Suhad Faisal <suha...@gmail.com> wrote:
Hello 

please, I need to compute the speed so I use the following code, Gama accept this code but in execution the result is division by zero , it seems that distance is not computed.

timings     <- init_data[8,i];                                       // the time value
oldtarget  <- point([posx, posy]) ;                           // first point
newtarget <- point([posx1,posy1]);                         //second point
distance   <- (oldtarget) distance_to (newtarget) ; // the distance between the two points
speedy     <- distance/timings ;                             // the speed of distance divided by speed 


thanks in advance for your recommendations 

cheers 
suhad

--
You received this message because you are subscribed to the Google Groups "GAMA" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gama-platfor...@googlegroups.com.
To post to this group, send email to gama-p...@googlegroups.com.
Visit this group at http://groups.google.com/group/gama-platform.
For more options, visit https://groups.google.com/d/optout.

Suhad Faisal

unread,
Sep 26, 2014, 9:15:35 AM9/26/14
to gama-p...@googlegroups.com
Thanks dear Arnau

I will check the values

cheers
Suhad

--
You received this message because you are subscribed to a topic in the Google Groups "GAMA" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/gama-platform/g64pLwe-Fl0/unsubscribe.
To unsubscribe from this group and all its topics, send an email to gama-platfor...@googlegroups.com.

Suhad Faisal

unread,
Sep 26, 2014, 9:54:54 AM9/26/14
to
Dear Arnaud 

your note was very useful to me and the time was read wrongly, the erroe fixed 

but please I want to relate my lines of data with the simulation cyle (each row of the matrix represented in one simulation cycle ) ... the code is below

thanks in advance 

cheers
Suhad

global 
{   matrix<int>  init_data <- matrix<int>(csv_file('../includes/alias2191258Date.csv', ';'));
file     Voronoi<-file('../includes/VoronoiVoronoi.shp');
geometry shapeworld  <- envelope(Voronoi);
init 
{ create towervoronoi  from: Voronoi  header:true;
create aliasrep ;   } 

species aliasrep skills:[moving]
 {  int   towerid  ;
    int   posx     ;
    int   posy     ;
    int   posx1    ;  
    int   posy1    ;
    int   timings  ;
    point oldtarget;
    point newtarget;
    float distance ;
    float speedy   ;

reflex matrixreading  update:every cycle {
      loop i from: 1 to: init_data.rows-1 {
      loop j from: 0 to: init_data.columns-1 {

         if j=0 {towerid <- init_data[j,i]; write towerid             ; }
 if j=1 {posx    <- init_data[j,i]; posx1  <- init_data[j,i+1]; }
         if j=2 {posy    <- init_data[j,i]; posy1  <- init_data[j,i+1]; }
         if j=7 {timings <- init_data[j,i]; write "time  "+ timings   ; }
         
                                          }
      oldtarget <-point([posx, posy]) ;  write "OLD    "+ oldtarget ;
      newtarget <-point([posx1,posy1]); write "NEW    " +newtarget ; 
                 
        if oldtarget!=newtarget    
     { distance  <- oldtarget distance_to newtarget;
      speedy    <-distance/timings ;
      write "Dis    " + distance ;
      write "Speed  " + speedy   ; 
     }
    do  goto   target: newtarget  return_path:true speed:speedy ; 
    } }  //closing i loop & reflex matrixreading
aspect basealias{ 
            draw circle(1)     color:rgb('red')          ;
                 draw '  '+ towerid color:rgb('black') size:3 ; 
 }   }  //closing aspect & species
species towervoronoi { 
aspect towericon { draw shape color:rgb(52,52,52); 
              draw rectangle(1,1500) color:rgb('black') at:location;
}   }

}
experiment Trajectory type: gui  {
   output { display  city_display type:java2D
 { image    'background'     file:'../includes/DivisionVoronoi.jpg';
species  towervoronoi   aspect: towericon     transparency: 0.7;
species  aliasrep       aspect: basealias;
Reply all
Reply to author
Forward
0 new messages