datavis

meow 2016-01-01T19:46:44.000955Z

@mikera: What do I need to do to get a Vec3 vector from core.matrix with (set-current-implementation :vectorz)? Or does this do the trick:

(array [1 2 3])
=> #vectorz/vector[1.0 2.0 3.0]

meow 2016-01-01T19:47:33.000956Z

The current string versions of vectors and matrices doesn't match the documentation so it gets a little confusing.

2016-01-01T19:49:40.000957Z

That's actually a dense array backed Vector. If you want the primitive Vector3 you can use mikera.vectorz.core/vec3

2016-01-01T19:53:07.000959Z

Or you van just use Java interop to instantiate a Vector3 directly... that will actually be faster as it avoids some Clojure overhead

meow 2016-01-01T20:10:19.000960Z

This is to store a whole bunch of vertices, so faster is better.

meow 2016-01-01T20:10:52.000961Z

So what would that Java interop look like?

meow 2016-01-01T20:11:18.000962Z

I guess I need to import something from vectorz?

meow 2016-01-01T20:13:52.000963Z

I have to say as someone new to matrices that my impression so far of core.matrix is that the code looks really good - well organized namespaces, docstrings on everything, readable code, etc. Very nice.

meow 2016-01-01T20:17:01.000964Z

The documentation, on the other hand, is not up-to-par. It has taken me far too long to understand the relationship between all the pieces and I don't know how to do something basic, like create a Vector3, and there is nothing to walk me from a beginner level to an intermediate level. And I think I'm reasonably intelligent and have been coding for some time now, so I don't think it's just me. And if what I say is true then you are probably losing a lot of people who might otherwise give core.matrix a shot.

meow 2016-01-01T20:17:56.000965Z

Take that as tough love from someone who does actually care about your project and wants it to succeed.

meow 2016-01-01T20:22:02.000966Z

So are these examples on the wiki no longer valid? https://github.com/mikera/vectorz-clj/wiki/Examples

meow 2016-01-01T20:22:18.000968Z

@mikera: ^

2016-01-01T20:23:32.000969Z

Hmmm example should still be valid but the underlying types might have changed, as has the string representation

meow 2016-01-01T20:23:52.000970Z

That very first example contradicts what you just told me:

(def v (array [1 2 3]))
; => #<Vector3 [1.0,2.0,3.0]>

meow 2016-01-01T20:24:44.000971Z

No offense, but, frustrating as fsck, if you don't mind me saying so. 😱

2016-01-01T20:24:48.000972Z

Yeah, you now get a Vector with length 3

2016-01-01T20:25:51.000973Z

I'll have a check through the docs and see what is useful to update. Contributions also welcome, if you find anything that can be improved.

meow 2016-01-01T20:26:21.000974Z

Using nREPL in Cursive this is what I see:

(def v (array [1 2 3]))
=> #'cad.mesh.core/v
v
=> #vectorz/vector[1.0 2.0 3.0]

meow 2016-01-01T20:27:16.000975Z

First I have to understand how to make any improvements before I can contribute. And I'd be happy to contribute, unless I give up.

2016-01-01T20:27:22.000976Z

Yeah the string representation changed to support tagged reader literals

2016-01-01T20:27:59.000977Z

It should still behave the same however, it is still a mutable length 3 vector

meow 2016-01-01T20:28:35.000978Z

But is it the magical Vector3 that is listed as a feature and that you just told me I should use Java interop to create?

meow 2016-01-01T20:29:16.000979Z

The old string rep looked that way.

meow 2016-01-01T20:30:26.000980Z

This is me taking my very first step to make use of a Vector3 in my mesh processing code. That's all I'm trying to do at this point.

meow 2016-01-01T20:31:59.000981Z

I've got:

