In SQLite, the SIN()
function calculates the sine of an angle specified in radians.
This is a fundamental trigonometric function that returns a value between -1 and 1, representing the ratio of the opposite side to the hypotenuse in a right triangle.
Syntax
SIN(angle_in_radians)
Where angle_in_radians
is a numeric expression representing an angle in radians. Note that if your angle is in degrees, you’ll need to convert it to radians first. The RADIANS()
function provides an easy way to do this.
Example 1
Here’s a simple example to demonstrate:
SELECT SIN(1.3);
Output:
+-------------------+
| SIN(1.3) |
+-------------------+
| 0.963558185417193 |
+-------------------+
Here are some other examples to remember:
SELECT
SIN(0),
SIN(PI()/2),
SIN(3 * PI()/2);
Output:
+--------+-------------+-----------------+
| SIN(0) | SIN(PI()/2) | SIN(3 * PI()/2) |
+--------+-------------+-----------------+
| 0.0 | 1.0 | -1.0 |
+--------+-------------+-----------------+
Example 2
Here’s a practical example that demonstrates the SIN()
function with various common angles:
-- Create a table with common angles in degrees
CREATE TABLE angles (
angle_id INTEGER PRIMARY KEY,
angle_degrees FLOAT
);
-- Insert common angles
INSERT INTO angles (angle_degrees) VALUES
(0), -- sin = 0
(30), -- sin = 0.5
(45), -- sin ≈ 0.707
(90), -- sin = 1
(180), -- sin = 0
(270); -- sin = -1
-- Calculate sine values
-- Note: We must convert degrees to radians first
SELECT
angle_degrees,
ROUND(SIN(RADIANS(angle_degrees)), 6) as sine_value
FROM angles;
Output:
+---------------+------------+
| angle_degrees | sine_value |
+---------------+------------+
| 0.0 | 0.0 |
| 30.0 | 0.5 |
| 45.0 | 0.707107 |
| 90.0 | 1.0 |
| 180.0 | 0.0 |
| 270.0 | -1.0 |
+---------------+------------+
Notice that we converted the values to radians first using the RADIANS()
function. That’s because the values in the database were in degrees, but the SIN()
function requires its argument to be in radians.
We also used the ROUND()
function to round the results to six decimal places.
Common Use Cases
The SIN()
function is often used in:
- Trigonometric calculations
- Wave pattern analysis
- Periodic data modeling
- Game development (calculating trajectories)
- Scientific computations
Things to Remember
- Always ensure your input is in radians. If working with degrees, use
RADIANS()
to convert - The return value is always between -1 and 1
- You can use
ROUND()
to control decimal places