# HG changeset patch # User Steve Losh # Date 1462926298 0 # Node ID 675cba1dba019bb5ebf432549f7db67719e1874e # Parent 5d8cc8199ec1883e26e07724bb44ad5882cc5d4b Coordinate utils diff -r 5d8cc8199ec1 -r 675cba1dba01 coding-math.asd --- a/coding-math.asd Tue May 10 23:59:15 2016 +0000 +++ b/coding-math.asd Wed May 11 00:24:58 2016 +0000 @@ -35,5 +35,6 @@ (:module "3d" :serial t :components ((:file "vectors") + (:file "coordinates") (:file "demo"))))))) diff -r 5d8cc8199ec1 -r 675cba1dba01 package.lisp --- a/package.lisp Tue May 10 23:59:15 2016 +0000 +++ b/package.lisp Wed May 11 00:24:58 2016 +0000 @@ -207,6 +207,18 @@ #:with-vec3 #:with-vec3s)) +(defpackage #:coding-math.3d.coordinates + (:use + #:cl + #:coding-math.math + #:coding-math.3d.vectors + #:coding-math.utils + #:coding-math.quickutils) + (:export + #:cartesian-to-cylindrical + #:cylindrical-to-cartesian + )) + (defpackage #:coding-math.3d.demo (:use #:cl @@ -216,5 +228,6 @@ #:coding-math.fps #:coding-math.math #:coding-math.3d.vectors + #:coding-math.3d.coordinates )) diff -r 5d8cc8199ec1 -r 675cba1dba01 src/3d/coordinates.lisp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/3d/coordinates.lisp Wed May 11 00:24:58 2016 +0000 @@ -0,0 +1,29 @@ +(in-package #:coding-math.3d.coordinates) + +;;; For this project, we'll define X and Y to be the typical 2D screen axes, and +;;; Z to be going into the screen (so it's a left-handed coordinate system). +;;; +;;; Cartesian coordinate vectors are: +;;; +;;; (x y z) +;;; +;;; Cylindrical coordinate vectors are: +;;; +;;; (radius azimuth height) where height is Y +;;; +;;; Polar coordinate vectors are: +;;; +;;; TODO + +(defun cylindrical-to-cartesian (coords) + (with-vec3 (radius azimuth height) coords + (make-vec3 (* radius (cos azimuth)) ; x + height ; y + (* radius (sin azimuth))))) ; z + +(defun cartesian-to-cylindrical (coords) + (with-vec3 (x y z) coords + (make-vec3 (sqrt (+ (square x) (square z))) ; r + (atan z x) ; a + y))) ; h +