Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

help detecting clicks on the line i have drawn

Status
Not open for further replies.

mike9606

Programmer
May 24, 2000
8
US
I need to be able to detect or work out if the line has been clicked, i have an array of tpoint and am able to detect if clicks occured on the skelton path of the line, <br><br>however i'm unsure as to how to work out if the click occured between two tpoints on the line, ie i have point a and point b and a line is drawn between them how do i work out if there has been a click on the line drawn between a and b? and can i create a method so that the click will be automatically detected and methods called to determine if the click was on the line?
 
Hi! You can identify if click point lie in the <br>rectangle if do this:<br><br>&nbsp;&nbsp;&nbsp;&nbsp;------------------------------<br>&nbsp;&nbsp;&nbsp;&nbsp;¦&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;¦<br>&nbsp;P1 *&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;* P2<br>&nbsp;&nbsp;&nbsp;&nbsp;¦&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;¦<br>&nbsp;&nbsp;&nbsp;&nbsp;------------------------------<br><br>P1 and P2 - two points of line (P1=(x1,y1);P2=(x2,y2))<br>W - half width of this line;<br>no matter how this rectangle oriented on plane,<br>if You have point (x,y) then You can calculate<br><br>&nbsp;&nbsp;&nbsp;&nbsp;((x-x1)*(y2-y1)-(x2-x1)*(y-y1))^2<br>A= ---------------------------------<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(x2-x1)^2+(y2-y1)^2<br>if A above W*W then point(x,y) don`t hit to rectangle<br>else point(x,y) lie in given rectangle.<br>
 
Ups! :)<br>I missed second condition.<br><br>&nbsp;&nbsp;&nbsp;(x-x1)*(x2-x1)+(y-y1)*(y2-y1)<br>B= -----------------------------<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(x2-x1)^2+(y2-y1)^2<br><br>So if (B&gt;=0)and(B&lt;=1)and(A&lt;=W*W) then given point<br>hit to rectangle.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top