找出圆周上像素坐标的算法
如果我知道圆心、圆半径和垂直角的像素坐标,如何找出圆圆周上一定角度的像素值。 基本上,我试图在不同的时间绘制时钟的指针(1点、2点等)
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 )
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
令
h
为 0 到 12 之间的浮点数形式的小时(h=2.25
为 02:15 等)。(cX,cY)
是中心的坐标。hLength
和mLength
是时针和分针的长度。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
andmLength
are the lengths of the hour and min hands.其中圆心为
(X0, Y0)
,半径为R
,与 x 轴的角度为 theta:
Where the centre of the circle is
(X0, Y0)
, the radius isR
and the angle with the x-axis is theta:and
如果 (x1,y1) 是圆周上的点且 (x,y) 是圆心,则
x1 = x + r * cos(angle)
且y1 = y + r *正弦(角度)
If (x1,y1) is a point on the circumference and (x,y) is the center, then
x1 = x + r * cos(angle)
andy1 = y + r * sin(angle)
如果中心位于左下角的 x0、y0 和 0,0 iz,则 1 点位于 x0 + rsin(2π/3), y0+rcos(2π/ 3)。
if center is at x0, y0, and 0,0 iz at bottom-left corner, then 1 o'clock is at x0 + rsin(2π/3), y0+rcos(2π/3).
从中心到用
sin
计算的 y 坐标和cos
计算的 x 坐标(均乘以手的长度)的坐标绘制线条。维基百科提供了有关 sin 和 cos 如何“工作”的更多信息。
Draw lines from the center to coordinates computed with
sin
for the y coordinates andcos
for the x coordinates (both multiplied by the length of the hand).Wikipedia has more information on how sin and cos "work".