Answered by:
[WP8.1] Get new position, relative to Canvas, of a rotated Rectangle

Question
-
I am struggling to figure out how i could get the new coordinate of a rotated Rectangle that is inside a Canvas.
My goal is to detect collisions between a non rotated rectangle and a rotated rectangle.Note: The rotated rectangle is rotated around a canvas point, not its center.
I wanted to experiment with the answer from this question but IntersectWith is not available:
WPF: Collision Detection with Rotated Squares
Any other solution for collision detection would be welcome!
Thanks in advance!
- Edited by Franklin ChenMicrosoft employee Monday, October 19, 2015 8:47 AM Subject
Saturday, October 17, 2015 12:48 PM
Answers
-
Hi JPSavard,
>>I wanted to experiment with the answer from this question but IntersectWith is not available
Yes, there is no replacement API in WINRT app, there are only two ways:
1) Calculate the bound of rectangle using Transform angle and Rotating center point, this need some mathematical knowledge, like this thread
2) Using VisualTreeHelper.HitTest method the detect the overlapping area: https://msdn.microsoft.com/en-us/library/system.windows.media.visualtreehelper.hittest.aspx
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click HERE to participate the survey.- Proposed as answer by Franklin ChenMicrosoft employee Wednesday, October 28, 2015 1:51 PM
- Marked as answer by Franklin ChenMicrosoft employee Thursday, October 29, 2015 4:55 AM
Monday, October 19, 2015 9:02 AM
All replies
-
I found out how to get the coordinate of the rotated rectangle relative to the Parent Canvas, however it doesnt consider the rotation.
var transform = target.TransformToVisual(null); return transform.TransformPoint(new Point(0, 0));
- Edited by JPSavard Saturday, October 17, 2015 1:56 PM
Saturday, October 17, 2015 1:56 PM -
Hi JPSavard,
>>I wanted to experiment with the answer from this question but IntersectWith is not available
Yes, there is no replacement API in WINRT app, there are only two ways:
1) Calculate the bound of rectangle using Transform angle and Rotating center point, this need some mathematical knowledge, like this thread
2) Using VisualTreeHelper.HitTest method the detect the overlapping area: https://msdn.microsoft.com/en-us/library/system.windows.media.visualtreehelper.hittest.aspx
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click HERE to participate the survey.- Proposed as answer by Franklin ChenMicrosoft employee Wednesday, October 28, 2015 1:51 PM
- Marked as answer by Franklin ChenMicrosoft employee Thursday, October 29, 2015 4:55 AM
Monday, October 19, 2015 9:02 AM