📚 The Unit Circle and Radian Measure | 单位圆与弧度制
When we think of the unit circle, we often picture a mathematical tool used to define sine and cosine. In IB Computer Science, however, the unit circle and radian measure become essential building blocks for graphics programming, game development, simulations, and any scenario that involves rotation, oscillation, or circular motion. Understanding how to translate these geometric concepts into code empowers you to create dynamic, visually engaging applications while reinforcing your computational thinking skills.
提起单位圆,我们通常会联想到数学中用于定义正弦和余弦的工具。但在 IB 计算机科学课程中,单位圆与弧度制是图形编程、游戏开发、模拟仿真以及任何涉及旋转、振荡或圆周运动场景的基本构建模块。理解如何将这些几何概念转化为代码,能让你创建出动态且具有视觉吸引力的应用程序,同时强化你的计算思维能力。
1. The Unit Circle in Computing | 计算中的单位圆
ircumference, we obtain an (x, y) pair where x = cos θ and y = sin θ. This simple mapping is the backbone of countless algorithms in 2D and 3D graphics.
单位圆是一个半径为 1、圆心位于笛卡尔平面原点 (0,0) 的圆。在计算机领域,我们很少把该圆当作纯粹的几何对象来绘制;相反,我们利用它的数学性质来计算坐标、角度和运动路径。将任意角度 θ 映射到圆周上的一个点,就能得到一个 (x, y) 坐标对,其中 x = cos θ,y = sin θ。这一简单的映射是无数二维和三维图形算法的基础。
2. Understanding Radian Measure | 理解弧度制
Radian measure provides a natural way to express angles based on the radius of a circle. One radian is the angle subtended at the centre of a circle by an arc equal in length to the radius. There are exactly 2π radians in a full circle (approximately 6.28318 rad). Because trigonometric functions in most programming languages expect arguments in radians, mastering this unit is crucial for correct calculations.
弧度制基于圆的半径,提供了一种表达角度的自然方式。1 弧度是指从圆心张开的角所对应的弧长等于半径的长度。整个圆周恰好包含 2π 弧度(约 6.28318 弧度)。由于大多数编程语言中的三角函数都期望以弧度作为输入参数,因此掌握这一单位对于确保计算正确至关重要。
3. Why Radians over Degrees? | 为何使用弧度而非角度?
Degrees feel intuitive to humans—after all, a right angle is 90° and a full turn is 360°. However, radians simplify many mathematical expressions, especially those involving derivatives, series expansions, and angular velocity. In code, using radians reduces the need for conversion factors and leads to cleaner implementations when dealing with periodic motion, physics engines, or signal processing.
角度制对人类而言很直观——毕竟直角是 90°,一整圈是 360°。但弧度制可以简化许多数学表达式,尤其是涉及导数、级数展开和角速度的公式。在代码中,使用弧度能减少转换因子的引入,使处理周期性运动、物理引擎或信号处理时的实现更为简洁。
4. Converting Between Degrees and Radians | 角度与弧度的转换
) and degrees = radians × (180 ÷ π). In practice, many programming languages provide built‑in constants such as Math.PI in JavaScript or math.pi in Python. Always perform conversions before calling trigonometric functions if your input data is in degrees.
转换公式非常简单:弧度 = 角度 × (π ÷ 180),而角度 = 弧度 × (180 ÷ π)。实践中,许多编程语言都提供了内置常量,例如 JavaScript 中的 Math.PI 或 Python 中的 math.pi。如果输入数据以角度为单位,请务必在调用三角函数之前完成转换。
Radians = Degrees × (π / 180)
Degrees = Radians × (180 / π)
5. The Unit Circle and Trigonometric Functions | 单位圆与三角函数
The tangent function, tan θ = sin θ / cos θ, can be understood as the slope of the line through the origin and that point.
在单位圆上,角 θ 的余弦值是该角的终边与圆相交点的 x 坐标,而正弦值则是 y 坐标。这种几何解释有助于程序员直观理解正弦波和余弦波的周期性特征,其值域为 -1 到 1。正切函数 tan θ = sin θ / cos θ 则可以理解为连接原点与该点的直线的斜率。
6. Programming the Unit Circle: Sine and Cosine | 编程实现单位圆:正弦与余弦
In code, retrieving the coordinates of a point on the unit circle for a given angle is as simple as calling cos(angle) and sin(angle). For instance, in Python:
在代码中,获取给定角在单位圆上的坐标只需调用 cos(angle) 和 sin(angle)。例如,在 Python 中:
import math
angle = math.pi / 4 # 45 degrees in radians
x = math.cos(angle) # approximately 0.707
y = math.sin(angle) # approximately 0.707
This snippet produces the point (√2/2, √2/2). The same approach works in Java (Math.cos()), C++ (std::cos()), and JavaScript (Math.cos()), all of which expect radian arguments.
这段代码会生成坐标点 (√2/2, √2/2)。同样的方法适用于 Java (Math.cos())、C++ (std::cos()) 和 JavaScript (Math.cos()),这些函数都以弧度作为输入参数。
7. Applying the Unit Circle in Animations and Rotations | 单位圆在动画与旋转中的应用
Rotation is fundamental to animation. To rotate a point (x, y) around the origin by an angle θ, you can use the formulas:
旋转是动画的基础。要使点 (x, y) 绕原点旋转角度 θ,可以使用以下公式:
x' = x·cos θ – y·sin θ
y' = x·sin θ + y·cos θ
These equations are derived directly from the unit circle and the angle‑sum identities. By incrementing θ each frame, you create smooth rotating objects. Game engines often implement this transformation via rotation matrices, which are built upon the same trigonometric values.
这些方程直接源自单位圆和角度和公式。通过每一帧递增 θ,就能创建平滑旋转的对象。游戏引擎通常借助旋转矩阵实现这一变换,而旋转矩阵正是基于相同的三角函数值构建的。
8. Circular Motion and Game Physics | 圆周运动与游戏物理
Circular motion appears frequently in simulations, from a planet orbiting a star to a wheel spinning on its axis. The position of an object moving with constant angular velocity ω (rad/s) can be expressed as:
圆周运动在模拟中频繁出现,从行星绕恒星运行到轮子绕轴旋转均可涉及。以恒定角速度 ω(弧度/秒)运动的物体的位置可表示为:
x(t) = r·cos(ωt + φ₀)
y(t) = r·sin(ωt + φ₀)
Here, r is the radius and φ₀ is the initial phase. Because ω is in radians per second, the product ωt naturally yields an angle in radians, making the code neat and physically meaningful.
其中 r 是半径,φ₀ 是初始相位。由于 ω 的单位是弧度/秒,乘积 ωt 自然会得到一个弧度制的角度,从而使代码简洁且具有物理意义。
9. Generating Points on a Circle | 生成圆上的点
cle, you can generate N equidistant points by iterating from i = 0 to N-1 and calculating:
图形编程中一个常见任务是绘制圆或将物体均匀放置在圆周上。借助单位圆,你可以通过从 i = 0 循环到 N-1 并计算来生成 N 个等距点:
angle = (2π × i) / N
x = centreX + radius × cos(angle)
y = centreY + radius × sin(angle)
This technique is the foundation of radar charts, circular menu interfaces, and clock‑face displays. Note that the division by N must be performed in floating‑point arithmetic to avoid integer truncation.
这一技术是雷达图、环形菜单界面和钟表显示的基础。请注意,除以 N 的运算必须采用浮点运算,以避免整数截断。
10. Radian Measure in Signal Processing | 弧度在信号处理中的应用
frequency and fₛ the sampling rate. Sine waves are generated by evaluating sin(ωn) for each sample index n. Since ω is in radians per sample, the periodicity of the sine wave directly reflects the properties of the unit circle, linking discrete‑time systems to continuous trigonometry.
在信号处理和音频编程中,弧度制体现在归一化角频率 ω = 2πf / fₛ 的概念中,其中 f 是信号频率,fₛ 是采样率。正弦波通过对每个采样索引 n 计算 sin(ωn) 来生成。由于 ω 的单位是弧度/样本,正弦波的周期性直接反映了单位圆的性质,从而将离散时间系统与连续三角学联系起来。
11. Common Pitfalls and Debugging Tips | 常见陷阱与调试技巧
- Degrees‑radians mix‑up: If an object rotates far too slowly or behaves erratically, check whether you are passing degrees to a function expecting radians. A quick sanity check: sin(π/2) should return exactly 1.
- 角度与弧度混淆:如果物体旋转过慢或行为异常,请检查是否将角度传递给了期望弧度的函数。一个快速的合理性验证:sin(π/2) 应精确返回 1。
- Floating‑point precision: After many repeated rotations, cumulative errors can distort positions. Use double‑precision types and consider resetting angles periodically.
- 浮点精度:多次重复旋转后,累积误差可能使位置失真。请使用双精度类型,并考虑定期重置角度。
- Negative radius values: Passing a negative radius to the circle formulas flips the point to the opposite side of the circle, which may be unintended. Always clamp or validate input values.
- 负半径值:向圆公式传递负半径会使点翻转到圆的另一侧,这可能并非预期行为。务必对输入值进行限制或验证。
12. Unit Circle and Radian IB Exam Insights | 单位圆与弧度的 IB 考试要点
In the IB Computer Science examination, questions may ask you to read pseudocode involving trigonometric calculations or to explain how a circular animation algorithm works. You are expected to recognise that trig functions operate in radians and to apply conversion formulas when necessary. Be prepared to sketch a unit circle to support your explanation of how coordinates are derived for a rotating sprite or a simulated clock hand.
在 IB 计算机科学考试中,题目可能会要求你阅读涉及三角函数计算的伪代码,或解释圆形动画算法的工作原理。你需要认识到三角函数以弧度为单位运行,并在必要时应用转换公式。做好准备画出单位圆,以辅助解释如何为旋转的精灵或模拟的钟表指针推导坐标。
Published by TutorHao | Computer Science Revision Series | aleveler.com
更多咨询请联系16621398022(同微信)

或截图后用「扫一扫 → 相册」选择本图