algorithm - Count or detect sprites passing from lines -


i have simulation in thousands of agents (multi-pixel sprites) move different directions. there imaginary (not drawn in space) detection lines in simulation space, specified coordinates.

what efficient method of detecting , counting agents pass each of lines? (only first time agent passes line counted).

two simple methods come mind:

1- in each simulation step (after agents have moved 1 pixel) draw imaginary lines , see agents lines cut, increase counter lines , mark agent passed through specific lines.

2- each "agent move", check whether on line (how? draw line each time?) , again save line passed , increase counter of line.

enter image description here

i think approach lot of objects , few lines following:

first, after object move, calculate equation of line against center, if it's way off (the effective distance moer radius), check if object close line before (via list attached line), if so, drop reference list. if it's close enough, perform thorough test against object's shape , line, if intersect, record object "just intersected", , add reference line's list of nearby objects.

if objects mathematical dots, , lines infinite, give objects set of boolean values, each corresponding line, , true value indicatin g positive result of equation, , false indicating negative, , check each move if sign flipped. each flip indicates crossing of line.

this method allows correctly detect intersections, exclude unnecessary calculations if objects' shapes complex (for circles if distance line less radius, intersect) , keeps track of intersections last more 1 iteration of movement.


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -