|
|
William F Pokorny <ano### [at] anonymousorg> wrote:
> On 5/6/21 10:58 AM, Tor Olav Kristensen wrote:
> >...
>...
> > Anyway the way that macro calculates the angle is not the best numerically.
> > I would rather suggest something like this:
> >
> >
> > #macro AngleBetweenVectors(v1, v2)
> >
> > #local v1n = vnormalize(v1);
> > #local v2n = vnormalize(v2);
> >
> > (2*atan2(vlength(v1n - v2n), vlength(v1n + v2n)))
> >
> > #end // macro AngleBetweenVectors
> >
>
> Interesting, thanks. I'll play with it. There will be four sqrt calls
> with this vs two so I expect it's a slower approach.
I prefer better accuracy before speed. If we need this to go faster we could
compile it into POV-Ray and make it a new command; e.g. vangle().
> Reminds me I captured fast approximation atan2 code I was thinking of
> making an inbuilt function, but I've not gotten to it...
>
> And that thought reminds me of my plans to turn many macros into
> "munctions"(1) calling new faster, inbuilt functions. Done only a tiny
> bit of that so far.
>
> (1) - Yes, thinking about creating a munctions.inc file breaking out
> what are really macro wrappers to functions into that file to make clear
> what they are. Maybe all as M_ prefixed so my current F_dents() would
> become M_dents(). Angle perhaps then M_Angle.
This sounds interesting. Can you please explain more ?
Are there any benefits from using these instead of new built in commands ?
> Something I've done too with the inbuilt function changes is allow
> alternative calculations for the same thing. Compiled such conditionals
> not that expensive. Most frequently single float options where those are
> much faster, but different methods too. For one thing, the alternatives
> I can bang against each other as a way to test!
Are you using this functionality to perform speed tests ?
--
Tor Olav
http://subcube.com
https://github.com/t-o-k
Post a reply to this message
|
|