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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T16:25:29+00:00 2026-06-01T16:25:29+00:00

I want to draw two lines that go through three points, and make a

  • 0

I want to draw two lines that go through three points, and make a rounded corner at the second point. Here I have a problem. If the angle between the two lines is less than 90 degrees, there will be an extra line appended on the line through point1 and point2. If the angle is larger than or equal to 90 degrees, it will be ok, though.

You can see this in the snippet below:

function Point(x, y){
  this.x = x ? x : 0;
  this.y = y ? y : 0;
}
var ctx,
    canvas = document.getElementById('canvas');
canvas.width = 600;
canvas.height = 600;

ctx = canvas.getContext('2d');
ctx.lineWidth = 2;

draw(ctx, new Point(50,10), new Point(20, 300), new Point(100, 320) );
draw(ctx, new Point(200,10), new Point(200, 300), new Point(300, 20) );

function draw(ctx, p1, p2, p3){
  var k1,k2, k, len, r=8;
  k1 = Math.atan2(p2.y - p1.y, p2.x - p1.x);
  k2 = Math.atan2(p3.y - p2.y, p3.x - p2.x);
  k = (k1-k2)/2;
  len = Math.abs(r/Math.tan(k));  // the distance between point of tangency and p2
  ctx.moveTo(p1.x, p1.y);
  ctx.lineTo(p2.x - len*Math.cos(k1), p2.y - len*Math.sin(k1) ); // lineTo the point of tangency
  ctx.arcTo(p2.x, p2.y, p2.x + len*Math.cos(k2), p2.y + len*Math.sin(k2), r ); // then arc
  ctx.lineTo(p3.x, p3.y); // till p3
  ctx.stroke();
}
<canvas id='canvas' style="width:600px; height:600px; margin: 0 auto; background-color: yellow; "; />
  • 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-01T16:25:31+00:00Added an answer on June 1, 2026 at 4:25 pm

    I couldn’t find your error so started again see http://jsfiddle.net/yUkK3/6/

    Seems to work OK unless you have P1 and P3 in wrong order. (Last example on the fiddle) Can see why it happens but have not worked on correction yet.

    Explanation of when it goes wrong.

    Taking P2 as origin, rotate P1 so that P1 to P2 lies along x axis with P1 positive, then drawing fails when P3.y is negative.

    Hope this helps

    EDIT Have now sorted out the order problem described above. http://jsfiddle.net/yUkK3/7/

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

Sidebar

Related Questions

I have a program where I want to draw a line between two points.
I have a two divs, Div1 and Div2, I want to draw two lines
I have been learning MFC these days.I want to draw lines with MoveTo() and
In the past, I wrote an app that would draw lines with two touches.
Ok, I have an application that uses a mapping system to draw lines. Each
I have a Line class composed of two Points of two ints each that
I have two series of N points I want to graph in two different
I'm using pygame to draw a line between two arbitrary points. I also want
I am again here with two Question, both inter-related I want to draw embossed
I want to draw some lines and rectangles on a panel. Sometimes it does

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.