# How to scale coordinates in CoordinateTransformations.jl

#1

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 !!!

#2

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.

#3
``````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
``````

#4

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.

#5

i guess they are happy about a PR…

#6

Probably true…

#7

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?

#8

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

``````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> 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`