• No results found

Sweep-Tiling for Continuous Broad Phase Collision Detection in 2D

N/A
N/A
Protected

Academic year: 2021

Share "Sweep-Tiling for Continuous Broad Phase Collision Detection in 2D"

Copied!
69
0
0

Bezig met laden.... (Bekijk nu de volledige tekst)

Hele tekst

(1)

Sweep-Tiling for Continuous Broad Phase Collision Detection in 2D

Bachelor Thesis

Author:

Coenraad B. E. Meijer

Student Computer Science at the University of Groningen

Supervisor:

Dr. Michael F. Wilkinson Senior Lecturer Computer Science

Second reader:

Prof. dr. Alexandru C. Telea

Professor Computer Science

(2)

Contents

1 Introduction 3

2 Kinetic Data Structures and Sweep-line Algorithms 6

2.1 Measures of Performance . . . . 7

2.2 KDS measurements as applied to broad phase collision detection 8 2.3 Sweep-line Algorithms . . . . 8

2.4 A Note on robustness. . . . 9

3 Previous Work 9 3.1 Spartial Subdivision . . . . 9

3.2 Sweep-and-Prune . . . . 10

3.3 Deformable free-space tiling . . . . 13

4 Description of sweep-tiling /main contribution 13 4.1 Pseudocode . . . . 14

4.2 Initialization . . . . 15

4.3 Maintaining the Sweep-tiling in Motion . . . . 15

4.4 The number of tiles . . . . 18

4.5 Theoretical performance . . . . 18

5 Description of Implementation 20 5.1 Implementation choices . . . . 20

5.2 Robustness . . . . 25

5.3 Bechmarks . . . . 28

5.3.1 Execution time . . . . 29

5.3.2 Efficiency . . . . 29

6 Discussion 32 7 Future Work 34 7.1 Design . . . . 34

7.2 Comparisons to other methods or implementations . . . . 34

7.3 Expansion into 3D . . . . 35

A Code listings 40 A.1 Naive method . . . . 40

A.2 Sweep-and-prune Method . . . . 42

A.2.1 Interval List . . . . 45

A.2.2 Disk Bound . . . . 46

A.3 tile-bound method . . . . 47

A.3.1 Tile Bound . . . . 55

A.3.2 Face . . . . 56

A.4 sweep-and-prune matrix . . . . 57

A.4.1 disc bound matrix . . . . 60

A.4.2 reference matrix . . . . 61

A.5 Helper classes . . . . 61

A.5.1 event math . . . . 61

A.6 Geometry Package . . . . 63

A.6.1 Vector2d . . . . 63

(3)

A.6.2 Line . . . . 64

A.6.3 Disc . . . . 64

A.6.4 common . . . . 65

A.7 Events Package . . . . 66

A.7.1 event.py . . . . 66

A.7.2 collision event . . . . 67

A.7.3 wall collision event . . . . 67

A.7.4 stop event . . . . 67

A.7.5 stop event . . . . 68

A.7.6 interval event (for sweep-and-prune) . . . . 68

(4)

Figure 1: An example of an application of collision detection in 2D

1 Introduction

There is a wide range of applications for simulated geometrical environments, both in 2D and 3D. In fig. 1 we see a fast moving object about to collide with an stationary object, which is then expected to move also. In this game it is important to know if and when a collision takes place so it can adjust the speeds of the colliding objects. Here there are many different objects in close proximity that could collide. It is a challenge to evaluate all the possibilities for collisions without taking so much time it would slow down the game.

In fig. 2 We see an image of a intersection with a lot of traffic. To simulate traffic realistically it is important that vehicles do not move through each other.

Vehicles will try to avoid collision, with other vehicles or with stationary objects.

In order to simulate that accurately we need to assess what collisions could occur in order to avoid them. The number of objects in these simulations are likely very large, but not every vehicle is close to every other vehicle, so it may pay to keep track of the proximity between the vehicles to cut back on the number of collisions to be evaluated.

In virtual reality for instance two objects passing through each other make the environment much less believable to the observer [6]. It is also important that any collisions are detected and processed quickly enough so that it does not slow down the simulation or cause drops in frame-rate. When virtual reality is interactive the path of some objects can be unpredictable so it is important that the simulation is quick to respond to any changes. When simulating traffic a collision between objects ideally does not happen, but when it happens it is important for the user to know about it.

In the field of robotics collision detection is also important. In robotics it is important for a robot or self-driving car to maneuver without colliding with the objects in its surroundings [16]. Collision detection algorithms can predict if a movement will cause a collision with other objects.

The field of collision detection is large and varied and includes covers rigid and deformable objects, penetrating and non-penetrating objects, collisions be- tween simple shapes such as spheres or convex polygons and detailed objects with a large polyhedral mesh. In this thesis I will concentrate on collisions between rigid, convex, non-penetrating objects.

In some cases we are able to describe the motion of simulated objects as rel-

(5)

Figure 2: An application of collision detection in simulation

Figure 3: Sometimes a low-polynomial description of the flight plan of an object can be given. In the case shown here the time of collision can be calculated by solving the equation k ~ z a (t) − ~ z b (t)k = r a + r b for t.

atively simple, low-polynomial functions. In such cases we can mathematically make an exact prediction if and when two given objects are going to collide.

(see fig. 3)

When handling more objects we can do this for each pair within the set of shapes. We store all collision events calculated in a queue. Whenever an collision occurs between two shapes both shapes need to update their collisions. This means that these shapes recalculate new collision times for each other object and remove the collision events they where involved in before the collision from the queue. (see fig. 4) Generally the time for a queue operation is O[log(n)]

where n is the size of the queue. The number of pairs for a set of n objects is n(n − 1)/2. For large n this becomes prohibitively expensive.

For this reason when dealing with a lot of different objects collision detection

can be broken up into a broad phase and a narrow phase [5, 17]. The goal of the

broad phase is to make a selection of pairs that excludes any pairs it determines

cannot collide. This is sometimes also referred to as pruning. This selection of

pairs is then processed by the narrow phase collision detection which determines

the actual collisions. Narrow phase collision detection can be resource intensive,

so it is important for the Broad Phase select as few pairs as possible without

using too many resources itself.

(6)

Figure 4: Disc a and disc b have a collison time when calculated through the method showed in figure 3. The positions of the discs at the calculated times are shown with striped borders. If disc b collides with disc c first the collision between a and b will not occur at the calculated time.

Broad phase collision detection methods often make use of bounding vol- umes. The idea behind bounding volumes is that while the bounding volumes are distinct, the objects contained in them cannot collide. Bounding Volumes are simple volumes to make it easier to determine whether objects collide or not. Examples of Bounding volumes are bounding spheres, axes aligned bound- ing boxes (AABBs) or convex hulls.

