Hello guys! I have two unsolved questions.
A)
How can I test if an axis aligned recteangle and a circle intersect? My approch returns false if the circle is inside the recteangle.
C#-Code.( Generic, so I have to use functions( calculator ) for numeric operations.
#region Intersects( Circle<Type, Calc> circle, Vector2<Type, Calc> recPosition )
/// <summary> Tests if the given circle intersects the rec. </summary>
/// <param name="circle"></param>
/// <param name="recPosition"> Position of the rec. </param>
/// <returns> True if they intersect, else false. </returns>
public bool Intersects( Circle<Type, Calc> circle, Vector2<Type, Calc> recPosition )
{
Type x0 = c.Sub( recPosition.x, circle.Position.x );
x0 = c.Mul( x0, x0 );
Type x1 = c.Add( recPosition.x, c.Sub( Width, circle.Position.x ) );
x1 = c.Mul( x1, x1 );
Type y0 = c.Sub( recPosition.y, circle.Position.y );
y0 = c.Mul( y0, y0 );
Type y1 = c.Add( recPosition.y, c.Sub( Height, circle.Position.y ) );
y1 = c.Mul( y1, y1 );
if( c.IsLess( c.Sqrt( c.Add( x0, y0 ) ), circle.Radius ) )
return true;
if( c.IsLess( c.Sqrt( c.Add( x0, y1 ) ), circle.Radius ) )
return true;
if( c.IsLess( c.Sqrt( c.Add( x1, y0 ) ), circle.Radius ) )
return true;
if( c.IsLess( c.Sqrt( c.Add( x1, y1 ) ), circle.Radius ) )
return true;
return false;
}
#endregion Intersects( Circle<Type, Calc> circle, Vector2<Type, Calc> recPosition )
B) How can I calculate the angle to rotate an object from the identity matrix to the object's orientation? ( 2x2 matrix ) Is this correct:
#region Angle
/// <summary> Returns the angle to the Idendity-Matrix. </summary>
/// <returns></returns>
public Type Angle
{
get
{
return calc.Acos( calc.Div( m00, calc.Sqrt(
calc.Add( calc.Mul( m00, m00 ), calc.Mul( m01, m01 ) ))));
}
}
#endregion Angle
Thank you very much! :)
[Edited by - Riddle on January 19, 2005 1:00:40 PM]