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

  • Home
  • SEARCH
  • 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 8257883
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T02:21:12+00:00 2026-06-08T02:21:12+00:00

I need a mechanism for detecting mouseover event for lines, curves and polylines which

  • 0

I need a mechanism for detecting mouseover event for lines, curves and polylines which have a various stroke width, I have already made such a mechanism for rectangles and ellipses, so I’m not new with canvas API. I do outline all of the drawn objects and detect mouse position over them, when rectangles or ellipses have a stroke width more than 1 pixel I expand the path so that it contains the border too. For lines and polylines it is difficult for me to understand how should I expand them when I have a lineWidth of 20 pixels for example.

My question is: how to transform lines, curves and polylines in some shape path, so that this path could contain all their width?

red - path, black - stroked path

I would need that the path created would contain the line / curve width represented with black in this image.

———-Some more information———-

I will try to simplify the problem:
We have 2 points (represented in red on the image below), they form a line that have a specific formula (y = mx + n), I need to dermine the formulas of perpendicular lines that are passing through these two initial points, after, it is necessary to determine the positions of the “blue” points, which are at the distance of the half of the value of context.lineWidth, when all points have been determined it is possible to create a new path using moveTo() and lineTo() sequence. This method should be applicable for quadratic and bezier curves using control points. The problem only remains in these mathematical calculations.

  • 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-06-08T02:21:14+00:00Added an answer on June 8, 2026 at 2:21 am

    I found the solution on math.stackexchange here, this solution is for lines only, but it is applicable for curves and polylines with some specific modifications. First of all, we need to determine the formula of the line which passes through the two initials points:

    Step 1

    Our points: P1(x1, y1) and P2(x2, y2)

    Distance between points and their neighbors: d

    General form: Ax + By + C = 0

    Where: A = y2 – y1; B = x1 – x2; C = x2y1 – x1y2.

    After, it is necessary to define this formula in the short form:

    Step 2

    Short form: y = mx +n

    Where: m = – A / B; n = – C / B. (when B != 0)

    If A == 0 then we have the formula: y = C (case when we have a horizontal line)

    If B == 0 then we have the formula: x = C (case when we have a vertical line)

    When we have the slope of the line, we need the slope of the perpendicular line on it:

    Step 3

    Perpendiculat line slope: m2 = – 1 / m

    If A == 0 or B == 0 go to Step 4

    Now we need to get the neighbor points for both initial points:

    Step 4

    I will note neighbor points as P1N1, P1N2 for the first point and P2N1 and P2N2 for the second one

    For the special cases (horizontal and vertical lines, when A == 0 or B == 0) we will have:

    For A == 0 (horizontal line):

    P1N1(x1, y1 – d / 2); P1N2(x1, y1 + d / 2); P2N1(x2, y2 + d / 2); P2N2(x2, y2 – d / 2).

    For B == 0 (vertical line):

    P1N1(x1 – d / 2, y1); P1N2(x1 + d / 2, y1); P2N1(x2 + d / 2, y2); P2N2(x2 – d / 2, y2).

    For other cases (A != 0 and B != 0):

    P1N1:

    x = (d / 2) / Math.sqrt(1 + Math.pow(m2, 2)) + x1;

    y = (m2 * (d / 2)) / Math.sqrt(1 + Math.pow(m2, 2)) + y1;

    P1N2:

    x = – (d / 2) / Math.sqrt(1 + Math.pow(m2, 2)) + x1;

    y = – (m2 * (d / 2)) / Math.sqrt(1 + Math.pow(m2, 2)) + y1;

    P2N1:

    x = (d / 2) / Math.sqrt(1 + Math.pow(m2, 2)) + x2;

    y = (m2 * (d / 2)) / Math.sqrt(1 + Math.pow(m2, 2)) + y2;

    P2N2:

    x = – (d / 2) / Math.sqrt(1 + Math.pow(m2, 2)) + x2;

    y = – (m2 * (d / 2)) / Math.sqrt(1 + Math.pow(m2, 2)) + y2;

    If you want to implement these formulas in your application you should cache some results to improve performance.

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

Sidebar

Related Questions

I need an efficient mechanism for detecting changes to the DOM. Preferably cross-browser, but
I have a MYSQL table that holds events information. I need a mechanism that
I need to design a translation mechanism/strategy for the static text in my (scalable)
I need to implement some form of communication mechanism in my application, to send
I need to find ways to add retry mechanism to my DB calls in
I need to implement a very specific demo mechanism. It must not expire after
I am learning and using Web API and need to implement following Authentication mechanism
Need some regular expressions help. So far I have my code working to allow
I have a perl script i made to automatically telnet into different servers .
I need a CRC mechanism to calculate the CRC of a number of strings,

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.