Results 1 to 6 of 6

Thread: Click on a line (Linear function)

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Aug 1999
    Location
    Ilirska Bistrica, Slovenia
    Posts
    242

    Click on a line (Linear function)

    I actually found one possible solution, however it doesn't work.
    Let's see:

    For each line there's a mathematical function with that form:

    y = k * x + n

    y= y coord; x = x coord; n = number; k = static variable

    Following function is the same as above, it just uses 2 coordinates (x, x1, y, y1)

    y - y1 = k * (x - x1) ---> y = k * (x - x1) + y1

    Point is that here we do not have k, so we have to calculate it. This is done by next function:

    k = (y2 - y1) / (x2 - x1)

    Now we have k, both coordinates and function for that line. And even now I cannot find out if I clicked on a line.

    Any suggestions?
    Zvonko Bostjancic
    Ilirska Bistrica, Slovenia
    [email protected]
    Using VS6 Professional with SP3
    Programming mostly in VB and I've started to learn VC++ & MFC

  2. #2
    Guru Yonatan's Avatar
    Join Date
    Apr 1999
    Location
    Israel
    Posts
    892
    The function of the line is:
    y = kx + n
    You clicked on the point: (a, b)
    So you clicked on your line, if the following is true:
    b = ka + n

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Aug 1999
    Location
    Ilirska Bistrica, Slovenia
    Posts
    242
    That's true, Yonatan.
    However I have two other constants to retrieve/get/find: k and n.
    K is retrieved with that function:
    k = (y2 - y1) / (x2 - x1)
    Then I have to get n. This is for me impossible, so I use another linear function, equivalent to y=kx+n: y - y1 = k(x - x1) or y = k(x - x1) + y1
    Like this I take one saved point (start or end coordinate - x,y) and point where I clicked (x1,y1).

    And it still doesn't work.

    Suggestions are welcome
    Zvonko Bostjancic
    Ilirska Bistrica, Slovenia
    [email protected]
    Using VS6 Professional with SP3
    Programming mostly in VB and I've started to learn VC++ & MFC

  4. #4
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    You're probably not clicking on the line, and might be a bit hard to do so. Instead you could try accepting clicks close enough to the line. You can get the distance to the line by squarerooting the difference between the length of vector AC and dotproduct of AB and AC. compare a scalar constant D which specify the max distance from the line with the root, to retrieve validation.
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Aug 1999
    Location
    Ilirska Bistrica, Slovenia
    Posts
    242
    Good answer, kedaman...

    That's what I wanted to do..

    However... would you be so kind and post an example here? I'm from Slovenia and english mathematical terms are not very familiar to me...
    Zvonko Bostjancic
    Ilirska Bistrica, Slovenia
    [email protected]
    Using VS6 Professional with SP3
    Programming mostly in VB and I've started to learn VC++ & MFC

  6. #6
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    perhaps you understand mathematical symbols isntead. I think you could use the crossproduct instead.
    Code:
    | AC x AB |
    _________ < D
    |AB|
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width