Reputation: 1002
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.
Upvotes: 5
Views: 6589
Reputation: 21351
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
Upvotes: 6
Reputation: 80327
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)
Upvotes: 1