I have a box with some text in it as shown in the picture below.

An example of the rotation is shown below, where the rotation is 40 degrees.

Another example of the rotation is shown below, where the rotation is 140 degrees.

I know the start point (upper and lower point) and the end point of the text and the width/height of the margin. It does not necessarily have the same width of the margin on both sizes of the text, but I always know the width of the margin.
In the picture above the rotation angle is set to 0, and it is easy to calculate the visible area, but when it is rotated, I cannot figure out how to calculate the visibile area.
The position is based upon the code above, so as you can see, the text is always visible.
protected override void OnSizeAllocated(double width, double height)
{
var upperLeft = new Point(Content.Margin.Left + Padding.Left, Content.Margin.Top + Padding.Top);
var upperRight = upperLeft;
upperRight.X += width - Content.Margin.HorizontalThickness - Padding.HorizontalThickness;
var lowerLeft = upperLeft;
lowerLeft.Y += height - Content.Margin.VerticalThickness - Padding.VerticalThickness;
var lowerRight = upperRight;
lowerRight.Y = lowerLeft.Y;
var rotationPoint = new Point()
{
X = (lowerRight.X - upperLeft.X) * AnchorX + upperLeft.X,
Y = (lowerRight.Y - upperLeft.Y) * AnchorY + upperLeft.Y
};
RotatedUpperLeftCorner = CalculateRotatedPoint(upperLeft, rotationPoint);
RotatedUpperRightCorner = CalculateRotatedPoint(upperRight, rotationPoint);
RotatedLowerLeftCorner = CalculateRotatedPoint(lowerLeft, rotationPoint);
RotatedLowerRightCorner = CalculateRotatedPoint(lowerRight, rotationPoint);
Device.BeginInvokeOnMainThread(() =>
{
TranslationX = Math.Min(Math.Min(RotatedUpperLeftCorner.X, RotatedUpperRightCorner.X), Math.Min(RotatedLowerLeftCorner.X, RotatedLowerRightCorner.X)) * (HorizontalOptions.Alignment == LayoutAlignment.End ? 1 : -1);
TranslationY = Math.Min(Math.Min(RotatedUpperLeftCorner.Y, RotatedUpperRightCorner.Y), Math.Min(RotatedLowerLeftCorner.Y, RotatedLowerRightCorner.Y)) * (VerticalOptions.Alignment == LayoutAlignment.End ? 1 : -1);
});
}
private Point CalculateRotatedPoint(Point p, Point rotationPoint)
{
var rotation = GetRotationInRadians();
var newPointX = Math.Cos(rotation) * (p.X - rotationPoint.X) - Math.Sin(rotation) * (p.Y - rotationPoint.Y) + rotationPoint.X;
var newPointY = Math.Sin(rotation) * (p.X - rotationPoint.X) + Math.Cos(rotation) * (p.Y - rotationPoint.Y) + rotationPoint.Y;
return new Point(newPointX, newPointY);
}
But does anyone have an idea of how to calculate the visible area? The text can be in all 4 corners
rotationPoint– Lasse Madsen Jul 25 '17 at 12:49