When my polygon initially gets drawn after coming in contact with a 'Tag', it's drawn fine with the appropriate size and angles. However, when I rotate it, it gets distorted for eg. a right-angled triangle becomes an acute-like triangle.
So I have a feeling something is wrong with the RotateTransform bit I'm doing but I can't figure out what.
Here is my code for initializing values and rotating a polygon:
public Tangible(Point topLeft, Point topRight, Point bottomLeft, Point bottomRight, Point centerOfTag, BlobPair taglocation, String name, Double tagAngleOffset, String colour, String shapeType)
{
TopLeft = topLeft;
TopRight = topRight;
BottomLeft = bottomLeft;
BottomRight = bottomRight;
TagLocation = taglocation;
Name = name;
CenterOfTag = centerOfTag;
TagAngleOffset = tagAngleOffset;
Colour = colour;
ShapeType = shapeType;
}
public void draw (Canvas tagCanvas)
{
shapeOutline = new Polygon();
//some other bits and pieces of code here
}
public void update(Canvas tagCanvas)
{
Double width = BottomRight.X - BottomLeft.X;
Double height = BottomLeft.Y - TopLeft.Y;
Double shapeOutlineCentreX = TopLeft.X + (width / 2.0);
Double shapeOutlineCentreY = TopLeft.Y + (height / 2.0);
Double TagCentreOffsetX = CenterOfTag.X - shapeOutlineCentreX;
Double TagCentreOffsetY = CenterOfTag.Y - shapeOutlineCentreY;
Point position = TagLocation.BigBlob.GetCenterPosition(tagCanvas);
Point otherPosition = TagLocation.SmallBlob.GetCenterPosition(tagCanvas);
Vector v = otherPosition - position;
Point centerPoint = position + v / 2;
Double trigCenterX = CenterOfTag.X - TopLeft.X;
Double trigCenterY = CenterOfTag.Y - TopLeft.Y;
**shapeOutline.RenderTransform = new RotateTransform(Math.Atan2(v.Y, v.X) * 180 / Math.PI - TagAngleOffset, trigCenterX, trigCenterY);**
shapeOutline.SetValue(Canvas.LeftProperty, centerPoint.X - (width / 2.0) - TagCentreOffsetX);
shapeOutline.SetValue(Canvas.TopProperty, centerPoint.Y - (height / 2.0) - TagCentreOffsetY);
}