On Thursday, July 30, 2015 at 6:38:11 PM UTC-7, kirby urner wrote:
>
>
>
> On Thu, Jul 30, 2015 at 6:14 PM, Leif wrote:
>
>> This still seems very verbose to me.  I think it is because the 
>> definition of "open," "opposite," and "closed" are implicit in the great 
>> big blocks of arithmetic you are doing.  I think a useful exercise would be 
>> to define edges in terms of points, and maybe faces in terms of edges and 
>> an `face?` function.  Then define different properties like `open?` in 
>> terms of functions on edges.
>>
>>
> Yes, in the ecosystem I'm coming from, edges are indeed defined by two 
> points, points being likewise vectors (in the coordinate system sense).  
>
> An Edge is defined by two Vectors e.g.  (def a (length (Edge v0 v1))).  
> For vectors, I sometimes use non-XYZ 4-tuples called Quadrays (check 
> Wikipedia).  
>
>
Since last week I've been studying defrecord and defprotocol.  

Again, I expect this is overly verbose, any feedback welcome.  

I posted a link to the Python version I'm working from at the end.

"""
(cl) K. Urner, MIT License 2015
Python -> Java -> Clojure curriculum
2D + 3D Graphics:  Martian Math
Topic:  Quadrays
http://www.grunch.net/synergetics/quadintro.html

*https://en.wikipedia.org/wiki/Quadray_coordinates*


*Asynchronous Learning Engine (Open Source project)*


*http://controlroom.blogspot.com/2015/08/asynchronous-learning-engine-ale.html*""";

(ns test-project.quadrays)

(defprotocol Ops
  (q-add [this other])
  (q-sub [this other])
  (q-len [this])
  (q-neg [this])
  (q-norm [this]))

(defrecord Quadray [OA OB OC OD]
  Ops
  (q-norm [this]
    (let [[a b c d] [(:OA this) (:OB this) (:OC this) (:OD this)]
          [x] [(min a b c d)]]
      (Quadray. (- a x) (- b x) (- c x) (- d x))))

  (q-neg [this] (q-norm (Quadray. (- 0 (:OA this))
                                  (- 0 (:OB this) )
                                  (- 0 (:OC this))
                                  (- 0 (:OD this)))))

  (q-len [this] (let [[a b c d] [(:OA this) (:OB this) (:OC this) (:OD this)]
                      [k] [(/ (+ a b c d) 4)]
                      [t0 t1 t2 t3] [(- a k) (- b k) (- c k) (- d k)]]
                  (* (Math/sqrt 2.0)
                     (Math/sqrt (+  (* t0 t0) (* t1 t1) (* t2 t2) (* t3 t3))))))

  (q-add [this other]
    (q-norm (Quadray. (+ (:OA this) (:OA other))
                      (+ (:OB this) (:OB other))
                      (+ (:OC this) (:OC other))
                      (+ (:OD this) (:OD other)))))

  (q-sub [this other] (q-add this (q-neg other))))

(def v0 (Quadray. 1 0 0 0))
(def v1 (Quadray. 0 1 0 0))
(println str (q-sub v0 v1))
(println str (q-add v0 v1))
(println str (q-neg v1))
(println str (q-len v1))


Link to Python version: 
  https://mail.python.org/pipermail/edu-sig/2015-August/011291.html

Kirby


>

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to