Methods of Collision Detection can be classified as static, pseudo-dynamic and dynamic [13]. Static refers to one time methods to determine if objects collide or overlap in a static configuration. Pseudo-dynamic collision detection applies static collision detection to a series of snapshots of a moving scene at regular intervals. Such a snapshot is generated using the speed of an object and the position in the last frame. Dynamic collision detection derives the precise time of collision from the shape and motion of the objects without using frames or snapshots.

Pseudo-dynamic collision detection can suffer from temporal aliasing. Some- times two simulated objects can connect and become distinct again between two snapshots. In these cases a collision is missed. Precision can be improved by in- creasing the number of snapshots of the simulation, but this comes at the cost of performance and this solution suffers from diminishing returns for higher frame rates.

Dynamic collision detection does not suffer from temporal aliasing, but places more restrictions on the type of movements of the objects. If the move- ment of the objects cannot be described by relatively simple or low polynomial functions determining the exact moment of collision becomes difficult.

Dynamic collision detection methods are Kinetic Data Structures or KDS’s [12]. A KDS is a proof for a geometric attribute over time, in the case of collision detection the attribute that different objects do not overlap. KDSs will be explained in more detail in section 2.

In this thesis a new type of continuous broad phase collision detection is presented that works in 2D that for n objects produces O(n) pairs and takes up O(n) space. It is similar to dynamic sweep-and-prune which is more broadly applicable but produces worst case O(n 2 ) number of pairs.

The rest of this thesis will be as follows: In section 2 we will describe Kinetic

Data Structures. Also we will be going into some examples that will be helpful in

understanding other algorithms described throughout this paper. In section 3 we

(7)

(a) four points on a line (b) The moment of a change in bound order of the points in the list

(c) Overlap between two projections

Figure 5: A swap event that changes the order of the points on a line in the dynamically sorted list.

will look at previous work on collision detection, particularly sweep-and-prune.

In section 4 we will present a new method of broad phase collision detection in detail. In section 5 we will describe an implementation of the new method and of sweep-and-prune and compare benchmarks. Section 6 discusses our results.

Section 7 is on future work.

Throughout the thesis we will use elastically colliding discs or spheres as example objects. Also we will assume linear motion. This is mainly for the sake of simplicity.

2 Kinetic Data Structures and Sweep-line Algo- rithms

Kinetic Data Structures are a class of algorithm that deals with geometrical objects in motion. This makes it a natural fit for collision detection. In this section we will describe at Kinetic Data Structures in general as a preparation for describing broad phase collision detection as a KDS in the following sections.

Also we will cover an example in detail that will tie in with sweep-and-prune, a method described in section 3.

A (static) geometric proof can be seen as a collection of assertions concerning a simple geometric relation or certificates from which follows a certain attribute.

When we introduce motion some of these assertions will fail. When a certificate fails we update the proof by making new certificates. A certificate failure can lead to a change in the attribute. A Kinetic Data Structure is such a collection of assertions together with rules on how to restore a proof when an assertion fails.

For a simple example let us consider the dynamically sorted list [1]: There is a set of points on a horizontal line. Suppose want to know the order of the points from left to right. This is our attribute. We can obtain this simply by sorting the points according to their x coordinates. (see fig. 5a)

Now we introduce motion to the points. We want to maintain a sorted list of the points on the line. This is guaranteed as long as each point in this list is left of the point next on this list (except for the last point). These are our assertions. When one of our assertions fails - when a point moves to the right of a point that is next on the list (see fig. 5b) - our KDS no longer reflects the configuration and needs to be updated.

First we restore the attribute. We do this by moving the point that caused

the attribute to break one place to the right in the list(see fig. 5b). This will

(8)

cause the points of the list to be sorted again(see fig. 5c). Then we need new assertions to maintain the proof. In this case we add assertions that the point that was moved up the list is to the left of the point that is now next on the list. Also we need to add similar assertions for the two points directly previous in the list.

Each object in a KDS is assigned a flight plan. A flight plan is an explicit mathematical description of the motion of an object in the near future. Presum- ing the motion of the subjects of the geometric relations is described in simple functions we can predict when a particular certificate is going to fail. The fail- ure of a certificate during motion is called an event. Events are stored in an event queue, according to their earliest failure time. Event queues are often implemented using a balanced tree or a heap. The cost of adding or removing an event is typically O[log(n)], where n is the number of items in the queue.

In our previous example of the points on the line let us suppose the points display linear motion. Their flight plans can be described in a formula x p = a p t + b p . From this description we can derive if and when a certain assertion is going to fail; for two points p and next in the list q we can see that the p is going to surpass point q at moment t = (b q − b p )/(a p − a q ) provided t is in the future.

a KDS has a main loop that repeatedly takes the first event from the stack and restores the proof and sometimes updates the attribute. In this respect it is similar to event driven simulations and sweep-line algorithms.

2.1 Measures of Performance

When measuring the performance of a kinetic data structure only measuring run time is not always adequate. This is because a simulation usually does not aim to provide one answer after which the program can stop. There are a few standard measures of performance [12]:

Responsiveness: A KDS is responsive if the cost of repairing the proof and the attribute after a certificate failure is relatively small. Leonas Guibass [12]

defines “small” as being poly-logarithmic in size. Most often the biggest cost of handling an event is updating the event queue.

Efficiency: A KDS is efficient if the number of certificate failures (or events) is in proportion to the number of the combinatorial changes to the attribute.

This often means that the ratio of the total number of events to the number of external events is small. External events are events that change the attribute of the KSD. Events that are not external exist only to maintain the KDS and do not produce output.

Compactness: A KDS is compact if the number of cached certificates is pro- portional to the size of the input. Compactness is linked to the memory space the algorithm needs to execute since cached certificates appear as events in the event queue.

The times to insert and delete events in the queue are dependent on the

size of the queue, thus the compactness also has a small influences the

responsiveness of a KDS.

(9)

Locality: A KDS is local if no particular object is involved in too many cer- tificates. This property reflects the performance because when the flight plan of a particular object changes its flight plan the this influences all the times that the it certificates is involved in fail. This not only means that these times will have to be calculated anew, but also that the event queue needs to be reordered.

2.2 KDS measurements as applied to broad phase collision detection

In the case of broad phase collision detection the attribute we try to maintain is a set of candidate pairs. However, the broad phase of collision detection is only half of an algorithm. When considering the efficiency of the broad phase of the collision detection counting the combinatorial changes to the list of pairs is not really representative of the true efficiency. A better measure would be to count the number of actual collisions in relation to the number of events handled. However, this is hard to predict, especially when we do not know anything about the narrow phase of the collision detection.

There is no guarantee that a pair reported by the broad phase collision detection will lead to an actual collision and potentially none of them will. In this case the ratio of actual collisions to events is undefined or infinity. For these reasons we will not be able to give an exact efficiency of our algorithms. Instead we will give estimates of the efficiency in this thesis.

