I am trying to test for a collision from a rectangle to a circle and I need to calculate the closest point on a rectangle to a point any ideas?
Code:
Public Shared Function HasCollisionOccured(ByVal Object1Pos As Vector2, ByVal Object2Pos As Vector2, ByVal Object1Radius As Single, ByVal Object2Size As Size) As Boolean
HasCollisionOccured = False
Dim Gap, distance, difX, DifY As Single
difX = Object1Pos.X - Object2Pos.X
DifY = Object1Pos.Y - Object2Pos.Y
Dim angle As Single = Math.Atan2(Object2Pos.X - Object1Pos.X, Object2Pos.Y - Object1Pos.Y)
MISSING CODE
Dim Object2Radius As Single
Dim x, y As Single
x = Math.Tan(angle) * Object2Size.Height
If x > Object2Size.Width Then
x = Object2Size.Width
y = Math.Tan(angle) * Object2Size.Width
End If
If x < -Object2Size.Width Then
x = -Object2Size.Width
y = Math.Tan(angle) * Object2Size.Width
End If
distance = Math.Sqrt(difX * difX + DifY * DifY)
Gap = distance - (Object1Radius + Object2Radius)
If Gap < 0 Then
Return True
End If
End Function