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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T09:23:03+00:00 2026-06-12T09:23:03+00:00

Im using the formula to calculate the distance between two points in order to

  • 0

Im using the formula to calculate the distance between two points in order to determine how much to rotate an image when I move my mouse over it.

  1. click, I capture the point where I clicked
  2. mouse moves dragging, I record the location of the point where my mouse has moved to
  3. I calculate the distance between origin and end
  4. I rotate the image using this value which starts at 1.

So lets say I click on the center of the image, I start dragging my mouse to the right, my image rotates perfectly, then without letting go the click i drag back the mouse on my image, my image is now counter rotating, which is perfect. Now once the mouse reaches that center(where I clicked initially) it forces my image rotate in the oposite directions because the distance reached its limit(0) and the new values are all positive even though im moving to the left.

I understand that the distance between two points is supposed to be positive but I need something to make negative once it comes back to (0) so that I can rotate my image properly.

  • 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-12T09:23:03+00:00Added an answer on June 12, 2026 at 9:23 am

    http://jsfiddle.net/wRexz/4/

    var dragging = false, startpoint, endpoint, midpoint = $("#center").position();
    midpoint = {x:midpoint.left - 2, y:midpoint.top-2};
    
    $("#stage").mousedown(function(e){
        dragging = true;
        startpoint = {x:e.offsetX, y:e.offsetY};
    });
    
    $("#stage").mouseup(function(e){
        dragging = false;
    });
    
    $("#stage").mousemove(function(e){
        if (dragging){
            var angle = 0, sp = startpoint, mp = midpoint;
            var p = {x:e.offsetX, y:e.offsetY};
            var sAngle = Math.atan2((sp.y-mp.y),(sp.x - mp.x));
            var pAngle = Math.atan2((p.y-mp.y),(p.x - mp.x));        
    
            angle = (pAngle - sAngle) * 180/Math.PI;
    
            $("#display").text(angle);
            $('#rotateme').css({ rotate: '+=' + angle });
    
            startpoint = {x:p.x, y:p.y};
        }
    });​
    

    This will find the relative angle of rotation between two points. It updates each time the mousemove event is fired, so it will never be more than 180 degrees in one go (except when dragging around the midpoint). Math.atan2 simplifies the logic compared to Math.atan as the latter isn’t meant for a coordinate system.

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

Sidebar

Related Questions

I am using this code to calculate the the distance between two points. I
In the program below, I am trying to calculate the distance between two points.
Distance between two points: sqrt((x1-x2)^2 + (y1-y2)^2) Is there a way to do this
I'm trying to find the distance between two points (for which I've latitudes &
I am using Bode's formuala to calculate distance of nth planet from sun dist
I'm developing an open-ended strategy game. I am using the following formula to calculate
I want to calculate average speed of the distance traveled using gps signals. Is
I want to calculate the minimum distance between a point and a bounding box
I am planning on using the following formula to calculate trending posts: Trending Score
1950 minutes is 32.5 hours. How do I calculate this using a formula in

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.