JuliaGeometry / CoordinateTransformations.jl

A fresh approach to coordinate transformations...
Other
179 stars 25 forks source link

Help: Example with spherical coordinates #47

Closed volkerkarle closed 4 years ago

volkerkarle commented 4 years ago

Hey folks, I do not quite understand the syntax. I thought the following code should work x = SVector{3,Float64}(1.0, 2.0, 0.5); SphericalFromCartesian(x) but it gives the error

MethodError: no method matching SphericalFromCartesian(::SArray{Tuple{3},Float64,1,3}) Closest candidates are: SphericalFromCartesian() at /home/obama/.julia/packages/CoordinateTransformations/IrN9A/src/coordinatesystems.jl:94 Stacktrace:

How does the syntax work?

andyferris commented 4 years ago

Oh right. So the capitalized things like SphericalFromCartesian are types. To construct a coordinate transformation you need to use a constructor, so SphericFromCartesian() for example. You can then use this object to perform transformations (most interesting transformations require some parameters to describe how the input and output coordinate systems differ). Therefore you would want:

x = SVector{3,Float64}(1.0, 2.0, 0.5)
SphericalFromCartesian()(x)