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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T21:35:36+00:00 2026-06-16T21:35:36+00:00

I try to draw a rotated line and after rotating to draw a point

  • 0

I try to draw a rotated line and after rotating to draw a point on the start and end of the line.

This is my code (doesn’t work correctly)

<!-- language: lang-html -->
<html><head><title>test</title></head><body>

    <canvas id="canvas" width="100" height="100"></canvas>

    <script type="text/javascript">

        var _context = document.getElementById("canvas").getContext('2d');

        var x = 40;
        var y = 40;
        var angle = 0.2;

        _context.beginPath();
        _context.translate( x, y);

        //rotate and draw line
        _context.rotate( angle );
        _context.moveTo( 0, 0);
        _context.lineTo( 0, 40);
        _context.stroke();

        //calculate the new x,y position from line
        x = x * Math.cos( angle ) - y * Math.sin( angle );
        y = x * Math.sin( angle ) + y * Math.cos( angle );

        //draw a point to this coords
        _context.save();
        _context.fillStyle = "orange";
        _context.beginPath();
        _context.arc( x, y, 4, 0, 2*Math.PI, true);
        _context.fill();

    </script>
</body></html>

jsFiddle Demo : http://jsfiddle.net/UT29j/

Has someone an idea?

  • 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-16T21:35:37+00:00Added an answer on June 16, 2026 at 9:35 pm

    Rotation and translation apply to everything drawn. You do not need to manipulate the coordinates yourself.

    <html><head><title>test</title></head><body>
    
        <canvas id="canvas" width="100" height="100"></canvas>
    
        <script type="text/javascript">
    
            var _context = document.getElementById("canvas").getContext('2d');
    
            var angle = 0.2;
    
            // rotate and translate
            _context.translate(40, 40);
            _context.rotate( angle );
    
            // draw line
            _context.beginPath();
            _context.moveTo( 0, 0);
            _context.lineTo( 0, 40);
            _context.stroke();
    
            //draw a point to this coords
            _context.save();
            _context.fillStyle = "orange";
            _context.beginPath();
            _context.arc(0, 40, 4, 0, 2*Math.PI, true);
            _context.arc(0, 0, 4, 0, 2*Math.PI, true);
            _context.fill();
        </script>
    </body></html>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I try to draw some lines with different colors. This code tries to draw
in this code i'm try to draw simple olympic ring and rotate it... the
i try to draw arc in view i use this code. - (void)viewDidLoad {
In this code I try to draw a cube.I try to draw all faces
I'am trying to draw a line above mapkit. If I try to set the
Try this code - import java.io.StringReader; public class StringReaderTest { public static void main(String[]
Try this piece of code - public class WhitespaceTest { public static void main(String[]
I try to draw a line with the width depending on the density. The
This time I try to draw a table like this: +-----+-----+-----+-----+ | | |
I try to draw a string in this texture: http://picasaweb.google.it/lh/photo/LkYWBv_S_9v2d6BAfbrhag?feat=directlink but the green numbers

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.