Also the number of pairs has to be taken into account when describing the performance of broad phase collision detection. Consider a “method” that does not filter out any pairs. It does not update its attribute at all, it has no cached certificates and no object is involved in any certificate. According to all other measurements mentioned here this is the ideal broad phase collision detection.

Clearly this is not what we think of when we think of a well-performing pruning.

2.3 Sweep-line Algorithms

Another kind of kinetic algorithm is the sweep-line algorithm. Unlike a KDS a sweep-line algorithm deals with a static scene. A way to explain the difference between a sweep-line algorithm and a KDS is that a sweep-line algorithm treats one of the axes of the space of the problem as a time axis. We visualize this by imagining a so called sweep-line that sweeps across a plane. The state of a sweep-line algorithm usually describes the intersection of this sweep-line with the plane of problem. Events are points on the plane that change the state.

An example of this can be seen in fig. 6. In this example of an sweepline al- gorithm that finds the intersection points of a collection of line segments. When the sweepline moves across the configuration it intersects with the different seg- ments. The points of intersection can be seen as moving along the sweepline.

We maintain a list of these points sorted according to their position on the

sweepline in the same way as is used in the example of the dynamically sorted

list. At a point when a swap occurs in the list two segments intersect.

(10)

(a) The sweepline meets the endpoint of a segment.

(b) The sweepline meets an intersec- tion point between segments.

Figure 6: An example of an sweepline algorithm. As the sweepline moves across the configuration the order of its intersection points with the line segments changes. When this happens there is also an intersection point between two segments.

2.4 A Note on robustness.

As with many algorithms in computational geometry, implementations of KDSs often have to address robustness issues due to rounding errors in floating point operators and so called degenerate input. The implementation we present in section 5 also has measures to deal with these problems.

Early versions of the implementation of both sweep-tiling (see 4) and sweep- and-prune (see 3) would sometimes not correctly handle events that occur nearly simultaneously. When a disk would be involved in two collisions at once, often one collision would be missed. Also when a bound would cross two other bounds simultaneously one crossing would go undetected. This last type of error would often propagate and interfere with collision detection later.

A final resort in dealing with these issues is to displace each point a small distance  in an random direction. The implementation we present will avoid such measures. We will be describing these issues in more detail in section 5.

3 Previous Work

3.1 Spartial Subdivision

There are many different methods for broad phase collision detection. One of the first solutions presented is spatial subdivision [15]. The idea behind this method is that objects that are in different areas cannot collide. The simulated area is divided into axes aligned boxes in a grid and the algorithm keeps track of which each object is in. This method works well when the objects are distributed evenly among the space which is simulated. However this is not always the case.

If all object happen to be in the same area this method does not exclude any pairs. There is a trade off in the number of areas the programmer uses in this method. Too many areas and the overhead of objects moving into other areas becomes very large. Too few, and the method becomes ineffective.

A possible solution for this problem is to subdivide a box into smaller boxes

when it gets to crowded [18].

(11)

Figure 7: Three circles and their projections on the x-axis

Figure 8: Axis aligned bounding boxes as implemented with two projections

3.2 Sweep-and-Prune

Another way method of broad phase collision detection is sweep-and-prune.

Sweep-and-prune was first described as a static collision detection algorithm [19].

First we take a look at sweep-and-prune in one dimension.

Sweep-and-prune is based on the separating axis theorem [1, 14]. This theo- rem states that if one projects a shape or object onto a line and the projections do not overlap the objects themselves do not overlap. We chose the x-axis as such a line for this example. To determine which projections overlap we gather the lowest and highest x-coordinates of all object. We will call these minimum and maximum coordinates lower and upper bounds. We sort the bounds from lowest to highest value. Then we go through the list from low to high. (See fig. 7) When we meet the lower coordinate of a projection we add the object to a list of intersecting projections and when we meet the highest coordinate we remove it from the list again. Also when we encounter a lowest bound of a projection we report the the projection as being intersecting with all the other projections in the list of intersecting projections.

This method can be applied to multiple axes. This effectively implements Axis-aligned boundig boxes or AABBs. See fig. 8.

This method was later improved upon by making use of temporal coher- ence [5, 6]. Between frames the order of the coordinates stays almost the same if the sample rate is not to small. This can be utilized by using different sorting schemes that take expected O(n) time to sort nearly sorted lists, like inser- tion sort [6, 11]. These sorting methods may have a worst case performance of O(n 2 ) [9] but when the order of the bounds changes too drastically it is likely that the sample rate is too low.

It is not required to use the the Cartesian axis as a projection line [8]. Also

we are not limited to perpendicular projection lines or a number of lines equal

to the number of dimensions of the simulated space. We can also chose a set

of many projection lines. For each object we chose a subset of these projection

lines that are roughly perpendicular to the motion of the object. We only need

(12)

(a) No overlap between projections

(b) The moment of a change in bound order of the bounds in the list

(c) Overlap between two projections

Figure 9: A Swap event that changes the order of the bounds in the dynamically sorted list.

one line on which the projections are distinct to determine that two objects are not colliding. Therefore it is not necessary for the (sub)sets of lines of an object to be the same as long as there is an intersection with one projection line with separate projections.

When such a separating line stops to be a separating line due to the pro- jections meeting we add a new separating projection line to the subsets of both objects. If no such line is in the set of projection lines the objects are paired.

Because we chose projection-lines roughly perpendicular to the direction of the motion of the object the projections on these lines will only move relatively slowly. Because of this there are less instances of edges of projections crossing each other.

Sweep-and-prune can also be made into a completely dynamic KDS [7, 13].

To maintain the sorted list we create a certificate for each two subsequent coordi- nates in the list stating that the value of the bound in the list that comes before is indeed lower than the one that comes after. When objects have motion-plans that are low-polynomial their bounds have low-polynomial flight plans as well.

Using these one-dimensional flight plans we can calculate exactly if and when these certificates are going to fail, that is to say, when the bounds cross.

When this happens the steps to restore the proof are as follows: First of all, places of the two bounds involved in the event are swapped. Then we need to make new certificates that guard the involved bounds with their new neighbours in the list. Finally we need to determine if overlapping state of two intervals has changed and if so, report it. This state changes when the bounds that crossed where a minimum and a maximum. When a higher bound overtakes a lower bound the projections become overlapping, when a lower bound overtakes a higher bound the two projections stop being overlapping, see fig. 9. When two lower bounds or two higher bounds cross their overlap status of their respective projections does not change.

We can measure performance of dynamic sweep-and-prune using the criteria mentioned in subsection 2.1 as the number of pairs it generates. First we take a look at sweep-and-prune in one dimension and then we look at more dimensions.

In one dimension dynamic sweep-and-prune is responsive; a swap event takes

O(log(n)) time to process. The switch itself takes constant time, but the op-

erations on the queue takes O(log(n)) for both the fetching of the event itself

(13)

Figure 10: In certain cases one dimensional dynamic sweep-and-prune does not exclude any pairs. This relies on a very particular configuration and can therefore be considered rare.

