Click here to Skip to main content
16,007,610 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralClicking on Line Pin
Monty26-Feb-04 21:25
Monty26-Feb-04 21:25 
GeneralRe: Clicking on Line Pin
Alexander M.,7-Feb-04 3:06
Alexander M.,7-Feb-04 3:06 
GeneralRe: Clicking on Line Pin
Jim Crafton7-Feb-04 7:59
Jim Crafton7-Feb-04 7:59 
GeneralRe: Clicking on Line Pin
AORD7-Feb-04 16:31
AORD7-Feb-04 16:31 
GeneralRe: Clicking on Line Pin
Tom Larsen8-Feb-04 7:36
Tom Larsen8-Feb-04 7:36 
GeneralRe: Clicking on Line Pin
Paul Hooper8-Feb-04 11:55
Paul Hooper8-Feb-04 11:55 
GeneralRe: Clicking on Line Pin
Monty28-Feb-04 17:56
Monty28-Feb-04 17:56 
GeneralRe: Clicking on Line Pin
Paul Hooper8-Feb-04 18:33
Paul Hooper8-Feb-04 18:33 
No problems. Two small caveats though.

First, the "sensitivity" is the distance you want the user to click within SQUARED. This saves calculating a sqrt.

Secondly, I forgot to mention in the original post that this code calculates the perpendicular distance to the line defined by the two points - extended to infinity in both directions. In other words

.
 .
  X
   \ *
    \
     \
      X
       .
        .
         .
        * .

if your line is defined by the X's then BOTH points marked with * would return true. If you want to restrict the result to only the top asterisk, you will need to add extra checking to the routine. The last line would need to be

return (h < Sensitivity && a < c && b < c);

I should also explain what the code is doing. It assumes that your start point, stop point and the click point form a triangle

        *
        |h
X------------------------X

the code calculates h - the perpendicular distance. First, we calculate the length of each side. Second, we use the three side lengths to calculate the area of the triangle using Heron's formula

Area = sqrt(s(s-a)(s-b)(s-c)) where s is (a+b+c)/2;

Third, we use the other formula for area of a triangle

Area = 1/2 base * height.

We know the area, we know the base, we can find the height. The code actually calculates h squared as described above.

Finally, the && a < c && b < c part of the modified last works this way.
                                   *
                                   |h
X-----------c------------X............

c is the distance between the X's and a would be the distance between the first X and the *. Because a > c, we know that the * is on the "extended" line.

I hope this all makes sense. Sorry I didn't explain it better the first time.



Paul Hooper

If you spend your whole life looking over your shoulder, they will get you from the front instead.
GeneralTransfer Files over Network Pin
rasha20036-Feb-04 20:54
rasha20036-Feb-04 20:54 
GeneralRe: Transfer Files over Network Pin
Alexander M.,7-Feb-04 3:00
Alexander M.,7-Feb-04 3:00 
GeneralRe: Transfer Files over Network Pin
Anonymous7-Feb-04 3:05
Anonymous7-Feb-04 3:05 
GeneralRe: Transfer Files over Network Pin
Ashman7-Feb-04 15:12
Ashman7-Feb-04 15:12 
GeneralRe: Transfer Files over Network Pin
John M. Drescher7-Feb-04 19:08
John M. Drescher7-Feb-04 19:08 
GeneralRe: Transfer Files over Network Pin
Tom Larsen8-Feb-04 7:39
Tom Larsen8-Feb-04 7:39 
Generalcreate a toolber in MFC Pin
Zeeshan Bilal6-Feb-04 18:24
Zeeshan Bilal6-Feb-04 18:24 
GeneralRe: create a toolber in MFC Pin
Selvam R6-Feb-04 18:46
professionalSelvam R6-Feb-04 18:46 
GeneralRe: create a toolber in MFC Pin
Anonymous6-Feb-04 18:48
Anonymous6-Feb-04 18:48 
GeneralHelp with user input problem. Pin
Pakled6-Feb-04 15:41
Pakled6-Feb-04 15:41 
GeneralRe: Help with user input problem. Pin
Daniel13246-Feb-04 16:02
Daniel13246-Feb-04 16:02 
GeneralGet local IP addresses &amp; netmask Pin
Anonymous___6-Feb-04 14:58
sussAnonymous___6-Feb-04 14:58 
GeneralRe: Get local IP addresses &amp; netmask Pin
David Crow6-Feb-04 15:40
David Crow6-Feb-04 15:40 
GeneralRe: Get local IP addresses &amp; netmask Pin
Anonymous7-Feb-04 3:07
Anonymous7-Feb-04 3:07 
GeneralBandwidth Throttling... Pin
code-frog6-Feb-04 12:51
professionalcode-frog6-Feb-04 12:51 
GeneralRe: Bandwidth Throttling... Pin
Jörgen Sigvardsson7-Feb-04 14:10
Jörgen Sigvardsson7-Feb-04 14:10 
GeneralRe: Bandwidth Throttling... Pin
code-frog7-Feb-04 15:47
professionalcode-frog7-Feb-04 15:47 

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.