旋转多边形会扭曲原始形状

时间:2015-08-11 23:21:38

标签: c# wpf rotation polygon

当我的多边形最初在与“标记”接触后被绘制时,它的绘制正确具有适当的大小和角度。但是,当我旋转它时,它会变形,例如。直角三角形变成锐角三角形。

所以我感觉我正在做的 RotateTransform 这个位有问题,但我无法弄清楚是什么。

Original triangle drawn

Rotated triangle drawn

这是我的初始化值和旋转多边形的代码:

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);
}

0 个答案:

没有答案