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 3428770
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T06:59:57+00:00 2026-05-18T06:59:57+00:00

I wish to determine when a point (mouse position) in on, or near a

  • 0

I wish to determine when a point (mouse position) in on, or near a curve defined by a series of B-Spline control points.

The information I will have for the B-Spline is the list of n control points (in x,y coordinates). The list of control points can be of any length (>= 4) and define a B-spline consisting of (n−1)/3 cubic Bezier curves. The Bezier curves are are all cubic. I wish to set a parameter k,(in pixels) of the distance defined to be “near” the curve. If the mouse position is within k pixels of the curve then I need to return true, otherwise false.

Is there an algorithm that gives me this information. Any solution does not need to be precise – I am working to a tolerance of 1 pixel (or coordinate).

I have found the following questions seem to offer some help, but do not answer my exact question. In particular the first reference seems to be a solution only for 4 control points, and does not take into account the nearness factor I wish to define.

Position of a point relative to a Bezier curve

Intersection between bezier curve and a line segment

EDIT:
An example curve:

 e, 63.068, 127.26   
    29.124, 284.61   
    25.066, 258.56   
    20.926, 212.47   
        34, 176  
    38.706, 162.87  
    46.556, 149.82  
    54.393, 138.78 

The description of the format is: “Every edge is assigned a pos attribute, which consists of a list of 3n + 1 locations. These are B-spline control points: points p0, p1, p2, p3 are the first Bezier spline, p3, p4, p5, p6 are the second, etc. Points are represented by two integers separated by a comma, representing the X and Y coordinates of the location specified in points (1/72 of an inch). In the pos attribute, the list of control points might be preceded by a start point ps and/or an end point pe. These have the usual position representation with a “s,” or “e,” prefix, respectively.”

EDIT2: Further explanation of the “e” point (and s if present).

In the pos attribute, the list of control points might be preceded by a start
point ps and/or an end point pe. These have the usual position representation with a
“s,” or “e,” prefix, respectively. A start point is present if there is an arrow at p0.
In this case, the arrow is from p0 to ps, where ps is actually on the node’s boundary.
The length and direction of the arrowhead is given by the vector (ps −p0). If there
is no arrow, p0 is on the node’s boundary. Similarly, the point pe designates an
arrow at the other end of the edge, connecting to the last spline point.

  • 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-18T06:59:58+00:00Added an answer on May 18, 2026 at 6:59 am

    You may do this analitically, but a little math is needed.

    A Bezier curve can be expressed in terms of the Bernstein Basis. Here I’ll use Mathematica, that provides good support for the math involved.

    So if you have the points:

    pts = {{0, -1}, {1, 1}, {2, -1}, {3, 1}};  
    

    The eq. for the Bezier curve is:

    f[t_] := Sum[pts[[i + 1]] BernsteinBasis[3, i, t], {i, 0, 3}];
    

    Keep in mind that I am using the Bernstein basis for convenience, but ANY parametric representation of the Bezier curve would do.

    Which gives:

    alt text

    Now to find the minimum distance to a point (say {3,-1}, for example) you have to minimize the function:

    d[t_] := Norm[{3, -1} - f[t]];  
    

    For doing that you need a minimization algorithm. I have one handy, so:

    NMinimize[{d[t], 0 <= t <= 1}, t]  
    

    gives:

     {1.3475, {t -> 0.771653}}  
    

    And that is it.

    HTH!

    Edit Regarding your edit “B-spline with consisting of (n−1)/3 cubic Bezier curves.”

    If you constructed a piecewise B-spline representation you should iterate on all segments to find the minima. If you joined the pieces on a continuous parameter, then this same approach will do.

    Edit

    Solving your curve. I disregard the first point because I really didn’t understand what it is.

    I solved it using standard Bsplines instead of the mathematica features, for the sake of clarity.

    Clear["Global`*"];
    (*first define the points *)
    pts = {{
            29.124, 284.61}, {
            25.066, 258.56}, {
            20.926, 212.47}, {
            34, 176}, {
            38.706, 162.87}, {
            46.556, 149.82}, {
            54.393, 138.78}};
    
    (*define a bspline template function *)
    
    b[t_, p0_, p1_, p2_, p3_] :=
                      (1-t)^3 p0 + 3 (1-t)^2 t p1 + 3 (1-t) t^2 p2 + t^3 p3;
    
    (* define two bsplines *)
    b1[t_] := b[t, pts[[1]], pts[[2]], pts[[3]], pts[[4]]];
    b2[t_] := b[t, pts[[4]], pts[[5]], pts[[6]], pts[[7]]];
    
    (* Lets see the curve *)
    
    Show[Graphics[{Red, Point[pts], Green, Line[pts]}, Axes -> True], 
     ParametricPlot[BSplineFunction[pts][t], {t, 0, 1}]]
    

    .
    ( Rotated ! for screen space saving )

    alt text

    (*Now define the distance from any point u to a point in our Bezier*)
    d[u_, t_] := If[(0 <= t <= 1), Norm[u - b1[t]], Norm[u - b2[t - 1]]];
    
    (*Define a function that find the minimum distance from any point u \
    to our curve*)
    h[u_] := NMinimize[{d[u, t], 0.0001 <= t <= 1.9999}, t];
    
    (*Lets test it ! *)
    Plot3D[h[{x, y}][[1]], {x, 20, 55}, {y, 130, 300}]
    

    This plot is the (minimum) distance from any point in space to our curve (of course the value over the curve is zero):

    alt text

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

Sidebar

Related Questions

I wish to test a function that will generate lorem ipsum text, but it
I wish Subversion had a better way of moving tags. The only way that
I wish to know all the pros and cons about using these two methods.
I wish to implement a 2d bit map class in Python. The class would
I wish to implement my software on a shareware basis, so that the user
I wish I were a CSS smarty .... How can you place a div
I wish to search a database table on a nullable column. Sometimes the value
I wish to use xml and xsl to generate controls on an asp.net page.
I wish to perform an experiment many different times. After every trial, I am
I wish to migrate the database of a legacy web app from SQL Server

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.