Quinn-Curtis Forums
Quinn-Curtis Forums
Home | Profile | Register | Active Topics | Members | Search | FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 Tools for Microsoft .Net
 Real-Time Graphics Tools for .Net (VB and C#)
 How to detect if a given point is inside an object
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

soundar

51 Posts

Posted - 07 Aug 2008 :  18:19:26  Show Profile  Reply with Quote
I have a list of RTRoundedRectangle2D objects.

I want to find out if a given point, in PHYS_COORDS, is inside any of these RTRoundedRectangle2D objects by iterating through them like so:

for each rt in myRectangles
if rt...Contains(x,y) then
'show the rectangle
else
'hide the rectangle
end if
next

myRectangles is a global List Of(RTRoundedRectangle2D)
I can show and hide the rectangles by adding the containing rectangle to the ChartView object, and by removing the previous object.

I cannot figure out how to do the hit test for a given point. This is a point known to me (not a mouse click point) and I am not sure if I should use the NearestDataPoint methods.

Please help.

quinncurtis

1586 Posts

Posted - 07 Aug 2008 :  18:54:03  Show Profile  Reply with Quote
If you restrict the test point and rectangle to physical coordinates it seems pretty simple to us. Perhaps we are missing something. This does not take into account the rounded corners, but none of our routines will.

public bool HitTest (Point2D pt, RTRoundedRectangle2D rect)
{
   bool result = false;
   if ((pt.X > rect.X) &&
       (pt.Y > rect.Y) &&
       (pt.X < (rect.X + rect.Width)) &&
       (pt.Y < (rect.Y + rect.Height)))
       {
          result = true;
       }
     return result;
}
Go to Top of Page

soundar

51 Posts

Posted - 07 Aug 2008 :  20:26:57  Show Profile  Reply with Quote
Thanks. I guess I was looking for a one-line function...because I noticed the CheckIntersection function and also the Contains method of the Rectangle2D class. I thought I should be able to use them.
Go to Top of Page

quinncurtis

1586 Posts

Posted - 07 Aug 2008 :  22:14:38  Show Profile  Reply with Quote
Those routines work in device (pixel) coordinates since they are designed to process mouse clicks.
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
Quinn-Curtis Forums © 2000-2018 Quinn-Curtis, Inc. Go To Top Of Page
Powered By: Snitz Forums 2000 Version 3.4.07