Figure 11: In specific cases axes aligned bounding boxes do not exclude any pairs. These cases can be considered rare.

from the queue and the insertion of any new swap events resulting from the new neighbours of the bounds that swap.

One dimensional sweep-and-prune is compact. The number of bounds in the list is proportional to the number of objects, and the number of certificates is proportional to the number of bounds.

Dynamic sweep-and-prune is local. Each object is involved in at most four different swap events at any one time, two for each bound.

When using only one dimensional sweep-and-prune we cast a pretty wide net; it will produce relatively many pairs. It is possible all pairs are reported.

(see fig. 10) This also means that the ratio of events to actual collisions is likely to be large.

When considering dynamic sweep-and-prune in more dimensions these mea- sures stay the same. The number of certificates doubles or triples, depending on the number of dimensions in which it is applied, but the measurements are in the same order of magnitude.

The reason we would like to apply sweep-and-prune in more dimensions is that we hope we can exclude more pairs. Though it is likely that this is the case, there is still no guarantee any pair is excluded. (see fig. 11) These cases are unlikely to arise on their own.

For some shapes there is a better worst case than depicted in fig. 11, like for

discs or spheres. Using geometric proofs it is often possible to prove the worst

case performance is better [2, 3]. Geometric proof will not be the main focus of

this thesis however.

(14)

3.3 Deformable free-space tiling

A technique used in narrow phase collision detection is deformable free-space tiling [4, 12]. In deformable tiling the space between shapes is divided into smaller, easier to define areas or tiles like triangles or pseudo-triangles. With this method there is less of a need for two phases of collision detection because it naturally generates less event for far away objects. As far as we know there is not yet a deformable free-space tiling in 3D.

4 Description of sweep-tiling /main contribu- tion

In this section a new algorithm is presented. It is a method for broad phase col- lision detection in two dimension on convex shapes. The crux of this algorithm is that we make and maintain a tiling. This tiling is constructed as follows: For each object we take the leftmost and the rightmost point. From these points we draw a line upwards and downwards until we meet another object or the boundary of our simulated space. We call these lines bounds. As we will see they are somewhat similar to the bounds in sweep-and-prune as described in section 3. These lines divide the simulates space up into tiles, (See Figure 12).

Both sweep-tiling and sweep-and-prune can be seen as a kinetization or a kinetic form of different sweep-line algorithm. The algorithm that sweep-and- prune uses sweeps left to right and marks all objects that the sweep-line crosses at the same time as neighbours. Sweep-tiling is a kinetization that is almost the same sweep-line, only it only marks two objects as neighbours when the line crosses them both and there is no other object in between.

Though we will speak of tiles in this section we do not have an actual explicit tile object in our implementation. We use bound-objects and infer what the tiles are from them. In these bound objects we keep track of the bodies that mark the end of the bound and the other bounds that lay on the other side of a tile.

All these properties will change over the course of a simulation.

We will make a distinction between the inside of a bound and the outside of a bound. We refer to the side of a bound that is above or below the object it is bounding as the inside and the side that is not as the outside. Each bound has one tile on the outside and who tiles on the inside; one above the bounded shape and one below. Each bound has three neighbour bounds: one outer neighbour, one upper neighbour and one lower neighbour.

Sweep-tiling does not have a dynamically sorted list of bounds like sweep- and-prune does. Instead it maintains a match of of nodes that represent the different bounds with double links between the bounds that are both adjacent to to the same tile. As can be seen from fig. 12 each bound is adjacent to three tiles, one to the side of the disc it it bounding, one above the disc it is bounding, one below and one to the side. This means every bound has a link to three other bounds.

The bounds in sweep tiling are similar to the type or bounds we use in the

method of sweep-and-prune as we described it in chapter 3. The main difference

is that in our method the bounds are not points on a horizontal line but also

carry information on their vertical location and size. If we were to extend all

the bounds we described in sweep tiling to the edge of the simulated space the

(15)

Figure 12: An example of a sweep-tiling of a configurations of discs. Each area that is enclosed by left and right by a vertical line (bound) and by either a disc or the edges of the thick rectangle are considered tiles.

bounds would act the same as the lines along we project in sweep-and-prune. If we were to draw a horizontal line on which we would project our new type of bound they would end up in the same places as the bounds used in sweep-and- prune.

The set of candidate pairs that sweep tiling produces is a subset of the pairs that sweep-and-prune produces. All pairs that sweepliling detects are detected by sweep-and-prune since the pairs that sweep-tiling detects are always connected by a vertical line. However sweep-tiling only produces pairs where such a line does not cross another shape.

4.1 Pseudocode

Algorithm 1: Main Loop

1 Function Main Loop

2 while the simulation is running do

3 get the next event form the queue ;

4 restore the KDS dependant on the type of event ;

5 end

Algorithm 2: Handle collision

Data: An collision-event object with a time, and two discs that are involved in the collision and all other discs.

1 Function Handle Collision (event)

2 change the flight plans of the discs involved according with an elastic collision;

3 remove all events collision events that the discs where involved in ;

4 compute new collision events for the discs involved with the new flight plan;

5 enter these events into the queue;

(16)

Algorithm 3: Handle collision Data:

1 Function Handle tile event (event)

2 determine what case sort of tile event remove all events collision events that the discs where involved in ;

3 compute new collision events for the discs involved with the new flight plan;

4 enter these events into the queue;

4.2 Initialization

To obtain the initial positions and endpoints of the dividing lines we use a sweep-line algorithm. We sort the leftmost and rightmost points according to x-coordinate. These points serve as events in our sweep-line algorithm.

The state of the sweep-line algorithm consists of left bounds of the objects on the line and the right-bounds that are visible from the sweep-line. By visible we mean that there are no other bounds between the sweep-line and the right-bound on a horizontal line. These bounds are stored in a list sorted by x-coordinate of the corresponding leftmost or rightmost point.

When the sweep-line meets a new event, that is to say a new leftmost or rightmost point, the algorithm creates a new bound and adds it to the state of the sweep-line. Further more any right bounds that become obscured are removed from the state. There are a few different cases to consider depending on whether the point is a leftmost point or a rightmost point.

If it is a rightmost point this means that the sweep-line at that point will no longer intersect with the shape the point belongs to going forward. This means that the left bound of the corresponding object is to be removed from the state of the sweep-line.

4.3 Maintaining the Sweep-tiling in Motion

When we have completed the Initialisation of the tiling we need to maintain it as the discs are moving. We do this using a Kinetic Data Structure.

There are two assertions associated with each tile, one concerning the pos- sible collision of the shapes at the bottom or the top of the tile and one that states that the width of the tile is positive, see also fig. 13. Predicting when the width of a tile is going to become zero is relatively simple since the movement of the bounds is the same as the movement of the objects that they bound and only the position and speed in the x-axis needs to be considered.

