Minor fixes and improvements to point geom impl.

This commit is contained in:
Andrey Antukh 2016-02-06 12:25:39 +02:00
parent 6a1dad581e
commit b102c19ea7
2 changed files with 28 additions and 13 deletions

View file

@ -60,7 +60,7 @@
(Point. (+ (:x p) (:x other))
(+ (:y p) (:y other)))))
(defn substract
(defn subtract
"Returns the subtraction of the supplied value to both
coordinates of the point as a new point."
[p other]
@ -94,17 +94,32 @@
{:pre [(point? p)]}
(-> (mth/atan2 (:y p) (:x p))
(mth/degrees)))
([p other]
{:pre [(point? p)]}
(let [other (-point other)
a (/ (+ (* (:x p) (:x other))
(* (:y p) (:y other)))
(* (length p) (length other)))
a (mth/acos (if (< a -1)
-1
(if (> a 1) 1 a)))]
(-> (mth/degrees a)
(mth/precision 6)))))
([p center]
(let [center (-point center)]
(angle (subtract p center)))))
(defn angle-with-other
"Consider point as vector and calculate
the angle between two vectors."
[p other]
{:pre [(point? p)]}
(let [other (-point other)
a (/ (+ (* (:x p) (:x other))
(* (:y p) (:y other)))
(* (length p) (length other)))
a (mth/acos (if (< a -1)
-1
(if (> a 1) 1 a)))]
(-> (mth/degrees a)
(mth/precision 6))))
(defn update-angle
"Update the angle of the point."
[p angle]
(let [len (length p)
angle (mth/radians angle)]
(Point. (* (mth/cos angle) len)
(* (mth/sin angle) len))))
(defn quadrant
"Return the quadrant of the angle of the point."