Geometry Problem
Geometry Problem
Geometry Problem
Geometry Problem
Geometry Problem
Geometry Problem Geometry Problem Geometry Problem Geometry Problem Geometry Problem Geometry Problem Geometry Problem Geometry Problem
Geometry Problem Geometry Problem
Geometry Problem
Go Back  Xtreme Visual Basic Talk > > > Geometry Problem


Reply
 
Thread Tools Display Modes
  #1  
Old 07-15-2005, 12:15 AM
Feline Feline is offline
Newcomer
 
Join Date: Jul 2005
Posts: 22
Default Geometry Problem


I'm writing a complex program that needs the following problem solved:

If you have two blocks (rectangle or square or even different sizes) with the top-left corner and width and height of each is given (we're dealing with Y values that increase as you go down), what code will determine if they intersect in any way (even if the corners of each block aren't in the other).

Any ideas?
Reply With Quote
  #2  
Old 07-15-2005, 12:18 AM
TeraBlight's Avatar
TeraBlightGeometry Problem TeraBlight is offline
Captain Convoluted

* Expert *
 
Join Date: Jun 2005
Posts: 1,918
Default

This kind of question sort of falls under "Game Programming" on this site. Do a search for "collision" either in that forum or in the "Code Library", you'll find enough material to keep you reading for a while
__________________
"To learn without thinking is to labour in vain" - Confucius
Reply With Quote
  #3  
Old 07-20-2005, 07:31 AM
simonle's Avatar
simonle simonle is offline
Centurion
 
Join Date: Dec 2004
Location: UK
Posts: 162
Default

Everytime you move them you could run this...
(untested)
Code:
If Block2YValue =< (Block1YValue + Block1Width) And Block2YValue >= Block1YValue Then If Block2XValue >= Block1XValue And Block2XValue =< (Block1XValue + Block1Width) Then 'Run Code End If End If
Reply With Quote
  #4  
Old 07-20-2005, 08:05 AM
Iceplug's Avatar
IceplugGeometry Problem Iceplug is offline
MetaCenturion

Retired Moderator
* Guru *
 
Join Date: Aug 2001
Location: Iowa, USA
Posts: 16,583
Default

A whole thread on detecting if two objects collide:
Overlaps & Collision Detection
__________________

Iceplug, USN
Quadrill 1 Quadrill 2 (full) Quadrill 3 JumpCross .NET Website is ALIVE! - DL Platform Tour for VB.NET! Posting Guidelines Hint: Specify your location in your user cp profile if you want compassion!
Reply With Quote
  #5  
Old 07-20-2005, 05:10 PM
Alkatran's Avatar
Alkatran Alkatran is offline
Contributor
 
Join Date: Jun 2003
Posts: 539
Default

You could also use the IntersectRect API call for a quick solution.
Reply With Quote
  #6  
Old 07-20-2005, 05:36 PM
DaftasBrush's Avatar
DaftasBrushGeometry Problem DaftasBrush is offline
Senior Contributor

* Expert *
 
Join Date: Jun 2003
Location: A room without Windows
Posts: 896
Default

I use this (or something similar)... no faffing about with RECT structures and API calls... and it's faster than any IntersectRect() method too.

Given we have objects B1 and B2 with Left,Top,Width,Height properties.
and you're using Y+ve = Down
Code:
If B1.Top > (B2.Top + B2.Height) Then ' B1 is completely below B2 Elseif (B1.Top + B1.Height) < B2.Top Then ' B1 is completely above B2 Elseif B1.Left > (B2.Left + B2.Width) Then ' B1 is completely left of B2 Elseif (B1.Left + B1.Width) < B2.Left then ' B1 is completely right of B2 Else ' They Must "Collide" (overlap in some manner) End if

You can change to <= and >= if you don't want "touching" to count as collision.

HTH
__________________
Dan B
"Don't anthropomorphize computers. They don't like it."
Trig is for wuss's - Coordinate Geometry RULES!

Last edited by DaftasBrush; 07-21-2005 at 03:14 AM.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Geometry Problem
Geometry Problem
Geometry Problem Geometry Problem
Geometry Problem
Geometry Problem
Geometry Problem Geometry Problem Geometry Problem Geometry Problem Geometry Problem Geometry Problem Geometry Problem
Geometry Problem
Geometry Problem
 
Geometry Problem
Geometry Problem
 
-->