When the width of a tile is no longer positive the arrangement of tiles is changed so that all tiles will have a positive width from that point onwards.

These events have some similarities to swap events in sweep-and-prune. The difference is that instead of a list we have a mesh where we move the bounds around in. This makes for a slightly more complicated process.

When a tile collapses (its width reduced to 0) the bounds that formed that

tile will form a new tile where each bound is on the other side. It could be said

the bounds swap positions. However this event also changes the branching of

the mesh. The bounds involved have to go into one of the branches of the other

(17)

Figure 13: Sweep-tiling uses two assertions per tile.

A

B C

D a

b

(a) both bounds end in the same bodies both above and below

A

B C

D a

b

(b) the moment of a tiling event

A

B C

D a

b

(c) the bound end in dif- ferent bodies both above and below

Figure 14: Three stages in a meeting or passing tiling event. Images can be read left to right and right to left.

bound, or they come out of such a branch, depending on what kind of bound the other bound is. Also we also the top and the bottom ends of the bound change in that they end in other bodies. This corresponds to the bodies on the top and on the body of the new tile.

We can distinguish three different cased of this type of event. Which case is appropriate can be derived from if the bounds involved are left bounds or right bounds.

Meeting: Bodies go from not being separated vertically by a tile (fig. 14a) to

being connected vertically by a new tile (fig. 14c). The tile that separated

the discs vertically disappears as the vertical distance between the two

discs becomes zero. Then the bounds pass each other a new tile is formed

connecting the two discs vertically. The two bodies involved, denoted A

and B in the figure become neighbours. The tile that connected body C

and D disappears. This means they are no longer neighbours.

(18)

During this event the bodies in which the bounds end change. Before the event both bounds have end on the same bodies both below and above.

After the bound of A denoted a ends in B on the bottom and bound b ends in body A on top.

Also the bound a and b change their neighbour bounds. Before the event the bounds a and b have each other as outer neighbour. In figure 14 a becomes the upper neighbour bound of b and b becomes the lower neigh- bour bound of a. In the simulation it will have to be evaluated which off the bodies is higher than the other. The bounds a and b get other outside bounds as well. The outside bound neighbour of a becomes what used to be the upper bound neighbour of b and the outside bound of be becomes what ever the upper neighbour bound of a used to be. Finally the new neighbour bounds of a and b need to register a and b as their new neighbours too. During this event one tile is destroyed and one is created;

the total number of tiles remains constant.

Parting: This event is the reverse of the a meeting event. Two discs change their positions in such a way that before the change one disc was partially under the other disc ( see fig. 14c) where after the change the there is a area separating the two discs vertically(see fig. 14a).

The different bodies are no longer neighbours. One tile that connects the discs vertically disappears. A new tile is formed that separates the two discs vertically. The new tile will reach to up to and down to the objects (discs) above and below at the time of the event. Before the event each body had at one bound that ends in one the other body.

In this type of event these are the bounds that pass each other and these ends change. After the event both bounds end in the same body. To see what the bodies on the ends of each bound is going to be we look at what the The new tile will reach to up to and down to the objects (discs) above and below at the time of the event. Before the event each body had at one bound that ends in one the other body. In this type of event these are the bounds that pass each other and these ends change. After the event both bounds end in the same bodies on both sides. To see what the bodies on the ends of each bound is going to be we look at what the unchanging ends of these bounds are to

Passing: In this case two discs involved stay under one another but one left bound crosses another left bound or a right bound crosses another right bound. A possible swap-event is depicted in fig. 15. During this event bodies B and C stop being neighbours and A and D become neighbours.

The lower end of the bound a is B before the event and D after. the top

end of bound b is C before the event and A after. The outside neighbour

bound of b becomes the outside neighbour of a. the outside neighbour of

b becomes a. The upper neighbour of b becomes the old lower neighbour

of a.

(19)

A

B C

D a

b

(a) the bound end in dif- ferent bodies both above and below

A

B C

D a

b

(b) the moment of a tiling event

A

B C

D a

b

(c) both bounds end in the same bodies both above and below

Figure 15: Three stages in a passing tiling event. Images can be read left to right and right to left.

4.4 The number of tiles

An important aspect of the sweep-tile algorithm is the number of tiles. The number of tiles remains 3n + 1 where n is the number of simulated objects; thus it is O(n).

As a base to work from we take the example of a simulated space with no objects in it. In this case there are no bounds and the whole space could be considered one tile. when we introduce the first objects and draw the bounds it cuts the tile that was there before in four tiles. We can keep adding new objects in this way to the left of the tiles already there. The bounds of these newly added objects all extend to the edge of the simulated space since all other objects are to the right. Each object adds three new tiles to the total so the total number of tiles is 3n + 1.

Of course this does not cover all possible configurations, but we can move the objects around after we added them to the simulated space. When we move the object the bounds of the object may meet other objects in a similar fashion as would happen in a our simulation as a bound even (see subsection 4.3). Note that during these events always one tile is created and one tile is destroyed.

This means that the total number of tiles stays the same.

4.5 Theoretical performance

In this section we will look at the performance in the terms laid out in section 2.1.

For benchmarks please see 5.3. Per tile there are two assertions: one stating that the left bound of the tile is indeed left of the right bound and one stating that the objects that on the top and the bottom do not collide.

Since the number of tiles if proportional to the number of simulated objects the number of cached assertions is also O(n). In other words the algorithm is O(n) compact. Also the number of pairs is proportional to the number of tiles, so it is also O(n).

In some cases it is possible that one simulated object is paired with each other simulated objects, such as in fig. 16. This means that the locality is O(n).

However these cases can be considered rare. When we assume two objects are

(20)

Figure 16: In a tiling it is possible that an single object (gray) is paired up with each other object in the scene. In the scent depicted here sweep-and-prune would result in O(n 2 ) pairs.

as likely to be paired with each other as any other two objects each object is in 6 pairs on average, so O(1). However in some cases this assumption may be too optimistic, for instance when one simulated object is much larger than the other objects.

The maximum size of the queue is equal to the number of cached assertions so it is also O(n). This means that the operations on the queue like getting the next event in the queue and adding and removing events take O[log(n)] time.

This is important when calculating the efficiency. In the case of a collision of an object that is paired with n − 1 other objects it is possible that there are n − 1 collision events to be removed from the queue or n − 1 new collision events to be added. In this case handling an event takes O[n · log(n)] time. Again however this case can be considered rare. When we assume that each two objects is as likely to be paired as each other two objects the average time to handle a collision event becomes O[log(n)]. Note that this assumption may not hold true in all cases; It stands to reason that when there are big differences bigger bodies will have more collisions and also more neighbours.

another way in which we hope sweep-tiling is an improvement over sweep- and-prune is in the total number of events. We will show that in the same simulation, that is to say the same objects with the same speed over the du- ration, the sweep-tiling will have at most the same number of bound events as sweep-and-prune has. In sufficiently dense arrangements it will most likely be significantly less.

