Click here to Skip to main content
15,937,198 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a circle Image on center of screen. My requirement is to calculate the
end-user mouse movements along with circle towards clock wise directions then It's required to calculate it's CUMULATIVE, SPEED.

Also once the user moves the mouse along with circle in anti-clock wise directions, then no need to count. The calculation is only for clock wise directions.

As a part I finished my circle in center of screen..So any guidance or right directions will be helpful.

My codes :- Display Circle in Center of my Screen

protected void Page_Load(object sender, EventArgs e)
        SolidBrush MyBrush = new SolidBrush(System.Drawing.Color.Brown);
        Bitmap Bmp1 = new Bitmap(150, 60);
        Graphics G = Graphics.FromImage(Bmp1);
        Pen MyDrawingPen = new Pen(Color.FromArgb(75, Color.Chocolate), 15);
        Rectangle MyRect = new Rectangle(25, 9, 45, 40);
        G.DrawEllipse(MyDrawingPen, MyRect);
        G.FillEllipse(MyBrush, MyRect);
        string path = Server.MapPath("/DrawEllipse_1.jpg");
        Bmp1.Save(path, ImageFormat.Jpeg);
        Image1.ImageUrl = "/DrawEllipse_1.jpg";

Thanks Again

What I have tried:

Trying to calculate the mouse cumulative, speed rotation along with circle, but only for clock wise rotation.
Updated 9-Jun-17 2:37am

1 solution

Rather than giving you code, I will explain the concept. Writing code is more than just copying code and pasting it into your project. Understanding the concepts and writing the process of what you are attempting to accomplish helps immeasurably. (This is called a specification) You can then write the code to fit the design.

Refer to the grid below starting at point 1. The mouse will move through the remaining numbers on the grid in a clockwise direction. You should have a basic understanding of trigonometry to help identify when you are drawing a circle.
|    |    |    |    |    |    |
|    |    |    |    |    |    |
|    | Q4 |    |    | Q1 |    |
^    |    |    |    |    |    V
|    |    |    |    |    |    |
|    |    |    |    |    |    |
|    |    |    |    |    |    |
|    |    |    |    |    |    |
^    | Q3 |    |    | Q2 |    V
|    |    |    |    |    |    |
|    |    |    |    |    |    |
|    |    |    |    |    |    |
Which direction are we going?
Below is a state table for determing clockwise direction, take the differences of the current mouse x and y values and the previous x and y values. The Q1 difference should result in a positive X value and a negative Y value, and so on. Keep a history of the direction to know if the mouse continues to move in a clokwise direction.
Quadrant   CW Dir Rslt
   Q1         +X -Y
   Q2         -X -Y
   Q3         -X +Y
   Q4         +X +Y

How fast are we going?
For calculating the speed for every change in mouse coordinates(X,Y) record the time since the last coordinate change. Hint: use the timer counter as a stop watch. A slow circle will take longer...

I will leave it to you to use google to find out how to get the mouse coordinates (mousemove event) and set up and read a timer to measure the time between events.

Good Luck!
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900