(:require [clojure.core.matrix :refer :all]
            [clojure.core.matrix.operators :refer :all]
and (set-current-implementation :vectorz) and I can follow the examples in the REPL. That's where I'm at.

meow 2016-01-01T20:34:41.000982Z

And I'm looking at examples the have use which I never use because I thought it was not considered good practice any more and the examples don't match what I'm seeing in the REPL and they don't match in a way that is hard to ignore because I can't tell what type I'm dealing with and that's kind of the point of using core.matrix and optimizing my code. 😞

2016-01-01T20:40:25.000984Z

(class (array :vectorz [1 2 3])) => mikera.vectorz.Vector

2016-01-01T20:40:51.000985Z

(class (Vector3/of 1 2 3)) => mikera.vectorz.Vector3

2016-01-01T20:42:44.000986Z

(class (mikera.vectorz.core/vec3 1 2 3)) => mikera.vectorz.Vector3

2016-01-01T20:42:53.000987Z

It sounds like you want one of the latter two options

meow 2016-01-01T20:43:35.000988Z

Okay, how are you getting a Vector3? It isn't available in my current setup. I need another :require

2016-01-01T20:44:09.000989Z

It's a Java import, add following to your ns

2016-01-01T20:44:11.000990Z

(:import [mikera.vectorz Vector1 Vector2 Vector3 Vector4])

meow 2016-01-01T20:47:07.000992Z

Sweet. TYVM

(class (Vector3/of 1 2 3))
=> mikera.vectorz.Vector3

meow 2016-01-01T20:48:25.000993Z

This is to store the [x y z] vertices so that should work.

meow 2016-01-01T20:48:52.000994Z

:simple_smile:

meow 2016-01-01T20:50:14.000995Z

Making this change is going to break Humpty Dumpty into a bunch of pieces that I'll need to put back together. Wish me luck. 😉

2016-01-01T20:58:23.000996Z

Good luck! Excited to see the results!

meow 2016-01-01T21:01:32.000997Z

@mikera: I will definitely let you know. Working on it now.

meow 2016-01-01T21:02:27.000998Z

So it looks like all the namespaces where I'm doing matrix manipulations will need to have this added to them:

(:refer-clojure :exclude [+ - * / == min max])
  (:require [clojure.core.matrix.operators :refer :all]

meow 2016-01-01T21:05:58.000999Z

@mikera: Question for you. I need an interpolate function and seem to recall that vectorz had one but it isn't in the core.matrix api. Is that correct?

2016-01-01T21:08:08.001Z

You can use scale-add! for interpolation in the core.matrix API, it's a relatively new function

meow 2016-01-01T21:58:48.001001Z

normalise instead of normalize? Got something against American English?

meow 2016-01-01T22:00:35.001002Z

@mikera: I don't think core.matrix is the place to fight a language battle - I suggest giving in and using normalize.

meow 2016-01-01T22:01:02.001003Z

and whatever other variations are lurking in there

meow 2016-01-01T22:01:11.001004Z

colour

meow 2016-01-01T22:10:46.001005Z

All unnecessary and easily avoidable barriers to adoption should be removed.

2016-01-01T22:38:09.001006Z

core.matrix uses international / british english as standard. Not going to change :simple_smile:

meow 2016-01-01T22:39:49.001007Z

@mikera: I'm calculating the area of triangles and the old code used a magnitude of a vector with code like this: (vm/rewrite-v3 buf (Math/sqrt (mm/madd x x y y z z))))

meow 2016-01-01T22:40:31.001008Z

Is there a simple equivalent in core.matrix - with or without british spelling... 😉

meow 2016-01-01T22:44:37.001009Z

This is the untested code I've got so far for this:

(defn mag [[x y z]]
  (Math/sqrt (+ x x y y z z)))

(defn norm-sign3
  [a b c] (mag (cross (- b a) (- c a))))

(defn tri-area3
  [a b c] (* 0.5 (norm-sign3 a b c)))

2016-01-01T22:48:38.001010Z

You can use length to get the Euclidean length and cross for the cross product

meow 2016-01-01T22:48:38.001011Z

And this pulls it all together:

(defn area
  [face]
  ((if (= 3 (count face))
     (apply tri-area3 face)
     (let [cent (centroid face)]
       (reduce + (map (fn [[v1 v2]] (tri-area3 cent v1 v2))
                      (vert-pairs face)))))))

meow 2016-01-01T22:50:28.001012Z

I still need to brush up on my maths. Been a long time.

2016-01-01T22:50:58.001013Z

You can avoid using the centroid too I think, just use one of the points

meow 2016-01-01T22:51:12.001014Z

See how I said "maths" instead of "math" - so British of me. 😉

2016-01-01T22:52:25.001015Z

Though you need to be careful about signs if the face is non-convex....

meow 2016-01-01T22:52:33.001016Z

Well, the face might not be planar, so area is not going to be %100 relevant or accurate, but I don't care so I figured triangulating it with the centroid would be reasonable.

2016-01-01T22:52:42.001017Z

Ah that makes sense

meow 2016-01-01T22:53:29.001018Z

Yeah, I'm just using it as a characteristic for some of the face coloring algorithms.

meow 2016-01-01T22:54:12.001019Z

And, actually, at the point I apply it they are all triangles, but I generalize the code regardless.

meow 2016-01-01T22:54:54.001020Z

Hopefully the code I have will work and then we can clean it up later.

meow 2016-01-01T22:55:07.001021Z

The old code worked...

meow 2016-01-01T22:55:47.001022Z

I'm just trying to do the least possible to convert to core.matrix and then let you review it.

meow 2016-01-01T23:56:37.001023Z

My brain is about fried. Not sure if I can convert this to core.matrix:

(defn centroid
  [[x & xs :as coll]]
  (case (count coll)
    0 nil
    1 x
    2 (gc/mix x (first xs))
    (let [s (/ 1.0 (count coll))
          f (fn [x _] (* x s))]
      (gc/reduce-vector x + f xs))))