简体   繁体   中英

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.

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM