Calculate collsion vectors for two objects
bounce_pair.Rd
Calculate collsion vectors for two objects
Arguments
- v1
Velocity vector of object 1. Two-dimensional numeric vector.
- v2
Velocity vector of object 2. Two-dimensional numeric vector.
- x1
Center of object 1 in the time collision. Two-dimensional numeric vector.
- x2
Center of object 1 in the time collision. Two-dimensional numeric vector.
Examples
# direct collision, speeds swap
bounce_pair(c(0, 1), c(0, -1), c(0, 0), c(0, 1))
#> [[1]]
#> [1] 0 -1
#>
#> [[2]]
#> [1] 0 1
#>
# 45deg contact angle, makes 90deg turns
bounce_pair(c(0, 1), c(0, -1), c(0, 0), c(1, 1))
#> [[1]]
#> [1] -1 0
#>
#> [[2]]
#> [1] 1 0
#>
bounce_pair(c(0, 1), c(0, -1), c(0, 1), c(1, 0))
#> [[1]]
#> [1] 1 0
#>
#> [[2]]
#> [1] -1 0
#>
# distance is not relevant, direct or 45 deg contact
bounce_pair(c(0, 1), c(0, -1), c(0, 0), c(0, 2))
#> [[1]]
#> [1] 0 -1
#>
#> [[2]]
#> [1] 0 1
#>
bounce_pair(c(0, 1), c(0, -1), c(0, 0), c(2, 2))
#> [[1]]
#> [1] -1 0
#>
#> [[2]]
#> [1] 1 0
#>
# Works also for different velocities
bounce_pair(c(0, 1), c(0, -2), c(0, 0), c(0, 1))
#> [[1]]
#> [1] 0 -2
#>
#> [[2]]
#> [1] 0 1
#>
bounce_pair(c(0, 1), c(0, -2), c(0, 0), c(1, 1))
#> [[1]]
#> [1] -1.5 -0.5
#>
#> [[2]]
#> [1] 1.5 -0.5
#>