davideberly / GeometricTools

A collection of source code for computing in the fields of mathematics, geometry, graphics, image analysis and physics.
Boost Software License 1.0
1.14k stars 214 forks source link

distArc2Point2 #47

Closed owai1980 closed 1 year ago

owai1980 commented 1 year ago

Hello

This is more a "feature request" ... I need a function to calculate the distance from a 2D point to a Arc2 ... I can easily get the distance from the point to the full circle... but for an Arc2 it's more difficult :-)

can you help or give clue?

thank you ... again!

Johan

davideberly commented 1 year ago

I will add an implementation of distance(point2,arc2). I should have the time in a couple of days. For an arc subtending an acute angle, you need only determine whether the incoming point is in the 2D wedge defined by the circle center and the arc. If so, you compute the distance to the circle (this is a Voronoi argument). Otherwise, the point is outside the wedge and you compute distance to the appropriate arc endpoint. For an arc subtending an obtuse angle, I believe the same idea works, but I need to think about it.

owai1980 commented 1 year ago

You are right, your idea sounds good! 👍 👍

I'll be happy to test your work!

Thank you.. Again!

Le ven. 18 nov. 2022 à 20:02, David Eberly @.***> a écrit :

I will add an implementation of distance(point2,arc2). I should have the time in a couple of days. For an arc subtending an acute angle, you need only determine whether the incoming point is in the 2D wedge defined by the circle center and the arc. If so, you compute the distance to the circle (this is a Voronoi argument). Otherwise, the point is outside the wedge and you compute distance to the appropriate arc endpoint. For an arc subtending an obtuse angle, I believe the same idea works, but I need to think about it.

— Reply to this email directly, view it on GitHub https://github.com/davideberly/GeometricTools/issues/47#issuecomment-1320416889, or unsubscribe https://github.com/notifications/unsubscribe-auth/AG3BAQJ6MJ5LWPEP3STQI7DWI7HDPANCNFSM6AAAAAASBAYFZU . You are receiving this because you authored the thread.Message ID: @.***>

davideberly commented 1 year ago

I posted the 2D distance queries for point-circle and point-arc. The file names are DistPoint2Circle2.h and DistPoint2Arc2.h. I have unit tested these, but if you discover any problems with the code, please let me know.

owai1980 commented 1 year ago

Wow thank you so much! I will check this tomorrow morning!

👍

Le jeu. 1 déc. 2022 à 18:56, David Eberly @.***> a écrit :

I posted the 2D distance queries for point-circle and point-arc. The file names are DistPoint2Circle2.h and DistPoint2Arc2.h. I have unit tested these, but if you discover any problems with the code, please let me know.

— Reply to this email directly, view it on GitHub https://github.com/davideberly/GeometricTools/issues/47#issuecomment-1334140469, or unsubscribe https://github.com/notifications/unsubscribe-auth/AG3BAQLDMMY33I726HJZCBLWLDRFBANCNFSM6AAAAAASBAYFZU . You are receiving this because you authored the thread.Message ID: @.***>

owai1980 commented 1 year ago

I just read your code... Looks prefect!

Just a little idea... In the distarc2point2 : You wrote this

               T length0 = std::sqrt(sqrLength0);
                T length1 = std::sqrt(sqrLength1);
                if (length0 <= length1)
                       ... 

I think (but I might be wrong) at we can compare the squared length in the if(), and compute only ONE OF the sqrt inside the if... Else... So we avoid one "sqrt" call.

Right?

Thank you again for your great work! 👍

Johan

davideberly commented 1 year ago

Modified and uploaded. Thanks.