Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to calculate the Cordinates of end point in an Arc if center and starting coordinates are Known along with sweeping angle in Android..?

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.

like image 571
Amritpal Singh Avatar asked Nov 05 '12 12:11

Amritpal Singh


People also ask

How do you find the coordinates of an arc?

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.


2 Answers

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
like image 166
mathematician1975 Avatar answered Nov 15 '22 00:11

mathematician1975


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)

like image 30
MBo Avatar answered Nov 15 '22 00:11

MBo