faster impl of atan2 in java...

P

Patricia Shanahan

Ken said:
that is of course if you ignore the sin and cos operation needed for
the rotation matrix to align the robots direction along the x axis, to
set up this condition!

I'm not ignoring it. In the portion you did not quote, I said
"Calculating these values involves trig, but it is only done once for
each scan request, and I think it is all simple forwards operations that
you already have cached."

In the part you quoted, I was talking about the work that has to be done
many times for each scan request, once for each robot that might be in
view. That does not contain any sine or cosine calculations.

Patricia
 
K

Ken

Ken said:
that is of course if you ignore the sin and cos operation needed for
the rotation matrix to align the robots direction along the x axis, to
set up this condition!

Of course you would be using precomputed values and so there would not
be a performance hit... however I can not see how this works here is my
issue, please tell me what I am missing:

Ahh, you translate THEN rotate... silly me, never mind.

Hmm, well isn't that a nice way to do it!

Lets see my way requires a normalization (2 multiplication, 1 addition,
1 square root, 2 divisions),
and a distance calculation (2 multiplication, 1 addition and a square
root) with a comparison.

Yours requires a matrix rotation, if the heading angle is stored as an
int, indexing into a table of precomputed sin and cos values... then
you need:
A translation (2 additions),
A rotation transformation (4 multiplication, 2 addition),
three comparisons each of which will short circuit if they fail, with
the last one requiring a multiplication. (an 'addition' may of course
be a negative number)

Such a clean solution. 5/5
 
P

Patricia Shanahan

Ken said:
Of course you would be using precomputed values and so there would not
be a performance hit... however I can not see how this works here is my
issue, please tell me what I am missing:

Ahh, you translate THEN rotate... silly me, never mind.

That's right. Alternatively, a single matrix multiply can be used, with
an extra row and column, and do both jobs in one. See, for example,
java.awt.geom.AffineTransform. However, for this case, with only one
translate and one rotate, it is more efficient to separate them.

Generally, the idea I'm pushing is to think about what coordinate system
to use for an operation. Quite often, the cost of transforming to an
appropriate system and then doing the operation is less than the cost of
doing the operation in an unsuitable system.
Such a clean solution. 5/5

Thanks

Patricia
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,777
Messages
2,569,604
Members
45,234
Latest member
SkyeWeems

Latest Threads

Top