optimisations for batch cartesian to polar?

Started by
3 comments, last by xoxos 8 years, 9 months ago

my application is checking angle and distance between many points, information for either 2d or 3d is welcome.

i'm sure many people would advise using sin and cos functions for straightforwardness in coding. i have a single core system and have a strong affectation for using optimisations, it's one of the things i enjoy most about coding.

for example a taylor series approximation may be sufficient if only a rough idea of angle is needed.

of course, if objects are in series they can be approximated with an array or oscillators (audio programmer, i use same algs for graphics)
cosappx -= w * sinappx; sinappx += w * cosappx; gives an oscillator in quadrature so can be used to draw circles/orbits/spirals.

neither a follower nor a leader behttp://www.xoxos.net
Advertisement

While not directly providing you with knowledge, I think answers to the below will help guide further replies to this post :)


i have a single core system and have a strong affectation for using optimisations, it's one of the things i enjoy most about coding.

for example a taylor series approximation may be sufficient if only a rough idea of angle is needed.

(Emphasis added)

Is only a rough idea of angle needed?

In other words, what are your current results, and what is your target? The more specific, the better.

You acknowledge that some optimizations can make your results less accurate, but potentially more performant. In the extreme ends of the spectrum, we've got A) Calculating everything with as much accuracy as is feasible and B) Returning a constant value regardless of input.

Where on that spectrum do you need to be? While there are probably tricks to maintain a specific accuracy while still increasing performance, knowing what your requirements are will help inform the choices and algorithms.

If the current accuracy is needed, have you considered profiling the amount of calls and see if you can reduce it? After all, the most performant code is the code that is never invoked!

You might just be converting a lot more than you need to do; this kind of conversion doesn't sound all to expensive to me.

On the other hand, it also sounds like you want this highly performant just because you want it to be (for the sake of enjoyment from optimazation), not because it needs to be. That's also valid, but keep in mind a lot of optimizations improve 1 or 2 of the following aspects, while decreasing the others:

1. Time to process.

2. Storage space.

3. Life-time spent on implementing.

Even in this case you'd need to decide how accurate it needs to be, while also having some sort of performance goal in mind.

Hello to all my stalkers.

all very true.

general enquiry, not task specific. i am inquiring about methods that may be fitted to yet undefined tasks. we are brothers in criteria analysis.

neither a follower nor a leader behttp://www.xoxos.net
Don't use angles and trigonometry; use vectors and linear algebra (the dot product of two directions is analogeous to measuring the angle between them, allowing you to accurately perform angle tests without using any angles or trig).

Optimize the algorithm and mathematics before you optimize the code.

hodgman, thank you -

i have noticed previously that visualisation of dot and cross ops would be a good idea (oops made myself open falstad.com to remember name), i've been using them semiconsciously for some tasks without being aware of the tolerance (i work like that). i've long neglected octave or similar and am mostly new to visual programming.

before checking that out i realised that triangulation can reduce angle computations for batches. i haven't tried tri strips yet.

neither a follower nor a leader behttp://www.xoxos.net

This topic is closed to new replies.

Advertisement