summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Thompson <dthompson2@worcester.edu>2016-04-24 21:30:06 -0400
committerDavid Thompson <dthompson2@worcester.edu>2016-04-24 21:30:06 -0400
commite362e357faf60f8258ac813f917e08ffd76d5668 (patch)
treefec37761effea20f671fb332c13ad0935cea3c6e
parent987d0c3e236c26669e0a794c871bbbc9da6b3bd7 (diff)
math: vector: Add polar2 procedure.
* sly/math/vector.scm (polar2): New procedure. * doc/api/math.texi (Vectors): Document it.
-rw-r--r--doc/api/math.texi5
-rw-r--r--sly/math/vector.scm7
2 files changed, 12 insertions, 0 deletions
diff --git a/doc/api/math.texi b/doc/api/math.texi
index 9582ea7..61aa17f 100644
--- a/doc/api/math.texi
+++ b/doc/api/math.texi
@@ -60,6 +60,11 @@ Create a new 4D vector with coordinates (@var{x}, @var{y}, @var{z},
@var{w}).
@end deffn
+@deffn {Scheme Procedure} polar2 @var{r} @var{theta}
+Create a new 2D vector from the polar coordinate (@var{r},
+@var{theta}) where @var{r} is the radius and @var{theta} is the angle.
+@end deffn
+
@deffn {Scheme Syntax} vector2? @var{v}
Return @code{#t} if @code{v} is a 2D vector.
@end deffn
diff --git a/sly/math/vector.scm b/sly/math/vector.scm
index bd556ea..cc03e4e 100644
--- a/sly/math/vector.scm
+++ b/sly/math/vector.scm
@@ -31,6 +31,7 @@
<vector4>
vector2 vector3 vector4
vector2? vector3? vector4?
+ polar2
vx vy vz vw
vmap v+ v- v* vdot vcross
magnitude normalize vlerp)
@@ -79,6 +80,12 @@
(define vw vector4-w)
+(define (polar2 r theta)
+ "Create a new 2D vector from the polar coordinate (R, THETA) where R
+is the radius and THETA is the angle."
+ (vector2 (* r (cos theta))
+ (* r (sin theta))))
+
(define (vmap proc v)
"Return a new vector that is the result of applying PROC to each
element of the 2D/3D/4D vector V."