sweep-tiling and sweep-and-prune have the same number of bounds and in the same places - to the left and to the right of each body. The main difference is that the bounds in sweep-tiling also have a limited size vertically.

Both sweep-and-prune and sweep tiling have to contend with a rare cases

where they become ineffectual. We will show that the cases that form a problem

for sweep tiling are a subset of the cases that form a problem for sweep-and-

(21)

prune.

5 Description of Implementation

5.1 Implementation choices

In this section we will focus on the more practical aspects of the implementation we made. The implementation was divided among different classes and packages of classes. We made three implementations: one of the naive implementation without any pruning, one with sweep-and-prune in one dimension, one in two dimenstions and one of sweep tiling.

All all the implementations are in Python. At the time I hoped Python would make it easier to implement the algorithms. Python certainly helped with keeping functions small and clear although it also had downsides. I was initially not that familiar with Python. One aspect with which we sometimes struggled was the lack of type checking in Python. We will reflect more on this choice in section 6: Discussion.

The most important aspects of all three of these implementations are of course the events and the queue. These two classes are very dependent on each other. The Event class is extended into many different types of event, but the interaction with the queue is all implemented between the base Event class and the EventQueue class. The queue is implemented as a heap queue where the heap is stored in a array. In order to make it possible to remove events from the middle of the queue each event stores its own index in the array.

One of the extensions of Event is the CollisionEvent. This is the type of events that signals the collision between two discs. When two discs collide the distance between their centers is equal to the sum of the radii of the discs. The time of a collision is determined by making an equation for the square of the distance between the centers of two discs as a function of time and compare that to the square of the sum of the radii of the discs. We use the squares instead of the actual distances because we use Pythagoras to determine the distance and this way eliminates a square root.

This results in a quadratic equation. First we check if the extreme value

−b/2a is in the past; if it is the discs are moving away from each other and there can be no solution, (see subsection 5.2). If the moment of the extreme value is in the future we proceed to solve the quadratic equation using the quadratic formula. The discriminant determines if the two discs are on a collision course at all. If they are the formula will yield two results.

Of the two solutions we always take the one with the smallest value for t, because this is the time that is associated with the time the discs make contact, as opposed to the time they would lose contact becoming separated if the discs would continue on there flightpath until this point in time, which, if the collision detection does what it is intended to do never happens.

For demonstration peruses we make it so that the discs stay within a rect- angle area. We do this by making them bounce off the borders of this rectangle.

To make this type of collision possible there is a second type of collision that gets its own type of event: the WallCollisionEvent.

WallCollisionEvents are very similar to regular collision events. The main

difference is that the walls remain motionless during the collision and the way

(22)

Figure 17: A domain model for Disc, TileBound and Face, where each domain

box is depicted on top of the geometry they represent.

(23)

Figure 18: Class diagram for the implementation of the naive method of dynamic collision detection.

the time of the collision is calculated. Instead of the distance between the centers of two discs we calculate the distance of the center of the disc to the wall minus the radius of the disc as a function of time. When this function goes from positive to negative an wall collision occurs.

For the implementation of sweep-and-prune I introduced IntervalEvents that restore the order of the list and store the two discs as neighbours.

Sweep-tiling does not keep a list of all balls that are its neighbour. Instead it uses the mesh of bounds to look for its neighbours when a change of flight plan occurs. In order to do this traversing all upper and lower neighbours on a collision. We begin at the left bound of the disc and look at its upper-insight face. From that we travel through all nodes of bounds that end in the colliding disc on the lower end and delete, add or replace the events that it may have with the bodies on the upper end. The same process is repeated for the lower side of the disc.

The reason this works is that the sweep-tiling-style bounds store the in-

(24)

Figure 19: Class diagram of the implementiation of sweep-and-prune.

(25)

Figure 20: Class diagram of the sweep-tiling method.

(26)

Figure 21: The equations that are used to calculate the time of a collision may yield the results that are in the past. These are the times of collisions that would have taken place if the flight plans would have been accurate at the calculated time (dotted lines). They are not however, and these results are to be ignored.

formation on in what body they end. A similar solution would not work in sweep-and-prune.

One could traverse all bounds between the left bound and the right bound of an body to determine the neighbours, but this method would fail in certain cases.

When one object is larger than the other and the bounds of the large object surround the small object traversing the other bounds between the bounds of the large object would reveal the smaller object as a neighbour, but traversing the bounds between the bounds of the smaller object would not reveal the bigger object.

There may be ways around this problem. For objects of the same size one could argue that the above example is impossible. If there are different sizes it is possible to continue traversing the bounds until the distance of the biggest object if covered. A Downside of this solution is that it potentially adds a performance burden on the bound-event which is usually the most occurring event.

5.2 Robustness

Algorithms involving computational geometry are notoriously vulnerable to edge cases and so called degenerate input. In some cases adding an offset of a small value  helps, other times it creates drastically different outcomes [10]. These issues also affected the initial implementation of the algorithm described here.

In this section we will discuss the issues we encountered and how we dealt with them.

The root of many of these problems are the rounding errors in the floating point calculations. When values that in reality are very close together are compared the results are not always consistent. Though the differences may be small the consequences of such errors can be large.

The flight plans of objects are not attached to a particular time. This is what makes them useful in a KDS – if they would be dependent on time they would need to be recalculated constantly. However this also means that when we use the flightpath to calculate the time an assertion breaks that calculation cannot take into account at what times those flightpath accurately describe the current state. The formulas that calculate the time of an event, as it where, assume that the flightpath are accurate for all of time. This sometimes leads to anomalous event times being calculated (see fig. 21).

Also note that the calculated event time can tell you the time the truthfulness

of an assertion changes but not in which direction. Consider a assertion that

states a(t) > b(t) where a and b can be any quantity (let us assume that both

(27)

a and b are linear). We can try to solve a(t) = b(t) for t. The result may mark the time where a becomes bigger than b but also the time at which a becomes smaller that b. This type of ambiguity may lead to another type of anomalous event-time results.

When designing a KDS it seems obvious to assume that all events that are calculated to occur in the past can be disregarded. The reasoning is that the simulation is accurate up to that point in time and any new events that are calculated to occur before that point are anomalies. If there are no rounding errors this is a perfectly accurate assumption, but with those errors this rea- soning becomes problematic. When the times between events are very close a rounding error may result in a real event being ignored of a anomalous event being scheduled.

In an earlier version of our program we followed this assumption and it lead to a few issues. When events occur in very quick succession the time between them may fall within the margin of error. This means that an anomalous event could be treated as an real event or visa versa.

Suppose a bound-event is missed in this way. When this type of error oc- cures it introduces a false assertion to the cache immediately. There now is an assertion stating that bound a is left of bound b where in reality it is the other way around. Needless to say this may interfere with detecting collisions.

