https://kotlinlang.org logo
#android
Title
# android
n

nuhkoca

09/16/2022, 10:45 AM
Hey people, do you know how to find a distance between 2 points along the curve in circle in Canvas?
😶 4
r

Rahul Rawat

09/16/2022, 10:49 AM
n

nuhkoca

09/16/2022, 10:53 AM
We want to calculate the distance between 2 points along the path, not distance between 2 points only
👍 1
s

Sergio C.

09/16/2022, 11:17 AM
That's simply the percentage of the perimeter of the circle. Get the angle between the points and divide by the total angle in whatever units you use then multiply by the perimeter.
n

nuhkoca

09/16/2022, 12:18 PM
Thanks for the answer. We do draw a circle with partitions ( using
drawArc()
). We want to put a space in between these partitions using
PathEffect.dashEffect()
. We know the start angle and *sweep angle (*which are defined in degrees). However the ``dashEffect()`` requires us to give a distance of the partition in
pixels
. Any idea on how to achieve it? That is the reason I asked for the distance along the path of curve. So I can compute it and use it to define the gaps (spacing) in between these ARCHes of CIRCLE
s

Sergio C.

09/16/2022, 12:58 PM
If you have the sweep angle and the radius of the circle, the rest is simple maths. ArcLenght = (sweepAngle/360) * (2*Pi * radius)
🚀 1
now you need to define how many dashes you need
n

nuhkoca

09/17/2022, 9:25 AM
Awesome Sergio! The formula did the trick, appreciate your help!
👍 1
4 Views