找出圆周上像素坐标的算法

发布于 2024-07-22 05:27:21 字数 75 浏览 6 评论 0原文

如果我知道圆心、圆半径和垂直角的像素坐标,如何找出圆圆周上一定角度的像素值。 基本上,我试图在不同的时间绘制时钟的指针(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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

世态炎凉 2024-07-29 05:27:21

h 为 0 到 12 之间的浮点数形式的小时(h=2.25 为 02:15 等)。(cX,cY) 是中心的坐标。 hLengthmLength 是时针和分针的长度。

// 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);

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);
她比我温柔 2024-07-29 05:27:21

其中圆心为 (X0, Y0),半径为 R,与 x 轴的角度为 theta

X1 = (R * cos theta) + X0

Y1 = (R * sin theta) + Y0

Where the centre of the circle is (X0, Y0), the radius is R and the angle with the x-axis is theta:

X1 = (R * cos theta) + X0

and

Y1 = (R * sin theta) + Y0
尸血腥色 2024-07-29 05:27:21

如果 (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) and y1 = y + r * sin(angle)

浅忆流年 2024-07-29 05:27:21

如果中心位于左下角的 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).

白芷 2024-07-29 05:27:21

从中心到用 sin 计算的 y 坐标和 cos 计算的 x 坐标(均乘以手的长度)的坐标绘制线条。

维基百科提供了有关 sin 和 cos 如何“工作”的更多信息

Draw lines from the center to coordinates computed with sin for the y coordinates and cos for the x coordinates (both multiplied by the length of the hand).

Wikipedia has more information on how sin and cos "work".

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文