Not only does the the technique help introduce false assertions in this way, it also helps this error to propagate (see fig. 22). Say a is left to b in the list, but in reality b is left to a. When a bound c is going to cross bound b from the left the algorithm is going to check if it is going to cross bound a in the future.

In reality bound c crossed bound a already. When we feed the numbers into the equations to determine a time when b and c would cross it will likely result in a value for time in the past and thus get disregarded.

This problem cannot be remedied by subtracting an  to the time value of the generated event. Although it prevents a crossing of bounds to be falsely ignored it also increases the possibility of a false positive. It could for instance re-introduce an event into the stack of an event that has already occurred which in turn may introduce yet other anomalous events into the queue. In some cased this leads to an infinite loop of events of crossings that trigger each other with approximately the same value for t.

We still need to find a way to exclude these events that would take place in the past without simply relying on comparing the time of the current event to the generated event. Instead of comparing the times on the events we compare the speed of the right bound to the speed of the left bound. To see what is the left bound and what is the right bound we do not compare their calculated positions but refer to what their relative position is according to our cached assertions. In sweep-and-prune this means the relative positions of the bounds in the list. For sweep-tiling this means the relative position according to the bound objects of the tile and their Face attributes.

We put the event in the queue if the speed with which they move towards each other is bigger than a chosen value . Here adding an epsilon does not come with the risk of an infinite loop the way it did with the test we described above.

There is still a chance the test will give a false result due to a rounding error

when comparing the speed. However the the difference between just passing

the test and just failing the test is not the same as the difference between a

(28)

(a) bound c approaches bound a but does not register bound a because b is still in between in the list

(b) bound c has past bound a, but has not switched with bound a in the list because b is in between.

(c) bound c has passed bound b in the list and now eveluates the time of crossing with bound a now that the two bounds are next to each other in the list. However the moment c has passed a is in the past and thus the event is ignored if that is a criteria to ignore events. – If instead of the time of crossing the algorithm looks at the relative position in the list in combination with the difference in speed a crossing event between a and c will be scheduled.

Figure 22: When the time of an event is used to determine if the event is to be

scheduled this can lead to error propagation.

(29)

discarded event and a immediate event like with our earlier solution. Rather an event that barely makes or fails the test - the distance between the bounds is changing only very slowly - is likely only to occur in the far future, and until that time the assertions are still correct. It is also likely that in the mean time the event is interrupted before its time, for instance because one of the bounds changes speed due to a collision. When this happens any old events in the queue regarding the crossing is discarded and the possibility for an bound event is reevaluated.

Also this solution makes it harder for errors to propagate. When looking at the situation depicted in fig. 22 we can see that in subfig. 22c a crossing event between a and c is scheduled because c is moving to the left relative to a and a is directly left to c in the list. The time of this event could be before the current time meaning that it is most likely a time before all other events in the queue which means that it will be the next event to be handled. This is exactly what we want.

This also means that there is an error with two bounds that are very close together this error can do relatively little harm. When this error occurs between two bounds that are very close they are likely to remain very close since the difference in their speed is very small.

A similar approach was taken to the collision events. Instead of comparing the current time to the time of collision I compare the current time to the time where the distance between the centers is smallest to see if the solution is anomalous. This has the additional advantage that this time is easier to calculate and can itself be used to calculate the time of the collision.

5.3 Bechmarks

We aim to devise benchmarks that illustrate the differences between sweep-and- prune and sweep-tiling. Our hypothesis is that sweep-tiling is better suited for situations that are dense - where there is relatively little space between the objects. To test this hypothesis we set up different benchmarks with different densities. For the purposes of this benchmark we will define the density of scene as the ratio of occupied area to the total area of the scene. To start each benchmark we overlay the simulated area with a grid of squares. In each square we put one disc where we solve the size of the disc to get an desired density.

The simulated area itself is a square with sides normalized to one.

We are also interested in how various solutions scale with larger numbers of objects. To this end we will will do benchmarks with different dimensions to the grid. We will note much time each solution will take, but since this is dependent on the implementation and the hardware we will also gather data that is independent of such things such as the total number of events and the the total number of collision events. This will also go towards giving an estimate of the efficiency of the algorithms as explained in section 2.1.

The different numbers of discs we use in the simulation are chosen so that each following number is four times as large as the previous number (25, 100, 400). This allows us to plot the results in what could be interpreted as a double logarithmic stale. (see fig. 23)

Because we want to have consistent density during the simulation it would be a problem if the discs would spread across an infinite region of simulated area.

To prevent this we set up walls around the simulated area. This is different from

(30)

the way that these kinds of algorithms are usually done where the simulation naturally moves to a state in which there are no further events. This does not happen when in our simulation due to the bounds we set up around the discs, so we have to use a time limit on our simulation. We do allow events to be entered into the queue that are after the planned end of the simulation. This does mean that the execution times will be longer because even though these events will never be executed they fill up the queue and thus influence the execution time of the queue.

All discs in the area are given a speed of one in a random direction. This way there is a sufficient amount of randomization while maintaining the same kinetic energy between the different benchmarks. A lower kinetic energy would result in a lower number of events and thus a faster execution time. We hope this way will give a better indication of what the performance would be over longer stretches of time where this type of time saving is less of a factor.

5.3.1 Execution time

From the graphs 23a and 23b we can see that for high densities sweep-tiling is the fastest followed by sweep-and-prune. For a density of 0.125 with 25 discs the naive method is faster (23c), probably due to less overhead, but otherwise sweep and prune is faster. When there is a density of 0.01 (fig. 23d). The naive method is faster than the other methods tested. We can also deduce information from the slopes of the lines of these graphs. In each graph the line with the steepest slope is that of the naive method followed by the sweep-and-prune and with sweep-tiling having the least steep line. This suggests that sweep-tiling scales better that the other methods. It is possible that for a density of 0.01 sweep- and-prune and sweeptining would be faster for an sufficiently large number of discs.

The difference in slope and height between sweep-tile and sweep-and-prune becomes smaller as the density becomes smaller. With a density of 0.01 the difference in slope becomes almost negligible. There is still a difference in height that indicates sweep-tiling is a constant factor faster. However a constant factor in execution time is also influenced by specific implementation and hardware.

5.3.2 Efficiency

When we want to make an estimate of the efficient and the responsiveness of the different algorithms we need to look at the different numbers of events. Based on the numbers of events alone the naive method seems to be even better, we can see that actually in most cases the naive method takes up most time.

Obviously the naive method is taking more time per event. This is probably due to the length of the queue during the execution of this method and more queue operations per event. Even though the sweep-and-prune and sweep tiling spend more time changing references in order to preserve their own data structure per event, sweep-tiling more so that sweep-and-prune, these results show that these factors are not as important when compared to the factors involving the queue operations. Event though there may be better implementations of this changing of references, this does not affect the number of queue operations or the size of the queue. Note that all implementations use the same queue.

