Collision Checker
There are two collisions checkers currently available in AutomotiveDrivingModels.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
AutomotiveDrivingModels.collision_checker
— Functioncollision_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.
collision_checker(scene::Frame{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
.
Vehicles can be converted to polygon (static matrices containing four vertices).
AutomotiveDrivingModels.polygon
— Functionpolygon(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
Minkowski Sum
Here are the methods available using Minkowski sum.
AutomotiveDrivingModels.is_colliding
— Functionis_colliding(ray::VecSE2{Float64}, poly::ConvexPolygon)
returns true if the ray collides with the polygon
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.
AutomotiveDrivingModels.ConvexPolygon
— TypeConvexPolygon
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
AutomotiveDrivingModels.CPAMemory
— TypeCPAMemory
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 AvehB::ConvexPolygon
bounding box for vehicle Bmink::ConvexPolygon
minkowski bounding box
AutomotiveDrivingModels.CollisionCheckResult
— TypeCollisionCheckResult
A type to store the result of a collision checker
Fields
is_colliding::Bool
A::Int64
# index of 1st vehicleB::Int64
# index of 2nd vehicle
AutomotiveDrivingModels.to_oriented_bounding_box!
— Functionto_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
AutomotiveDrivingModels.get_oriented_bounding_box
— Functionget_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
AutomotiveDrivingModels.is_potentially_colliding
— Functionis_potentially_colliding(A::Entity{S,D,I}, B::Entity{S,D,I}) where {S,D<:AbstractAgentDefinition,I}
A fast collision check to remove things clearly not colliding
AutomotiveDrivingModels.get_collision_time
— Functionget_collision_time(ray::VecSE2{Float64}, poly::ConvexPolygon, ray_speed::Float64)
returns the collision time between a ray and a polygon given ray_speed
AutomotiveDrivingModels.get_first_collision
— Functionget_first_collision(scene::EntityFrame{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]
get_first_collision(scene::EntityFrame{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
.
get_first_collision(scene::EntityFrame{S,D,I}, mem::CPAMemory=CPAMemory()) where {S,D<:AbstractAgentDefinition,I}
Loops through the scene and finds the first collision between any two vehicles
AutomotiveDrivingModels.is_collision_free
— Functionis_collision_free(scene::EntityFrame{S,D,I}, mem::CPAMemory=CPAMemory()) where {S,D<:AbstractAgentDefinition,I}
is_collision_free(scene::EntityFrame{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]
AutomotiveDrivingModels.Vec.get_distance
— FunctionVec.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.
The distance between the line segment and the point P
The distance between the line and the point P
The distance between the line segment and the point P
Returns the absolute distance between the plane and a point
AutomotiveDrivingModels.get_edge
— Functionget_edge(pts::Vector{VecE2{Float64}}, i::Int, npts::Int=length(pts))
returns the ith edge in pts