ygoe
ygoe

Reputation: 20354

TransformBack a Point with RotateTransform

WPF has a RotateTransform class that can be applied to a DrawingContext. Any drawing operations performed with this transform in place will be rotated accordingly. I can call the RotateTransform.Transform method to explicitly rotate a single point in code. I use this transformation to freely rotate some diagram graphics.

Now, for proper mouse hit testing of the effective points, I need to reverse-rotate a given point with this RotateTransform instance. It doesn't seem to offer that though. How can this be done?

I'm looking for something like this TransformBack method, much like IValueConverter has a Convert and ConvertBack method:

var rotate = new RotateTransform(angle, centerX, centerY);
Point virtualPoint = new Point(100, 200);
Point realPoint = rotate.TransformBack(virtualPoint);   // Doesn't exist

Upvotes: 0

Views: 44

Answers (1)

Clemens
Clemens

Reputation: 128013

You could use the Inverse Transform:

var realPoint = rotate.Inverse.Transform(virtualPoint);

Upvotes: 3

Related Questions