This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
@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]
The current string versions of vectors and matrices doesn't match the documentation so it gets a little confusing.
That's actually a dense array backed Vector. If you want the primitive Vector3 you can use mikera.vectorz.core/vec3
Or you van just use Java interop to instantiate a Vector3 directly... that will actually be faster as it avoids some Clojure overhead
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.
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.
Take that as tough love from someone who does actually care about your project and wants it to succeed.
So are these examples on the wiki no longer valid? https://github.com/mikera/vectorz-clj/wiki/Examples
Hmmm example should still be valid but the underlying types might have changed, as has the string representation
That very first example contradicts what you just told me:
(def v (array [1 2 3]))
; => #<Vector3 [1.0,2.0,3.0]>
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.
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]
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.
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?
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.
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.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. 😞
Okay, how are you getting a Vector3? It isn't available in my current setup. I need another :require
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. 😉
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]
@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?
You can use scale-add!
for interpolation in the core.matrix API, it's a relatively new function
@mikera: I don't think core.matrix is the place to fight a language battle - I suggest giving in and using normalize
.
@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))))
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)))
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)))))))
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.
And, actually, at the point I apply it they are all triangles, but I generalize the code regardless.