|
-
Apr 15th, 2001, 04:27 AM
#1
Thread Starter
Addicted Member
Hi guys,
Please explain me how can I find whether any drawn line on the form crossed or not Image box. Line has started coordinates X, Y when mouse button pressed and final coordinates X, Y when it was released. And Image – say small circle with coordinates X, Y and also width ~ 15 pixels. I appreciate any help.
-
Apr 20th, 2001, 02:46 AM
#2
Retired VBF Adm1nistrator
You want to check if a line intersects a rectangle is it ?
Well in java I had to do something similar.
This code might help (its easily ported) ;
Code:
private static boolean isCross(myVertex lne1, myVertex lne2) {
boolean toReturn = false;
double dx1 = lne1.x2 - lne1.x1;
double dy1 = lne1.y2 - lne1.y1;
double dx2 = lne2.x2 - lne2.x1;
double dy2 = lne2.y2 - lne2.y1;
double n = 0.0;
double s = 0.0;
if ((dx2 * dy1) - (dy2 * dx1) != 0) {
n = (dx1 * (lne2.y1 - lne1.y1) + dy1 * (lne1.x1 - lne2.x1)) / (dx2 * dy1 - dy2 * dx1);
s = (dx2 * (lne1.y1 - lne2.y1) + dy2 * (lne2.x1 - lne1.x1)) / (dy2 * dx1 - dx2 * dy1);
toReturn = ((s >= 0) && (s <= 1) && (n >= 0) && (n <= 1));
}
return toReturn;
}
class myVertex {
int x1;
int y1;
int x2;
int y2;
}
Microsoft MVP : Visual Developer - Visual Basic [2004-2005]
-
Apr 21st, 2001, 06:14 AM
#3
Thread Starter
Addicted Member
Thanks a lot, plenderj. It just what I needed. I have tried it tonight and it worked fine.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|