Class CollisionChecker
Helper methods for detecting collisions in joint movements.
Collision checks work by tracking the movements of all edges in the system. Edges are created by all bonds and expanded, expanding and contracting particles in the system, as well as the boundaries of objects. If any two edges that do not coincide in one point at the start or the end of the movement intersect during the movement, a collision occurs.
Inheritance
Namespace: AS2.Sim
Assembly: .dll
Syntax
public static class CollisionChecker
Fields
| Edit this page View SourcedebugDisplayTime
The number of seconds for which the collision visualization should be displayed.
Declaration
public static float debugDisplayTime
Field Value
Type | Description |
---|---|
float |
debugLines
The debug lines drawn for the last detected collision.
Declaration
private static List<CollisionChecker.DebugLine> debugLines
Field Value
Type | Description |
---|---|
List<CollisionChecker.DebugLine> |
Methods
| Edit this page View SourceComputeOrientationTwoSegments(Vector2Int, Vector2Int, Vector2Int)
Calculates the orientation of the triangle formed by the three given points.
The orientation can be counter-clockwise, clockwise or collinear.
Declaration
public static int ComputeOrientationTwoSegments(Vector2Int p1, Vector2Int p2, Vector2Int p3)
Parameters
Type | Name | Description |
---|---|---|
Vector2Int | p1 | The first point. |
Vector2Int | p2 | The second point. |
Vector2Int | p3 | The third point. |
Returns
Type | Description |
---|---|
int |
|
DrawDebugLine(DebugLine, float)
Helper for drawing debug lines.
Declaration
private static void DrawDebugLine(CollisionChecker.DebugLine line, float time = -1)
Parameters
Type | Name | Description |
---|---|---|
CollisionChecker.DebugLine | line | The line to be drawn. |
float | time | The time for which the line should be displayed. Negative values lead to debugDisplayTime being used. |
DrawDebugLine(Vector2Int, Vector2Int, Color, bool, float)
Helper for drawing debug lines.
Declaration
private static void DrawDebugLine(Vector2Int p, Vector2Int q, Color color, bool arrow = false, float time = -1)
Parameters
Type | Name | Description |
---|---|---|
Vector2Int | p | The start point of the line. |
Vector2Int | q | The end point of the line. |
Color | color | The color of the line. |
bool | arrow | Determines whether the line should have an arrow. |
float | time | The time for which the line should be displayed. Negative values lead to debugDisplayTime being used. |
DrawDebugLines(DebugLine[], float)
Draws the given debug lines onto the screen.
Note that this only works in the Unity Editor and the "Gizmos" toggle in the Game View must be activated for the lines to be visible.
Declaration
public static void DrawDebugLines(CollisionChecker.DebugLine[] lines, float time = -1)
Parameters
Type | Name | Description |
---|---|---|
DebugLine[] | lines | The lines to be drawn. Should be the return value of GetDebugLines(). |
float | time | The time in seconds for which the lines should be displayed. A negative value will lead to debugDisplayTime being used. |
EdgesCollide(EdgeMovement, EdgeMovement)
Checks if the two given edge movements collide. This is the most general of the collision check methods. It selects the most appropriate helper procedure to apply to the two edges.
Declaration
public static bool EdgesCollide(EdgeMovement em1, EdgeMovement em2)
Parameters
Type | Name | Description |
---|---|---|
EdgeMovement | em1 | The first edge movement. |
EdgeMovement | em2 | The second edge movement. |
Returns
Type | Description |
---|---|
bool |
|
EdgesCollideBothNonStatic(EdgeMovement, EdgeMovement)
Checks if the two given edges collide, where both edges can be contraction or expansion movements.
Declaration
public static bool EdgesCollideBothNonStatic(EdgeMovement em1, EdgeMovement em2)
Parameters
Type | Name | Description |
---|---|---|
EdgeMovement | em1 | The first edge movement. |
EdgeMovement | em2 | The second edge movement. |
Returns
Type | Description |
---|---|
bool |
|
EdgesCollideOneStatic(EdgeMovement, EdgeMovement)
Checks if the two given edges collide, given that the first edge is not a contraction or expansion.
Declaration
public static bool EdgesCollideOneStatic(EdgeMovement emStatic, EdgeMovement emOther)
Parameters
Type | Name | Description |
---|---|---|
EdgeMovement | emStatic | The edge movement that is not a contraction or expansion. |
EdgeMovement | emOther | The other edge movement, which might be a contraction or expansion. |
Returns
Type | Description |
---|---|
bool |
|
GenerateDebugLines(EdgeMovement, bool)
Helper that generates lines and arrows showing the absolute trajectory of an EdgeMovement.
The generated movements are added to debugLines.
Declaration
private static void GenerateDebugLines(EdgeMovement em, bool pov)
Parameters
Type | Name | Description |
---|---|---|
EdgeMovement | em | The movement to draw. |
bool | pov |
GetDebugLines()
Returns the list of debug lines generated for the last detected collision. These lines can be used to display where the collision was detected.
Declaration
public static CollisionChecker.DebugLine[] GetDebugLines()
Returns
Type | Description |
---|---|
DebugLine[] | An array containing information for drawing lines that show where the last collision was detected. |
HaveSharedNode(EdgeMovement, EdgeMovement)
Checks whether the two given edge movements share an end point at the start or the end of the movement.
Declaration
public static bool HaveSharedNode(EdgeMovement em1, EdgeMovement em2)
Parameters
Type | Name | Description |
---|---|---|
EdgeMovement | em1 | The first edge movement. |
EdgeMovement | em2 | The second edge movement. |
Returns
Type | Description |
---|---|
bool |
|
LineSegmentsIntersect(Vector2Int, Vector2Int, Vector2Int, Vector2Int)
Checks if the two given two-dimensional line segments intersect.
Uses the algorithm described in https://www.dcs.gla.ac.uk/~pat/52233/slides/Geometry1x1.pdf.
Declaration
public static bool LineSegmentsIntersect(Vector2Int p1, Vector2Int q1, Vector2Int p2, Vector2Int q2)
Parameters
Type | Name | Description |
---|---|---|
Vector2Int | p1 | The start point of the first segment. |
Vector2Int | q1 | The end point of the first segment. |
Vector2Int | p2 | The start point of the second segment. |
Vector2Int | q2 | The end point of the second segment. |
Returns
Type | Description |
---|---|
bool |
|
SegmentsIntersect1D(float, float, float, float)
Checks if the two given one-dimensional line segments intersect.
Declaration
public static bool SegmentsIntersect1D(float p1, float q1, float p2, float q2)
Parameters
Type | Name | Description |
---|---|---|
float | p1 | The start of the first segment. |
float | q1 | The end of the first segment. |
float | p2 | The start of the second segment. |
float | q2 | The end of the second segment. |
Returns
Type | Description |
---|---|
bool |
|