I am working on a pie chart where i have drawn arcs with known sweeping angles.Now i want to display labels in center of each Arc, or say draw a line from center of each Arc.
Given that i know center coordinates,start coordinates,sweep angle and radius,I want to Calculate the end coordinates.
I have also tried this by drawing a triangle matching all coordinates and use Distance formula also but i don't know how to solve equations in java.
Kindly provide me an appropriate solution.
You know the radius and arc length to the second point so you can calculate the angle between by s = rθ. Then you can use the fact that the arc length is proportional to the angle to calculate the angle β to your other point. Then just use polar coordinates at (100,100) to get the x and y coordinates.
Work in vectors. Let the A
be the vector from circle centre to the arc start. Calculate this by
A = start_point - centre
Let theta
be the sweep angle (work in radians). Use a rotation matrix to rotate the arc start around the circle centre. http://en.wikipedia.org/wiki/Rotation_matrix
Explicitly,
newpoint_x = cos(theta)*A_x + sin(theta)*A_y
newpoint_y = -sin(theta)*A_x + cos(theta)*A_y
where A_x
is x component of A
(and similarly for A_y
). Then
newpoint = centre + (newpoint_x,newpoint_y)
is the point you want. It may be that the point appears rotated the wrong way (anticlockwise) and if so, just use
theta = -theta
instead. This should work for you.
If you want to evaluate the mid-point of the arc, just use
theta = theta / 2
StartAngle = atan2(StartY-CenterY, StartX - CenterX)
EndX = CenterX + Radius * Cos(StartAngle + SweepAngle)
EndY = CenterY + Radius * Sin(StartAngle + SweepAngle)
Another way: Make matrix product of
shift by (Center - Start)
rotation by SweepAngle
back shift
and apply this matrix to start point (multply matrix and vector)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With