Sign In|Join
Home/Silverlight.NET Forums/Programming with .NET - General/Capture Mouse Moving Direction/Re: Re: Capture Mouse Moving Direction
Member
110 Points
110 Posts
Oct 15, 2007 02:22 PM | LINK
Hi yaseer and all,
Thanks yaseer for your reply with explanation.
Please can you convert or give me code in C#.Net?
Actually i am rotation Line Object.
I can rotate my line on both direction but line is not rotating properly when my mouse rotates.
My Code is:
Point actPos = e.GetPosition(MyCanvas);
if (oActiveLine != null && sElementName == "Line") { //Fidning the angle using Triangle theorem. double a, b, c; X.X = oActiveLine.Left; X.Y = oActiveLine.Top; Y.X = structStartPosition.X; Y.Y = structStartPosition.Y; Z.X = actPos.X; Z.Y = actPos.Y; b = System.Math.Sqrt(((Y.X - oActiveLine.Left) * (Y.X - oActiveLine.Left)) + ((Y.Y - oActiveLine.Top) * (Y.Y - oActiveLine.Top))); oActiveLine.Height = System.Math.Sqrt(((actPos.X - oActiveLine.Left) * (actPos.X - oActiveLine.Left)) + ((actPos.Y - oActiveLine.Top) * (actPos.Y - oActiveLine.Top))); a = System.Math.Sqrt(((Y.X - Z.X) * (Y.X - Z.X)) + ((Y.Y - Z.Y) * (Y.Y - Z.Y))); c = System.Math.Sqrt(((X.X - actPos.X) * (X.X - actPos.X)) + ((X.Y - actPos.Y) * (X.Y - actPos.Y))); double angle = System.Math.Acos((b * b + c * c - a * a) / (2 * b * c)) * (180.0 / System.Math.PI); if (((Z.Y < X.Y) && (Z.X < Y.X)) || ((Z.Y > X.Y) && (Z.X > Y.X))) oActiveLine.Angle -= angle; if (((Z.Y < X.Y) && (Z.X > Y.X)) || ((Z.Y > X.Y) && (Z.X < Y.X))) oActiveLine.Angle += angle; angle = 0.0; a = b = c = 0; } structStartPosition = actPos;
nirav5884
Member
110 Points
110 Posts
Re: Re: Capture Mouse Moving Direction
Oct 15, 2007 02:22 PM | LINK
Hi yaseer and all,
Thanks yaseer for your reply with explanation.
Please can you convert or give me code in C#.Net?
Actually i am rotation Line Object.
I can rotate my line on both direction but line is not rotating properly when my mouse rotates.
My Code is:
Point actPos = e.GetPosition(MyCanvas);
if (oActiveLine != null && sElementName == "Line")
{
//Fidning the angle using Triangle theorem.
double a, b, c;
X.X = oActiveLine.Left;
X.Y = oActiveLine.Top;
Y.X = structStartPosition.X;
Y.Y = structStartPosition.Y;
Z.X = actPos.X;
Z.Y = actPos.Y;
b = System.Math.Sqrt(((Y.X - oActiveLine.Left) * (Y.X - oActiveLine.Left)) + ((Y.Y - oActiveLine.Top) * (Y.Y - oActiveLine.Top)));
oActiveLine.Height = System.Math.Sqrt(((actPos.X - oActiveLine.Left) * (actPos.X - oActiveLine.Left)) + ((actPos.Y - oActiveLine.Top) * (actPos.Y - oActiveLine.Top)));
a = System.Math.Sqrt(((Y.X - Z.X) * (Y.X - Z.X)) + ((Y.Y - Z.Y) * (Y.Y - Z.Y)));
c = System.Math.Sqrt(((X.X - actPos.X) * (X.X - actPos.X)) + ((X.Y - actPos.Y) * (X.Y - actPos.Y)));
double angle = System.Math.Acos((b * b + c * c - a * a) / (2 * b * c)) * (180.0 / System.Math.PI);
if (((Z.Y < X.Y) && (Z.X < Y.X)) || ((Z.Y > X.Y) && (Z.X > Y.X)))
oActiveLine.Angle -= angle;
if (((Z.Y < X.Y) && (Z.X > Y.X)) || ((Z.Y > X.Y) && (Z.X < Y.X)))
oActiveLine.Angle += angle;
angle = 0.0;
a = b = c = 0;
}
structStartPosition = actPos;