# How to scale coordinates in CoordinateTransformations.jl

**URL:** https://discourse.julialang.org/t/how-to-scale-coordinates-in-coordinatetransformations-jl/4394
**Category:** General Usage
**Tags:** question
**Created:** [June 21, 2017, 7:30pm UTC](https://discourse.julialang.org/t/how-to-scale-coordinates-in-coordinatetransformations-jl/4394 "2017-06-21T19:30:32Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![yakir12](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yakir12/32/297_2.png) [@yakir12](https://discourse.julialang.org/u/yakir12)
#### Post date: [June 21, 2017, 7:30pm UTC](https://discourse.julialang.org/t/how-to-scale-coordinates-in-coordinatetransformations-jl/4394/1 "2017-06-21T19:30:32Z")

</div>

How do I scale coordinates in `CoordinateTransformations.jl`? They mention `UniformScaling`, but I don’t understand how I’m supposed to use that in order to differently scale each dimension in my coordinates.  
Say I have a coordinate at `[6, 3, 1]`, and I need to scale it by `[1, 2, 6]` so that after applying the transformation the new coordinate would be `[6, 6, 6]`. How do I accomplish that using the transformations in `CoordinateTransformations.jl` (or `UniformScaling`)?

Thanks @andyferris !!!

---

<div class="post-metadata">

### Author: ![lobingera](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lobingera/32/211_2.png) [@lobingera](https://discourse.julialang.org/u/lobingera)
#### Post date: [June 21, 2017, 7:45pm UTC](https://discourse.julialang.org/t/how-to-scale-coordinates-in-coordinatetransformations-jl/4394/2 "2017-06-21T19:45:53Z")

</div>

just by looking at their readme and with a small background in linear transformation, i’d guess you put your scaling factors on the main diag of a square matrix:

> if you know the dimensionality of your points (e.g. 2D or 3D) you might consider a statically sized matrix like SMatrix from StaticArrays.jl.

---

<div class="post-metadata">

### Author: ![Evizero](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/evizero/32/10118_2.png) [@Evizero](https://discourse.julialang.org/u/Evizero)
#### Post date: [June 21, 2017, 7:47pm UTC](https://discourse.julialang.org/t/how-to-scale-coordinates-in-coordinatetransformations-jl/4394/3 "2017-06-21T19:47:58Z")

</div>

```julia
julia> using CoordinateTransformations, StaticArrays

julia> scaletfm(x,y,z) = LinearMap(@SMatrix([x 0. 0.; 0. y 0.; 0. 0. z]))
scaletfm (generic function with 1 method)

julia> tfm = scaletfm(1,2,6)
LinearMap([1.0 0.0 0.0; 0.0 2.0 0.0; 0.0 0.0 6.0])

julia> tfm([6,3,1])
3-element StaticArrays.SVector{3,Float64}:
 6.0
 6.0
 6.0

```

---

<div class="post-metadata">

### Author: ![yakir12](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yakir12/32/297_2.png) [@yakir12](https://discourse.julialang.org/u/yakir12)
#### Post date: [June 21, 2017, 7:50pm UTC](https://discourse.julialang.org/t/how-to-scale-coordinates-in-coordinatetransformations-jl/4394/4 "2017-06-21T19:50:09Z")

</div>

Thanks!  
While this is pretty straight forward, it seems a bit odd to include a native type for Translation (which surely is a simple transformation), but not one for scaling.

---

<div class="post-metadata">

### Author: ![lobingera](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lobingera/32/211_2.png) [@lobingera](https://discourse.julialang.org/u/lobingera)
#### Post date: [June 21, 2017, 8:04pm UTC](https://discourse.julialang.org/t/how-to-scale-coordinates-in-coordinatetransformations-jl/4394/5 "2017-06-21T20:04:46Z")

</div>

i guess they are happy about a PR…

---

<div class="post-metadata">

### Author: ![yakir12](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yakir12/32/297_2.png) [@yakir12](https://discourse.julialang.org/u/yakir12)
#### Post date: [June 21, 2017, 8:06pm UTC](https://discourse.julialang.org/t/how-to-scale-coordinates-in-coordinatetransformations-jl/4394/6 "2017-06-21T20:06:44Z")

</div>

Probably true…

---

<div class="post-metadata">

### Author: ![andyferris](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/andyferris/32/235_2.png) [@andyferris](https://discourse.julialang.org/u/andyferris)
#### Post date: [June 22, 2017, 1:00am UTC](https://discourse.julialang.org/t/how-to-scale-coordinates-in-coordinatetransformations-jl/4394/7 "2017-06-22T01:00:56Z")

</div>

Sorry - I am at JuliaCon right now, but the short answer is that the efficient way should be: `LinearMap(Diagonal(SVector(a,b,c)))`.

To me this makes sense as a scaling - perhaps some documentation improvements are necessary however?

---

<div class="post-metadata">

### Author: ![yakir12](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yakir12/32/297_2.png) [@yakir12](https://discourse.julialang.org/u/yakir12)
#### Post date: [June 22, 2017, 10:06am UTC](https://discourse.julialang.org/t/how-to-scale-coordinates-in-coordinatetransformations-jl/4394/8 "2017-06-22T10:06:54Z")

</div>

Hmm, `LinearMap(Diagonal(SVector(a,b,c)))` doesn’t seem to maintain the type of the diagonal vector:

```julia
m = LinearMap(Diagonal(SVector(1, 2, 3)))
LinearMap([1 0 0; 0 2 0; 0 0 3])

julia> typeof(m.m)
Diagonal{Int64}

```

As opposed to the (desired) following:

```julia
julia> m = LinearMap(@SMatrix([1 0 0; 0 2 0; 0 0 3]))
LinearMap([1 0 0; 0 2 0; 0 0 3])

julia> typeof(m.m)
StaticArrays.SArray{Tuple{3,3},Int64,2,9}

```

I suspect this has more to do with `StaticArrays.jl` and `Diagonal` than with `CoordinateTransformations.jl`…
