@@ -24,13 +24,13 @@ Base.show(io::IO, trans::CartesianFromPolar) = print(io, "CartesianFromPolar()")
24
24
function (:: PolarFromCartesian )(x:: AbstractVector )
25
25
length (x) == 2 || error (" Polar transform takes a 2D coordinate" )
26
26
27
- Polar (sqrt (x[1 ]* x[ 1 ] + x[ 2 ] * x[2 ]), atan (x[2 ], x[1 ]))
27
+ Polar (hypot (x[1 ], x[2 ]), atan (x[2 ], x[1 ]))
28
28
end
29
29
30
30
function transform_deriv (:: PolarFromCartesian , x:: AbstractVector )
31
31
length (x) == 2 || error (" Polar transform takes a 2D coordinate" )
32
32
33
- r = sqrt (x[1 ]* x[ 1 ] + x[ 2 ] * x[2 ])
33
+ r = hypot (x[1 ], x[2 ])
34
34
f = x[2 ] / x[1 ]
35
35
c = one (eltype (x))/ (x[1 ]* (one (eltype (x)) + f* f))
36
36
@SMatrix [ x[1 ]/ r x[2 ]/ r ;
@@ -114,14 +114,14 @@ Base.show(io::IO, trans::SphericalFromCylindrical) = print(io, "SphericalFromCyl
114
114
function (:: SphericalFromCartesian )(x:: AbstractVector )
115
115
length (x) == 3 || error (" Spherical transform takes a 3D coordinate" )
116
116
117
- Spherical (sqrt (x[1 ]* x[ 1 ] + x[2 ]* x[ 2 ] + x[3 ]* x[ 3 ] ), atan (x[2 ],x[1 ]), atan (x[3 ]/ sqrt (x[1 ]* x[ 1 ] + x[ 2 ] * x[2 ])))
117
+ Spherical (hypot (x[1 ], x[2 ], x[3 ]), atan (x[2 ], x[1 ]), atan (x[3 ], hypot (x[1 ], x[2 ])))
118
118
end
119
119
function transform_deriv (:: SphericalFromCartesian , x:: AbstractVector )
120
120
length (x) == 3 || error (" Spherical transform takes a 3D coordinate" )
121
121
T = eltype (x)
122
122
123
- r = sqrt (x[1 ]* x[ 1 ] + x[2 ]* x[ 2 ] + x[ 3 ] * x[3 ])
124
- rxy = sqrt (x[1 ]* x[ 1 ] + x[ 2 ] * x[2 ])
123
+ r = hypot (x[1 ], x[2 ], x[3 ])
124
+ rxy = hypot (x[1 ], x[2 ])
125
125
fxy = x[2 ] / x[1 ]
126
126
cxy = one (T)/ (x[1 ]* (one (T) + fxy* fxy))
127
127
f = - x[3 ]/ (rxy* r* r)
@@ -150,14 +150,14 @@ transform_deriv_params(::CartesianFromSpherical, x::Spherical) = error("Cartesia
150
150
function (:: CylindricalFromCartesian )(x:: AbstractVector )
151
151
length (x) == 3 || error (" Cylindrical transform takes a 3D coordinate" )
152
152
153
- Cylindrical (sqrt (x[1 ]* x[ 1 ] + x[2 ]* x[ 2 ] ), atan (x[2 ],x[1 ]), x[3 ])
153
+ Cylindrical (hypot (x[1 ], x[2 ]), atan (x[2 ], x[1 ]), x[3 ])
154
154
end
155
155
156
156
function transform_deriv (:: CylindricalFromCartesian , x:: AbstractVector )
157
157
length (x) == 3 || error (" Cylindrical transform takes a 3D coordinate" )
158
158
T = eltype (x)
159
159
160
- r = sqrt (x[1 ]* x[ 1 ] + x[ 2 ] * x[2 ])
160
+ r = hypot (x[1 ], x[2 ])
161
161
f = x[2 ] / x[1 ]
162
162
c = one (T)/ (x[1 ]* (one (T) + f* f))
163
163
@SMatrix [ x[1 ]/ r x[2 ]/ r zero (T) ;
0 commit comments