Reputation: 198
Using WPF I need to (touch) rotate ellipse with one finger only (one manipulator) ?
Like old phones radial dial
Any Suggestion ?
Upvotes: 0
Views: 362
Reputation: 5135
It's quite easy to do. All you need is to recall your high school geometry classes :)
ManipulationStarted
event, save your starting point in the event handler. Let's call the point S
(start).O
be the center of your ellipse. Find vector a = OS
.ManipulationDelta
handler get your the finger's location. Let's call it M
.b = OM
.var angle = Math.Abs(Math.Atan2(a.X, a.Y) - Math.Atan2(b.X, b.Y));
ipi's answer is good too, but the angle is limited by the cos^-1
function (it won't matter if you have a solid color ellipse, otherwise your object will "teleport" after reaching pi/2
).
Upvotes: 6
Reputation: 250
If you know the position of the center of the ellipse and you know the position of the finger, you can calculate the vector from the ellipse to the finger with (finger vector) - (ellipse vector)
.
Then, when the finger position updates, do the above again and store it separately. Then perform the dot product on the two vectors: A . B = |A| |B| cos(theta)
.
If A and B are unit vectors (i.e. of magnitude 1), the dot product ((A.x * B.x) + (A.y * B.y)
) will yield cos(theta)
. Perform the inverse operation and you will have your angle in radians. You can then perform your rotation.
More resources which elaborate on the dot product and vector maths are a Google search away...
Upvotes: 1