Collision Checker

There are two collisions checkers currently available in AutomotiveSimulator.jl. The first collision checker is accessible through the function is_colliding and relies on Minkowski sum. The second one is accessible through collision_checker and uses the parallel axis theorem. The latter is a bit faster. A benchmark script is available in test/collision_checkers_benchmark.jl and relies on static arrays.

Parallel Axis Theorem

This collision checker relies on the parallel axis theorem. It checks that two convex polygon overlap

AutomotiveSimulator.collision_checkerFunction
collision_checker(veh_a::Entity, veh_b::Entity)
collision_checker(veh_a, veh_b, veh_a_def::AbstractAgentDefinition, veh_b_def::AbstractAgentDefinition)

return True if veh_a and veh_b collides. Relies on the parallel axis theorem.

source
collision_checker(scene::Scene{Entity{S,D,I}}, egoid::I) where {S, D<:AbstractAgentDefinition, I}

return true if any entity in the scene collides with the entity of id egoid.

source

Vehicles can be converted to polygon (static matrices containing four vertices).

AutomotiveSimulator.polygonFunction
polygon(pos::VecSE2{Float64}, veh_def::AbstractAgentDefinition)
polygon(x::Float64,y::Float64,theta::Float64, length::Float64, width::Float64)

returns a 4x2 static matrix corresponding to a rectangle around a car centered at pos and of dimensions specified by veh_def

source

Minkowski Sum

Here are the methods available using Minkowski sum.

AutomotiveSimulator.is_collidingFunction
is_colliding(ray::VecSE2{Float64}, poly::ConvexPolygon)

returns true if the ray collides with the polygon

source
is_colliding(A::Entity{S,D,I}, B::Entity{S,D,I}, mem::CPAMemory=CPAMemory()) where {D<:AbstractAgentDefinition,I}

returns true if the vehicles A and B are colliding. It uses Minkowski sums. is_colliding(mem::CPAMemory) returns true if vehA and vehB in mem collides.

source
AutomotiveSimulator.ConvexPolygonType
ConvexPolygon
ConvexPolygon(npts::Int)
ConvexPolygon(pts::Vector{VecE2{Float64}})

Mutable structure to represent a convex polygon. It is used by the Minkowski sum collision checker

Fields

  • pts::Vector{VecE2{Float64}}
  • npts::Int
source
AutomotiveSimulator.CPAMemoryType
CPAMemory

A structure to cache the bounding boxes around vehicle. It is part of the internals of the Minkowski collision checker.

Fields

  • vehA::ConvexPolygon bounding box for vehicle A
  • vehB::ConvexPolygon bounding box for vehicle B
  • mink::ConvexPolygon minkowski bounding box
source
AutomotiveSimulator.to_oriented_bounding_box!Function
to_oriented_bounding_box!(retval::ConvexPolygon, center::VecSE2{Float64}, len::Float64, wid::Float64)
to_oriented_bounding_box!(retval::ConvexPolygon, veh::Entity{S,D,I}, center::VecSE2{Float64} = get_center(veh))

Fills in the vertices of retval according to the rectangle specification: center, length, width

source
AutomotiveSimulator.get_oriented_bounding_boxFunction
get_oriented_bounding_box(center::VecSE2{Float64}, len::Float64, wid::Float64) = to_oriented_bounding_box!(ConvexPolygon(4), center, len, wid)
get_oriented_bounding_box(veh::Entity{S,D,I}, center::VecSE2{Float64} = get_center(veh))  where {S,D<:AbstractAgentDefinition,I}

Returns a ConvexPolygon representing a bounding rectangle of the size specified by center, length, width

source
AutomotiveSimulator.get_first_collisionFunction
get_first_collision(scene::EntityScene{S,D,I}, target_index::Int, mem::CPAMemory=CPAMemory()) where {S,D<:AbstractAgentDefinition,I}

Loops through the scene and finds the first collision between a vehicle and scene[target_index]

source
get_first_collision(scene::EntityScene{S,D,I}, vehicle_indeces::AbstractVector{Int}, mem::CPAMemory=CPAMemory()) where {S,D<:AbstractAgentDefinition,I}

Loops through the scene and finds the first collision between any two vehicles in vehicle_indeces.

source
get_first_collision(scene::EntityScene{S,D,I}, mem::CPAMemory=CPAMemory()) where {S,D<:AbstractAgentDefinition,I}

Loops through the scene and finds the first collision between any two vehicles

source
AutomotiveSimulator.is_collision_freeFunction
is_collision_free(scene::EntityScene{S,D,I}, mem::CPAMemory=CPAMemory()) where {S,D<:AbstractAgentDefinition,I}
is_collision_free(scene::EntityScene{S,D,I}, vehicle_indeces::AbstractVector{Int}, mem::CPAMemory=CPAMemory()) where {S,D<:AbstractAgentDefinition,I}

Check that there is no collisions between any two vehicles in scene

If vehicle_indeces is used, it only checks for vehicles within scene[vehicle_indeces]

source
AutomotiveSimulator.Vec.get_distanceFunction
Vec.get_distance(A::Entity{S,D,I}, B::Entity{S,D,I}, mem::CPAMemory=CPAMemory()) where {D<:AbstractAgentDefinition,I}

returns the euclidean distance between A and B.

source

The distance between the line segment and the point P

source

The distance between the line and the point P

source

The distance between the line segment and the point P

source

Returns the absolute distance between the plane and a point

source