Click here to Skip to main content
15,920,053 members
Home / Discussions / C#
   

C#

 
GeneralRe: How to stop downloading progress in WebClient? Pin
amx_tiger30-Apr-12 6:09
amx_tiger30-Apr-12 6:09 
QuestionRe: How to stop downloading progress in WebClient? Pin
Eddy Vluggen30-Apr-12 6:16
professionalEddy Vluggen30-Apr-12 6:16 
AnswerRe: How to stop downloading progress in WebClient? Pin
amx_tiger30-Apr-12 6:35
amx_tiger30-Apr-12 6:35 
GeneralRe: How to stop downloading progress in WebClient? Pin
Eddy Vluggen30-Apr-12 7:02
professionalEddy Vluggen30-Apr-12 7:02 
GeneralRe: How to stop downloading progress in WebClient? Pin
amx_tiger30-Apr-12 22:19
amx_tiger30-Apr-12 22:19 
GeneralRe: How to stop downloading progress in WebClient? Pin
Eddy Vluggen1-May-12 1:02
professionalEddy Vluggen1-May-12 1:02 
QuestionInserting a row into an Access Database with C# Pin
Premisoft29-Apr-12 20:00
Premisoft29-Apr-12 20:00 
AnswerRe: Inserting a row into an Access Database with C# Pin
OriginalGriff29-Apr-12 22:05
mveOriginalGriff29-Apr-12 22:05 
GeneralRe: Inserting a row into an Access Database with C# Pin
Premisoft30-Apr-12 3:48
Premisoft30-Apr-12 3:48 
GeneralRe: Inserting a row into an Access Database with C# Pin
Wes Aday30-Apr-12 5:23
professionalWes Aday30-Apr-12 5:23 
QuestionWinmm.dll for CF Windows CE Pin
baranils29-Apr-12 11:30
baranils29-Apr-12 11:30 
QuestionCollision detection between a circle and rectangle Pin
lethula29-Apr-12 5:46
lethula29-Apr-12 5:46 
AnswerRe: Collision detection between a circle and rectangle Pin
Abhinav S29-Apr-12 16:36
Abhinav S29-Apr-12 16:36 
GeneralRe: Collision detection between a circle and rectangle Pin
lethula30-Apr-12 13:20
lethula30-Apr-12 13:20 
AnswerRe: Collision detection between a circle and rectangle Pin
BobJanova29-Apr-12 23:18
BobJanova29-Apr-12 23:18 
GeneralRe: Collision detection between a circle and rectangle Pin
lethula30-Apr-12 13:27
lethula30-Apr-12 13:27 
GeneralRe: Collision detection between a circle and rectangle Pin
BobJanova30-Apr-12 22:19
BobJanova30-Apr-12 22:19 
GeneralRe: Collision detection between a circle and rectangle Pin
lethula1-May-12 22:17
lethula1-May-12 22:17 
GeneralRe: Collision detection between a circle and rectangle Pin
BobJanova2-May-12 0:46
BobJanova2-May-12 0:46 
If your rectangle is already axis-oriented you don't have to rotate, so the transformation is trivial: the circle's centre in rectangle space is (x2-(x1+½w), y2-(y1+½h)). Call this [x' y'].

Now check if the circle is possibly colliding:

if(!(x' in range [-(r + ½w), r + ½w]) || (y' in range [-(r + ½h), r + ½h])) no collision;


That accounts for the 99% case where there is definitely no collision, and you can avoid any further processing.

Then check the easy cases:

if((x' in range [-½w, ½w]) || (y' in range [-½h, h])) collision;


Finally check distance to corners. The closest corner is the closest independently along the two axes:

var dx1 = x' - ½w, dx2 = x' + ½w, dy1 = y' - ½h, dy2 = y' + ½h;
var dx_closest = min(dx1, dx2), dy_closest = min(dy1, dy2);
if(r² > (dx² + dy²)) collision;



|vector| is the vector magnitude function, i.e. distance; in a standard 2D system this is the Pythagorean distance as expanded above.

If you care about the collision vector, in the easy case it is [1, 0], [-1, 0], [0, 1] or [0, -1] depending on which side you intersected with, and in the closest-corner case it is along [dx_closest, dy_closest].
GeneralRe: Collision detection between a circle and rectangle Pin
lethula2-May-12 8:36
lethula2-May-12 8:36 
GeneralRe: Collision detection between a circle and rectangle Pin
BobJanova3-May-12 0:30
BobJanova3-May-12 0:30 
QuestionHow to get video frames from usb cam buffer Pin
bunyamin_28-Apr-12 22:58
bunyamin_28-Apr-12 22:58 
Questionhow to Encrypting Class Library Pin
jojoba201128-Apr-12 17:55
jojoba201128-Apr-12 17:55 
AnswerRe: how to Encrypting Class Library Pin
Richard MacCutchan28-Apr-12 21:28
mveRichard MacCutchan28-Apr-12 21:28 
AnswerRe: how to Encrypting Class Library Pin
OriginalGriff28-Apr-12 21:45
mveOriginalGriff28-Apr-12 21:45 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.