Library reference

Cosine

Multiply a sloping length by the cosine of its angle to find its horizontal reach. A 60-degree angle is about 1.0472 radians.

@cos

Simple example

Use an angle of zero radians.

Start0
Result1
lesson.zig
const std = @import("std");

pub fn main() !void {
    std.debug.print("{d}\n", .{@cos(@as(f64, 0.0))});
}
Output
1
Advertisements

Everyday examples

A four-metre awning slopes at 60 degrees. How many metres of ground does it cover horizontally?

Start1.0471975511965976
Result2.0000000000000004
lesson.zig
const std = @import("std");

pub fn main() !void {
    std.debug.print("{d}\n", .{4.0 * @cos(@as(f64, 1.0471975511965976))});
}
Output
2.0000000000000004

A camera arm is six metres long and points 60 degrees above the ground. What is its horizontal reach?

Start1.0471975511965976
Result3.000000000000001
lesson.zig
const std = @import("std");

pub fn main() !void {
    std.debug.print("{d}\n", .{6.0 * @cos(@as(f64, 1.0471975511965976))});
}
Output
3.000000000000001

A two-metre board lies flat. How far does its end reach across the floor?

Start0
Result2
lesson.zig
const std = @import("std");

pub fn main() !void {
    std.debug.print("{d}\n", .{2.0 * @cos(@as(f64, 0.0))});
}
Output
2
Run the example
Terminal
zig run lesson.zig
Official documentation