Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6029609
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T04:54:42+00:00 2026-05-23T04:54:42+00:00

Im not sure if this clear enough to describe the problem… I have 2

  • 0

Im not sure if this clear enough to describe the problem…

I have 2 different points, Start -> End then it forms a Line.

I would like to make an event on MouseMove if the MousePos touches the lines..

what i did was using the PtInRect but the results are for the rectangle area not the line. is there any function to use or manually made. any idea?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T04:54:43+00:00Added an answer on May 23, 2026 at 4:54 am

    Check this code (original source check if the Cursor is on a line?) from torry’s

    type
      TForm73 = class(TForm)
        Button1: TButton;
        procedure FormCreate(Sender: TObject);
        procedure FormMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
        procedure Button1Click(Sender: TObject);
      private
        x1,y1,x2,y2 : Integer;
      public
      end;
    
    var
      Form73: TForm73;
    
    implementation
    
    {$R *.dfm}
    
    function PontInLine(X, Y, x1, y1, x2, y2, d: Integer): Boolean;
    var
      sine, cosinus: Double;
      dx, dy, len: Integer;
    begin
      if d = 0 then d := 1;
      asm
        fild(y2)
        fisub(y1) // Y-Difference
        fild(x2)
        fisub(x1) // X-Difference
        fpatan    // Angle of the line in st(0)
        fsincos   // Cosinus in st(0), Sinus in st(1)
        fstp cosinus
        fstp sine
      end;
      dx  := Round(cosinus * (x - x1) + sine * (y - y1));
      dy  := Round(cosinus * (y - y1) - sine * (x - x1));
      len := Round(cosinus * (x2 - x1) + sine * (y2 - y1)); // length of line
      Result:= (dy > -d) and (dy < d) and (dx > -d) and (dx < len + d);
    end;
    
    
    procedure TForm73.Button1Click(Sender: TObject);
    begin
      with Canvas do
      begin
        Pen.Color := clRed;
        MoveTo(x1,y1);
        LineTo(x2,y2);
      end;
    end;
    
    procedure TForm73.FormCreate(Sender: TObject);
    begin
       x1:=10;
       y1:=100;
       x2:=200;
       y2:=150;
    end;
    
    procedure TForm73.FormMouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    var
      p: TPoint;
    begin
      GetCursorPos(p);
      p := ScreenToClient(p);
      if PontInLine(p.x, p.y, x1, y1, x2, y2, 1) then
        Caption := 'Mouse on line.'
      else
        Caption := 'Mouse not on line.'
    end;
    

    UPDATE

    This is the equivalent function PontInLine without use assembly (directly).

    uses
      Math;
    
    function PontInLine(X, Y, x1, y1, x2, y2, d: Integer): Boolean;
    var
      Theta,  sine, cosinus: Double;
      dx, dy, len: Integer;
    begin
      if d = 0 then d := 1;
      //calc the angle of the line
      Theta:=ArcTan2( (y2-y1),(x2-x1));
      SinCos(Theta,sine, cosinus);
      dx  := Round(cosinus * (x - x1) + sine * (y - y1));
      dy  := Round(cosinus * (y - y1) - sine * (x - x1));
      len := Round(cosinus * (x2 - x1) + sine * (y2 - y1)); // length of line
      Result:= (dy > -d) and (dy < d) and (dx > -d) and (dx < len + d);
    end;
    

    enter image description here
    (source: swissdelphicenter.ch)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am not sure the title is clear enough. I have a dataframe (see
So I am not sure if my title is clear enough. I essentially have
I'm sure this is a fairly trivial problem, but I'm not sure what to
Ok, I'm not sure that my title was clear enough, but I will try
EDIT: I'm not sure that my original question is clear enough. I need an
I'm sure there's a clean way to do this, but I'm probably not using
Not sure this is a programming question, but we use LaTeX for all our
Not sure this is possible, but looking to write a script that would return
I'm not sure this is possible, but in ruby, you can dynamically call a
I'm not sure this is possible, but is there a syntax to be used

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.