# CoordinateTransformations.jl usage arguments?

**URL:** <https://discourse.julialang.org/t/coordinatetransformations-jl-usage-arguments/7753>\
**Category:** New to Julia\
**Created:** [December 14, 2017, 12:30am UTC](https://discourse.julialang.org/t/coordinatetransformations-jl-usage-arguments/7753 "2017-12-14T00:30:38Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![glemieux](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/glemieux/32/212792_2.png) [@glemieux](https://discourse.julialang.org/u/glemieux)\
**Post date:** [December 14, 2017, 12:30am UTC](https://discourse.julialang.org/t/coordinatetransformations-jl-usage-arguments/7753/1 "2017-12-14T00:30:38Z")

</div>

I’m trying to transform from a `Spherical` type to an `SVector` using the `CartersianFromSpherical()` function, but I get the following error:

```julia
julia> CartesianFromSpherical(S)
ERROR: MethodError: Cannot `convert` an object of type CoordinateTransformations.Spherical{Float64} to an object of type Coo
rdinateTransformations.CartesianFromSpherical
This may have arisen from a call to the constructor CoordinateTransformations.CartesianFromSpherical(...),
since type constructors fall back to convert methods.
Stacktrace:
 [1] CoordinateTransformations.CartesianFromSpherical(::CoordinateTransformations.Spherical{Float64}) at .\sysimg.jl:24

```

I take it I’m not calling the function correctly? Paging @andyferris?

---

<div class="post-metadata">

**Author:** ![rdeits](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rdeits/32/286_2.png) [@rdeits](https://discourse.julialang.org/u/rdeits)\
**Post date:** [December 14, 2017, 12:39am UTC](https://discourse.julialang.org/t/coordinatetransformations-jl-usage-arguments/7753/2 "2017-12-14T00:39:55Z")

</div>

`CartesianFromSpherical` is a type, not a function, so you have to actually instantiate it:

```julia
julia> using CoordinateTransformations

julia> CartesianFromSpherical()(Spherical(1., 1., 1.))
3-element SVector{3,Float64}:
 0.291927
 0.454649
 0.841471

```

More typical usage would be something like:

```julia
julia> tform = CartesianFromSpherical()
CartesianFromSpherical()

julia> tform(Spherical(1., 1., 1.))
3-element SVector{3,Float64}:
 0.291927
 0.454649
 0.841471

```

---

<div class="post-metadata">

**Author:** ![glemieux](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/glemieux/32/212792_2.png) [@glemieux](https://discourse.julialang.org/u/glemieux)\
**Post date:** [December 14, 2017, 1:59am UTC](https://discourse.julialang.org/t/coordinatetransformations-jl-usage-arguments/7753/3 "2017-12-14T01:59:42Z")

</div>

Thanks @rdeits! Since I’m new to types in Julia, would you mind explaining the rationale for having the transform as a type versus a function?

---

<div class="post-metadata">

**Author:** ![rdeits](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rdeits/32/286_2.png) [@rdeits](https://discourse.julialang.org/u/rdeits)\
**Post date:** [December 14, 2017, 2:11am UTC](https://discourse.julialang.org/t/coordinatetransformations-jl-usage-arguments/7753/4 "2017-12-14T02:11:27Z")

</div>

Many transformations have parameters, like the angle of a rotation or the distance of a translation, so it makes sense to construct them like `r = RotX(0.2)` and then use `r(p)`. Transformations without parameters are just treated the same way (presumably for consistency of the API).

---

<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:** [December 15, 2017, 5:33am UTC](https://discourse.julialang.org/t/coordinatetransformations-jl-usage-arguments/7753/5 "2017-12-15T05:33:41Z")

</div>

Yeah, that’s right. Arguably one could export a `const cartesianfromspherical = CartesianFromSpherical()` function (transformation) from CoordianteTransformations, but it didn’t seem that worth it.

Also maybe worth keeping in mind that the spherical/Cartesian/cylindrical stuff was simply a prototype for myself to prove that the method (manipulations on transformations, using composition and inverse, etc) would actually work. To me the useful stuff are the Affine transformations, camera transformations, the transformations in Geodesy.jl, image transformations, and so-on.