In the implementations of both sweep-tiling and sweep-and-prune we have

(31)

25 100 400

# of discs

1

10 100 1000 10000

e x ecution time (s)

naive s&p tile

(a) execution times with a density of 0.5

25 100 400

number of discs

0.1

1 10 100 1000

e x ecution time (s)

naive s&p tile

(b) execution times with a density of 0.25

25 100 400

number of discs

0.1

1 10 100 1000

e x ecution time (s)

naive s&p tile

(c) execution times with a density of 0.125

25 100 400

number of discs

0.1

1 10 100 1000

e x ecution time (s)

naive s&p tile

(d) execution times with a density of 0.01

Figure 23: execution times of the naive method, sweep-and-prune and sweep-

tiling with different densities and different numbers of discs.

(32)

naive, n = 25s&p, n = 25tile, n = 25naive, n = 100s&p, n = 100tile, n = 100naive, n = 400s&p, n = 400tile, n = 400 0.00%

20.00%

40.00%

60.00%

80.00%

100.00%

bound events wall events collision events

(a) events as percentage of total with density of 0.5

naive, n = 25s&p, n = 25tile, n = 25naive, n = 100s&p, n = 100tile, n = 100naive, n = 400s&pn = 400tile, n = 400 0.00%

20.00%

40.00%

60.00%

80.00%

100.00%

bound events wall events collision events

(b) events as percentage of total with density of 0.25

naive, n = 25s&p, n = 25tile, n = 25naive, n = 100s&p, n = 100tile, n = 100naive, n = 400s&pn = 400tile, n = 400 0.00%

20.00%

40.00%

60.00%

80.00%

100.00%

bound events wall events collision events

(c) events as percentage of total with density of 0.125

naive, n = 25s&p, n = 25tile, n = 25naive, n = 100s&p, n = 100tile, n = 100naive, n = 400s&pn = 400tile, n = 400 0.00%

20.00%

40.00%

60.00%

80.00%

100.00%

bound events wall events collision events

(d) events as percentage of total with density of 0.01

Figure 24: percentages of different sorts of events for the naive method, sweep-

and-prune and sweep-tiling with different densities and different numbers of

discs.

(33)

Figure 25: Sweep-tiling is not suitable for non-convex shapes.

made an optimalization that makes it so that when a bound event occurs be- tween a disc and a border it is treated as a wall bounce event. For the purpose of evaluating the efficiency of the algorithms we count how they are treated rather that how they appear in the queue.

From the graphs in fig. 24 we can see that for sweep-and-prune and sweep- tining the number of bound events outnumbers the other types of events, in a lot of cases many times over. The most difference between the two is with a density of 0.5 and 400 discs. This is wholly expected since it is expected that in these circumstances the algorithm benefits the most from the effect of discs ob- scuring bounds of other balls as explained in section 4. With lower numbers of discs and lower densities the difference becomes smaller. This is consistent with the smaller differences in execution times under the same circumstances. When reading the graphs it is usefull to keep in mind that the numbers of collisions and wall collisions very little between different runs of different algorithms with the same parameters for density and numbers of discs.

I made an implementation of sweep-and-prune in two directions using a two dimensional array to cross reference overlaps in the different directions. It was slower in the benchmarks so I did not include it in the final benchmarks.

6 Discussion

From the results in subsection 5.3 we can see that sweep-tiling compares favor- ably to sweep-and-prune when sweeping in one direction. Also it can be proven that there is an upper limit of O(n) to the total number of active pairs that sweep-tiling produces where the upper limit of sweep-and-prune is O(n 2 ).

The sweep-tile approach benefits from dense scenes when compared to sweep- and-prune. In dense scenes two objects are most likely to be obscured from each other by other objects.

Sweep-tiling had a few disadvantages to sweep-and-prune. Sweep-tiling is

only suitable for convex forms. (see fig. 25) Sweep-tiling is not easily expanded

to three dimensions like sweep-and-prune is. Also sweep-tiling is not suitable

(34)

Figure 26: A type of event where one object passes through another object.

This sort of event has some associated difficulties. In the middle depiction it is ambiguous what object is above in the gray area. Objects in the gray area could possibly collide with both depicted objects. At some point bounds in the gray area will go from ending in one disc to ending in the other, but when exactly this should occur is unclear.

for bounding circles.

This is because sweep-tiling breaks down when objects move through or over each other. It cannot handle objects that go from one being on top to the other being on top. This is no problem as long as the objects are solid and cannot move through each other. However if we try use it with bounding spheres as an intermediate step this is no longer true. We can use AABBs, but only when the bounds are tight and objects can’t move around each other while their AABBs overlap. We will elaborate more on why this is and how we could fix it in section 7.

A similar problem presents itself when trying to extend the process to three dimensions. Unlike sweep-and-prune, we cannot take an two dimensional pro- jection and extend to the third dimension, because the algorithm does not work on the projection because one body can move over the other. We will discuss this matter more in section 7.

We are confident that these adjustments are possible however. Such adjust- ment would need to include a way to handle the transition or move over event we described as causing the problem. This could be done by doing the steps that would occur if the objects would move around each other within one event.

This solution would take expected constant time, but could take up to O(n) in rare circumstances.

Another thing we would need to assess is when exactly this move over event

would occur. It is possible that an object is only partly above or below another

object, see fig.26. We could disambiguate by using AABBs with a separate set

of bounds for the upper and the lower part of the box. We treat the horizontal

lines of the box as separate bodies, and with horizontal lines it is unambiguous

what line is on top. Sadly this would mean that the number of active pairs is

no longer O(n).

Referenties

GERELATEERDE DOCUMENTEN

 Affiliate marketing platforms represent a strategic point in the industry: Affiliate marketing platforms were identified by some sweep participants as a strategic point

JACOBS (DOMINE). vir emigrante sou sulke aanwysings seker onmisbaar wees, maar die skrywer wou tog iets anders gee. Gevoel vir skoonheid het hy ook:, maar

Een voorwaarde voor effectieve invloed is dat er meer inzicht komt in aspecten van ruimtelijke vormgeving die van belang zijn voor de verkeers- veiligheid en dat

bodemval komen. De aangetroffen soorten moe- ten in de lokale vegetatie geleefd hebben en na hun dood op de bodem van het ven zijn terecht- gekomen. Uiteindelijk raakten ze in

Figure 6.7 displays the source image top-left, the destination image top-right and the middle image of the morphing sequence created by the implementation discussed above.. Because

Abstract-A type of dc to 3-phase series-resonant converter (s.r.- converter) for potentially submegawatt industrial applications is pre- sented. The converter

So far we ignored some nasty cases, which make the sweep algorithm more complicated. First of all it is possible that a segment has the north pole as its upper endpoint or the

Matrix-induced autologous chondrocyte implantation versus microfracture in the treatment of cartilage defects of the knee: a 2-year randomised study. Knee Surg Sports