# Apply LinearTransformation to a Rectangle

**URL:** <https://discourse.julialang.org/t/apply-lineartransformation-to-a-rectangle/78926>\
**Category:** General Usage\
**Tags:** linearalgebra\
**Created:** [April 3, 2022, 12:23am UTC](https://discourse.julialang.org/t/apply-lineartransformation-to-a-rectangle/78926 "2022-04-03T00:23:55Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![vshesh](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/vshesh/32/20362_2.png) [@vshesh](https://discourse.julialang.org/u/vshesh)\
**Post date:** [April 3, 2022, 12:23am UTC](https://discourse.julialang.org/t/apply-lineartransformation-to-a-rectangle/78926/1 "2022-04-03T00:23:55Z")

</div>

I have represented a box as a 4 col x 2 row matrix

something like `bbox = [0 0 ; 50 0; 50 100; 0 100]`

I have a few of these boxes and I want to rotate them by a certain angle.  
I create a ` LinearMap(RotMatrix(deg2rad(angle)))` … now how do I use this to transform the coordinates?

```julia
bbox = 4×2 Matrix{Int64}:
 396 979
 424 979
 424 1009
 396 1009

>>> warp(bbox', LinearMap(RotMatrix(deg2rad(180))))
2×4 OffsetArray(::Matrix{Float64}, -2:-1, -4:-1) with eltype Float64 with indices -2:-1×-4:-1:
 1009.0 1009.0 979.0 979.0
  396.0 424.0 424.0 396.0

```

So it changed the shape of the matrix too?

```julia
>>> LinearMap(RotMatrix(deg2rad(180))) * bbox'
No method matching .... found .... 

```

So I also can’t treat it like a matrix and multiply it directly.

How do I do this?

---

<div class="post-metadata">

**Author:** ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)\
**Post date:** [April 3, 2022, 8:28pm UTC](https://discourse.julialang.org/t/apply-lineartransformation-to-a-rectangle/78926/2 "2022-04-03T20:28:55Z")

</div>

You could define your own rotation matrix:

```julia
rot(θ) = [cosd(θ) -sind(θ); sind(θ) cosd(θ)]

box = [0 0 ; 50 0; 50 100; 0 100]'
rbox30 = rot(30)*box

```
