Last active
December 21, 2015 18:18
-
-
Save xorgy/6345925 to your computer and use it in GitHub Desktop.
Util for converting between Cartesian coordinates and spherical coordinates(with the physics symbolic convention).
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(define (xyz->ρ x y z) | |
(sqrt (+ | |
(expt x 2) | |
(expt y 2) | |
(expt z 2)))) | |
(define (zρ->θ z ρ) | |
(acos (/ z ρ))) | |
(define (yx->φ y x) | |
(atan (/ y x))) | |
(define (xyz->ρθφ x y z) | |
(define (ρ) (xyz->ρ x y z)) | |
(define (θ) (zρ->θ z (ρ))) | |
(define (φ) (yx->φ y x)) | |
(list (ρ) (θ) (φ))) | |
(define (ρθφ->x ρ θ φ) | |
(* | |
ρ | |
(sin θ) | |
(cos φ))) | |
(define (ρθφ->y ρ θ φ) | |
(* | |
ρ | |
(sin θ) | |
(sin φ))) | |
(define (ρθ->z ρ θ) | |
(* ρ (cos θ))) | |
(define (ρθφ->xyz ρ θ φ) | |
(define (x) (ρθφ->x ρ θ φ)) | |
(define (y) (ρθφ->y ρ θ φ)) | |
(define (z) (ρθ->z ρ θ)) | |
(list (x) (y) (z))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment