On Thu, Jul 30, 2015 at 6:14 PM, Leif <leif.poor...@gmail.com> 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).

A Polyhedron is defined as a set of faces, going around clockwise or
counter, giving all the vectors to that face.  Vectors are "tail
originating" by definition i.e. their tails are all anchored at the origin.

Here's my Clojure code after some recent refactoring, minus the redundant
bits I've not changed yet.

I was 2nd powering all the six edge lengths each time inside the three
sub-functions (components of Volume) whereas really Volume should just do
that once.

That's all my let form does anymore:

(ns test-project.synmods)

(defn add-open
  [a2 b2 c2 d2 e2 f2]
  (+ (* f2 a2 b2)
     (* d2 a2 c2)
     (* a2 b2 e2)
     (* c2 b2 d2)
     (* e2 c2 a2)
     (* f2 c2 b2)
     (* e2 d2 a2)
     (* b2 d2 f2)
     (* b2 e2 f2)
     (* d2 e2 c2)
     (* a2 f2 e2)
     (* d2 f2 c2)))

(defn add-closed
  [a2 b2 c2 d2 e2 f2]
  (+ (* a2 b2 d2)(* d2 e2 f2)(* b2 c2 e2)(* a2 c2 f2)))

(defn add-opposite
   [a2 b2 c2 d2 e2 f2]
   (+ (* a2 e2 (+ a2 e2)) (* b2 f2 (+ b2 f2))(* c2 d2 (+ c2 d2))))

(defn Volume
   [edges]
   (let [[a2 b2 c2 d2 e2 f2] (map (fn [x] (* x x)) edges )]
     (Math/sqrt (*
                  (-
                    (- (add-open a2 b2 c2 d2 e2 f2)(add-closed a2 b2
c2 d2 e2 f2) )
                    (add-opposite a2 b2 c2 d2 e2 f2))
                  0.5))))

(println (format "All edges D=1, Volume: %s" (Volume [1.0 1.0 1.0 1.0
1.0 1.0]) ))

; A Module
; Fig. 986.421
; http://www.rwgrayprojects.com/synergetics/s09/figs/f86421.html

-- 
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