# Need help for image drawing procedure. Incorrect Vector.Rotate transform

**URL:** <https://forums.fusetools.com/t/need-help-for-image-drawing-procedure-incorrect-vector-rotate-transform/2210>\
**Category:** How-to Discussions\
**Created:** [August 24, 2016, 1:40am UTC](https://forums.fusetools.com/t/need-help-for-image-drawing-procedure-incorrect-vector-rotate-transform/2210 "2016-08-24T01:40:20Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Max\_Graey](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/max_graey/32/347_2.png) [@Max\_Graey](https://forums.fusetools.com/u/Max_Graey)\
**Post date:** [August 24, 2016, 1:40am UTC](https://forums.fusetools.com/t/need-help-for-image-drawing-procedure-incorrect-vector-rotate-transform/2210/1 "2016-08-24T01:40:20Z")

</div>

I’m trying to extend some features of standard `<Image>` element and reimplement OnDraw method. I found SizingContainer on the forum and it has really simplified life. So, my goal is to make transform of texture coordinates possible. At this stage, I simply rotated the tex coordinates by 45 degrees around center but something wrong.

\*\*\* Code \*\*\*

```auto
protected void Draw(DrawContext dc, float2 pos, float2 size, float2 uvPosition, float2 uvSize, texture2D tex) {
    float2 offset = float2(this.LocalTransform.M41 - this.WorldTransform.M41,
                           this.LocalTransform.M42 - this.WorldTransform.M42) / size;

    draw {
        apply Fuse.Drawing.Planar.Rectangle;
        DrawContext: dc;
        Visual: this;
        Position: pos;
        Size: size;
        TexCoord: Vector.Rotate((VertexData.XY - 0.5f), Math.DegreesToRadians(45f)) * uvSize + uvPosition + 0.5f * uvSize;
        ClipPosition: float4(VertexData.X + offset.X, 1f - VertexData.Y + offset.Y, 0f, 1f);
        PixelColor: sample(tex, TexCoord);
    };
}

```

\*\*\* Result \*\*\*

![Screenshot](https://dl.dropboxusercontent.com/u/33221668/screen.png)

Why image skewed after transform?

PS It seems height of “size” or “uvSize” compute not perfectly. Dimention along y-axis slightly stretched compared to the original

---

<div class="post-metadata">

**Author:** ![Anders\_Lassen](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/anders_lassen/32/522_2.png) [@Anders\_Lassen](https://forums.fusetools.com/u/Anders_Lassen)\
**Post date:** [August 24, 2016, 4:20am UTC](https://forums.fusetools.com/t/need-help-for-image-drawing-procedure-incorrect-vector-rotate-transform/2210/2 "2016-08-24T04:20:33Z")

</div>

Hi,

Simply rotating the texture coordinates will not guarantee a uniform stretch. For this to work you have to work out the math to get it to take the aspect (`size.X/size.Y`) of the rectangle into account. Divide out the aspect, do rotation in linear space, then factor aspect back in.

---

<div class="post-metadata">

**Author:** ![Max\_Graey](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/max_graey/32/347_2.png) [@Max\_Graey](https://forums.fusetools.com/u/Max_Graey)\
**Post date:** [August 24, 2016, 5:03am UTC](https://forums.fusetools.com/t/need-help-for-image-drawing-procedure-incorrect-vector-rotate-transform/2210/3 "2016-08-24T05:03:44Z")

</div>

Thanks Anders, it’s work!
