Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

algorithm for finding out pixel coordinates on a circumference of a circle

how do i find out pixel value at certain degree on the circumference of a circle if I know the pixel co-ordinates of the center of the circle, radius of the circle ,and perpendicular angle. Basically, I am trying to draw the hands of a clock at various times ( 1 o clock , 2 o clock etc )

like image 764
Surya Avatar asked May 29 '09 09:05

Surya


People also ask

How do you find the coordinates of a point on the circumference of a circle?

From trigonometry, we know that θ1 is related by y1 by the sine function, i.e. sinθ1=y1r, where r is the radius. Thus, we can solve for θ1 and then find θ2. From there we can use the cosine function to find x2 and the sine function to find y2. Save this answer.

How do you calculate pixel circle?

Since 2Pi*R = circumference, the running length of diameter of the circle, this is the total amount of pixels you have. Now simply write R = 2000/2*Pi and this will give you the radius. Now you should be able to draw a circle the comprised of 2000 pixels.

How do you write an algorithm for the area of a circle?

The circle area is computed using 3.14 * radius * radius.

How do you find the exact coordinates of a circle?

Use the Distance Formula to find the equation of the circle. Substitute (x1,y1)=(h,k),(x2,y2)=(x,y) and d=r . Square each side. The equation of a circle with center (h,k) and radius r units is (x−h)2+(y−k)2=r2 .


1 Answers

Let h be the hour as a floating point number (h=2.25 would be 02:15, etc.) between 0 and 12. (cX,cY) are the coordinates of the center. hLength and mLength are the lengths of the hour and min hands.

// Hour hand
hAngle = 2.0*Pi*h/12.0; // 0..12 mapped to 0..2*Pi
hX = cX + hLength * sin(hAngle);
hY = cY - hLength * cos(hAngle);

// Min hand
mAngle = 2.0*Pi*h; // 0..1 mapped to 0..2*Pi, etc.
mX = cX + mLength * sin(mAngle);
mY = cY - mLength * cos(mAngle);
like image 181
Eric Bainville Avatar answered Oct 05 '22 00:10

Eric Bainville