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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T22:47:44+00:00 2026-05-23T22:47:44+00:00

I need to draw a curve smoothly through N points with N>2 with Javascript.

  • 0

I need to draw a curve smoothly through N points with N>2 with Javascript. I am currently using the bezierCurveTo() within an html5 canvas object. I’ve invested a good deal of time into trying to find the best method of accomplishing this, and while Catmull-Rom Splines sound promising, I am unaware of a way to draw them as lines. I therefore am left with Poly-line Bézier curves and need to find all intermediate control points.

It took me relearning a good deal of math but I have a partially working example here. The line is not particularly smooth at times, and there is an issue with my control points being off for certain vectors. Here is my initial math.stackexchange question that I asked to get the bulk of the math for the control points.

I would also be open to the Catmull-Rom Splines but would need some help as to how I can convert them to lines on the canvas. I have found this resource, but again am lost in applying it to my needs.

Heres an image created from my example link above illustrating how to replicate the bad control points:

enter image description here

Thank you very much for any help in advance!

  • 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-23T22:47:45+00:00Added an answer on May 23, 2026 at 10:47 pm

    Original code:

    var a = new Array(points[p-1].x,points[p-1].y);
    var b = new Array(points[p].x,points[p].y);
    var c = new Array(points[p+1].x,points[p+1].y);
    
    var delta_a = subtract_v(a, b);
    var delta_c = subtract_v(c, b);
    
    // Get vector (m) perpendicular bisector
    var m = normalize_v( add_v( normalize_v(delta_a),normalize_v(delta_c) ) );
    
    // Get ma and mc
    var ma = normalize_v( subtract_v(delta_a,multiply_v(multiply_v(delta_a,m),m) ) );
    var mc = normalize_v( subtract_v(delta_c,multiply_v(multiply_v(delta_c,m),m) ) );
    
    // Get the coordinates
    points[p].c2x = resolution( b[0] + ( (Math.sqrt( sqr(delta_a[0]) + sqr(delta_a[1]) ) / tightness) * ma[0] ) );
    points[p].c2y = resolution( b[1] + ( (Math.sqrt( sqr(delta_a[0]) + sqr(delta_a[1]) ) / tightness) * ma[1] ) );
    points[p+1].c1x = resolution( b[0] + ( (Math.sqrt( sqr(delta_c[0]) + sqr(delta_c[1]) ) / tightness) * mc[0] ) );
    points[p+1].c1y = resolution( b[1] + ( (Math.sqrt( sqr(delta_c[0]) + sqr(delta_c[1]) ) / tightness) * mc[1] ) );
    

    I have no idea what “Get ma and mc” is supposed to do here. What you need is a vector orthogonal to the angle bisector (m), and its negative.

    Sorry for the horrible drawing

    So this should be fine:

    var delta_a = subtract_v(b, a); // note that we're calculating AB instead of BA
    var delta_c = subtract_v(c, b);
    
    // Get an orthogonal to the angle bisector
    var m = normalize_v( add_v( normalize_v(delta_a),normalize_v(delta_c) ) );
    
    var ma = [-m[0],-m[1]];
    var mc = m;
    

    Also make sure to remove the resolution() for your control points.

    Edit:
    You should also add a fallback for edge cases (for example, A==B or A==C, in which case your script will throw an exception, trying to normalize the 0 vector)

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

Sidebar

Related Questions

I need to draw a complicated object with Qt primitives using QPainter. The thing
I need to draw a curve in WPF on a canvas, which alternates colour,
I need to draw text onto a window HDC along a circular path using
I need to draw a UILabel striked through. Therefore I subclassed UILabel and implemented
I need to draw an elliptic curve over the finite field F17(in other words,
I need to draw an arc using GraphicsPath and having initial, median and final
I need to draw a BufferedImage within a given quadrilateral. I want to do
I'm trying to draw a function's curve, so I need a method to convert
I need to draw 3d projections and i am using opengl wrapper for JAVA.
i need to draw something like the image below using WPF... i need this

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.