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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T06:26:47+00:00 2026-05-28T06:26:47+00:00

I am attempting to draw the 3 arrows below. I can draw the top

  • 0

I am attempting to draw the 3 arrows below. I can draw the top one correctly but I cannot draw the other 2 arrow heads correctly. I am using HTML5 Canvas to draw these arrows.

enter image description here

The problem occurs with my arcTo calls. I just cannot get the correct curve to occur for some reason. Maybe I should be using a Bezier curve? Would anyone be able to tell me what HTML5/Javascript functions I use to produce the above arrow heads?

Can you provide an example of how to achieve the above arrow heads?

Heres the JSFiddle to show whats going wrong: http://jsfiddle.net/hJX8X/

<canvas id="testCanvas" width="400px" height="400px">

</canvas>
<script type="text/javascript">
<!--
    var canvas = document.getElementById("testCanvas");
    var dc     = canvas.getContext("2d");

    // Points which are correct (when I draw straight lines its a perfect arrow
    var width    = 400;
    var height   = 100;
    var arrowW   = 0.35 * width;
    var arrowH   = 0.75 * height;
    var p1       = {x: 0,              y: (height-arrowH)/2};
    var p2       = {x: (width-arrowW), y: (height-arrowH)/2};
    var p3       = {x: (width-arrowW), y: 0};
    var p4       = {x: width,          y: height/2};
    var p5       = {x: (width-arrowW), y: height};
    var p6       = {x: (width-arrowW), y: height-((height-arrowH)/2)};
    var p7       = {x: 0,              y: height-((height-arrowH)/2)};

    dc.clearRect(0, 0, canvas.width, canvas.height);
    dc.fillStyle = "#FF0000";

    dc.beginPath();

    dc.moveTo(p1.x, p1.y);
    dc.lineTo(p2.x, p2.y);
    dc.lineTo(p3.x, p3.y);      
    dc.moveTo(p3.x, p3.y);
    dc.arcTo(p3.x, p3.y, p4.x, p4.y, 50);
    dc.moveTo(p4.x, p4.y);
    dc.arcTo(p4.x, p4.y, p5.x, p5.y, 50);
    dc.moveTo(p5.x, p5.y);
    dc.lineTo(p6.x, p6.y);
    dc.lineTo(p7.x, p7.y);

    dc.closePath();
    dc.fill();

    /* Draw arrow without curves
    dc.moveTo(p1.x, p1.y);
    dc.lineTo(p2.x, p2.y);
    dc.lineTo(p3.x, p3.y);      
    dc.lineTo(p4.x, p4.y);  
    dc.lineTo(p5.x, p5.y);
    dc.lineTo(p6.x, p6.y);
    dc.lineTo(p7.x, p7.y);
    */
-->
</script>
  • 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-28T06:26:48+00:00Added an answer on May 28, 2026 at 6:26 am

    So we’ve got this path that makes an arrow. I’ve annotated it:

    dc.moveTo(p1.x, p1.y);
    dc.lineTo(p2.x, p2.y); // end of main block
    dc.lineTo(p3.x, p3.y); // topmost point     
    dc.lineTo(p4.x, p4.y); // endpoint 
    dc.lineTo(p5.x, p5.y); // bottommost point 
    dc.lineTo(p6.x, p6.y); // end at bottom point 
    dc.lineTo(p7.x, p7.y);
    

    We really want to keep it as similar as possible except we want to get to the endpoint (and back) in a different way than just a straight line. We absolutely do not want to use any moveTo commands except the first one. That really confounds things and makes them hard to understand. I’d also avoid using arcTo unless you really need part of an arc (like in a pie) because its fairly confusing compared to the other path commands.

    So we’ll use quadratic curves which are like beziers but only have one control point, making them pretty simple. They work by specifying a control point like this (on the left).

    So we take the same exact arrow code and insert two quadratic beziers to make a skinny arrow. We want the control points to be sorta “inside” the mass of the arrow to make the quadratics bend inwards:

    dc.moveTo(p1.x, p1.y);
    dc.lineTo(p2.x, p2.y); // end of main block
    dc.lineTo(p3.x, p3.y); // topmost point
    // control point is based on p3 (topmost point)
    dc.quadraticCurveTo(p3.x + 20, p3.y + 30, p4.x, p4.y); // endpoint 
    // control point is based on p5 (bottommost point)
    dc.quadraticCurveTo(p5.x + 20, p5.y - 30, p5.x, p5.y); // bottommost point 
    dc.lineTo(p6.x, p6.y); // end at bottom point 
    dc.lineTo(p7.x, p7.y);
    

    Or a fat one, we put the control point at the same height as the topmost and bottommost point, and around the same X as the endpoint:

    dc.beginPath();
    // Draw arrow without curves
    dc.moveTo(p1.x, p1.y);
    dc.lineTo(p2.x, p2.y); // end of main block
    dc.lineTo(p3.x, p3.y); // topmost point
    // control point is based on p3 (topmost point)
    dc.quadraticCurveTo(p3.x + 120, p3.y, p4.x, p4.y); // endpoint 
    // control point is based on p5 (bottommost point)
    dc.quadraticCurveTo(p5.x + 120, p5.y, p5.x, p5.y); // bottommost point 
    dc.lineTo(p6.x, p6.y); // end at bottom point 
    dc.lineTo(p7.x, p7.y);
    

    Live example here: http://jsfiddle.net/Yp7DM/

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

Sidebar

Related Questions

Using OpenGL I'm attempting to draw a primitive map of my campus. Can anyone
I'm attempting to draw text to the screen using GLUT in 2d. I want
I am attempting to implement a method to draw a bunch of cubes using
I'm attempting to change RenderTargets at runtime, so I can draw some elements at
I am trying to draw a transparent plane (X[0..100],Y[0..100],Z=0) in Java 3D, but can't
I am using XNA to build a project where I can draw graffiti on
I'm attempting to draw a div over elements below the page at a specific
I am attempting to draw a star (this is my first OpenGL attempt), but
I am attempting to draw a bitmap along a rectangle, but I am not
I'm attempting to draw a graph using Cubic Hermite Splines . I grabbed the

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.