---
title: "sin: 셰이더 함수 뜻과 사용법, 계산 예제와 입력 범위 및 주의점 | TypeShade"
description: "사인은 라디안 단위의 각도에 대응하는 단위원 위의 세로 좌표입니다. 같은 파형이 반복되므로 부드러운 진동을 표현합니다. 파도, 반복 운동, 주기적인 무늬를 표현하는 데 사용합니다. 입력 단위는 라디안입니다."
url: https://typeshade.dev/ko/reference/functions/sin/
language: ko
---

# `sin`

함수

사인은 라디안 단위의 각도에 대응하는 단위원 위의 세로 좌표입니다. 같은 파형이 반복되므로 부드러운 진동을 표현합니다.

## 함수 그래프

`y = sin(x)`

![sin 그래프입니다. 곡선이 출력을 나타내며, 강조된 점은 선택한 입력을 따라 움직입니다.](https://typeshade.dev/stills/reference-function-sin.webp)

`y` = 1.25 `y` = -1.25 `x` = -6.28 `x` = 6.28

파란 곡선은 출력이고, 주황색 점은 선택한 입력의 위치입니다.

휠로 확대·축소하고 드래그로 이동한다. 3D에서는 드래그로 회전한다. 키보드: 방향키, +/-, Home으로 초기화.

축 옆에 표시한 범위만 그립니다. 이 범위 밖의 값은 화면에 나타나지 않습니다.

입력 변화 관찰

- x가 영점을 지날 때는 곡선의 기울기가 가파르고, 꼭대기에서는 평평해집니다.

**전체 셰이더 코드**

[Playground에서 열기](https://typeshade.dev/ko/playground/)

sin-plot.shade.ts

```ts
"use typeshade";

import { PlotUniforms, plot2D, plot3D } from "./function-plot.shade.ts";

class Uniforms extends PlotUniforms {}
declare const u: uniform<Uniforms>;

// Inputs outside the mathematical domain are omitted, including after pan or zoom.
function sample(x: f32): f32 {

  return sin(x);
}

function trajectory(t: f32): vec3 {
  return vec3(t, sample(t), 0.);
}

@fragment
export function main(uv: location<0, vec2>): vec4 {
  const flat = plot2D(sample, uv, u, false);
  if (u.plotBlend <= 0.) { return flat; }
  const space = plot3D(trajectory, uv, u, false);
  return mix(flat, space, clamp(u.plotBlend, 0., 1.));
}
```

페이지가 매 프레임 채우는 값이라 컨트롤이 없습니다: `resolution`, `plotCenter`, `plotSpan`, `plotRotation`, `plotBlend`.

## 활용

파도, 반복 운동, 주기적인 무늬를 표현하는 데 사용합니다.

계산 예제: `sin(1.5707963) ≈ 1`

참고 계산의 결과는 읽기 쉽게 반올림했습니다. 실제 셰이더 출력은 대상 언어의 정밀도 규칙을 따릅니다.

## 입력 범위와 주의사항

이 예제의 입력 조건: x ∈ ℝ

입력 단위는 라디안입니다. 도 단위의 각도는 라디안으로 변환해야 합니다.

셰이더의 입력 규칙과 정밀도는 [WGSL](https://www.w3.org/TR/WGSL/)과 [GLSL ES 3.00](https://registry.khronos.org/OpenGL/specs/es/3.0/GLSL_ES_Specification_3.00.pdf)에서 규정합니다.

## 관련 함수

- [`cos`](https://typeshade.dev/ko/reference/functions/cos/)
- [`tan`](https://typeshade.dev/ko/reference/functions/tan/)
- [`asin`](https://typeshade.dev/ko/reference/functions/asin/)
- [`acos`](https://typeshade.dev/ko/reference/functions/acos/)

**WGSL**

`sin(a)`

**GLSL ES 3.00**

`sin(a)`

시그니처와 이름 아래 문장, 컴파일러 메시지는 커밋 af54ddad5의 컴파일러가 쓴 영어 원문입니다.

Returns the sine of `x` (in radians), componentwise over vectors.

## 구문

```ts
declare function sin<V extends vec2 | vec3 | vec4>(a0: V): V
declare function sin<P0 extends number>(a0: P0): ScalarOf<P0>
declare function sin<T extends Numeric | Vec64Any>(a0: T): T
```

매개변수나 반환 위치에 쓰인 `number`는 스칼라가 들어갈 자리입니다. 앰비언트 파일은 GPU 스칼라를 브랜드가 붙은 number로 선언하고 그 브랜드는 선택이라서, 리터럴도 브랜드가 붙은 스칼라도 이 자리에 들어갑니다.

`type f32 = number & { readonly [f32Tag]?: true }`

타입으로 쓴 `number`는 쓰이는 곳을 보고 추론하며, `f32`, `i32`, `u32`는 너비를 고정합니다. 그 행과 컴파일러가 낸 결과는 [TypeScript에서](https://typeshade.dev/ko/guide/language/from-typescript/) 페이지에 있습니다.

시그니처에는 앰비언트 파일이 스스로 쓰려고 선언한 타입이 나올 수 있습니다. 아래가 그 선언입니다.

**`Vec64Any`**

`type Vec64Any = vec2f64 | vec3f64 | vec4f64`

**`ScalarOf`**

`type ScalarOf<A, B = unknown, C = unknown> = unknown extends A ? number : [A] extends [boolean] ? bool : typeof f32Tag extends keyof A ? f32 : typeof i32Tag extends keyof A ? i32 : typeof u32Tag extends keyof A ? u32 : typeof f64Tag extends keyof A ? f64 : ScalarOf<B, C>`

**`Numeric`**

`type Numeric = number | vec2 | vec3 | vec4 | vec2i | vec3i | vec4i | vec2u | vec3u | vec4u`

## 매개변수

`a0`, `a1`처럼 자리로만 붙은 매개변수 이름은 앰비언트 파일이 만들어 낸 것입니다. 호출은 인자를 순서대로 넘기고 이름은 쓰지 않습니다.

- `a0` `V``P0``T`

## 반환값

`V``ScalarOf<P0>``T`

## 설명

Also accepts `f64` operands.

CPU 오라클이 `f64`로 직접 계산합니다.

## 대상별 출력

**WGSL**

`sin(a)`

**GLSL ES 3.00**

`sin(a)`

## 예제

- [`path/moving-wave/moving-wave.shade.ts`](https://typeshade.dev/ko/guide/examples/moving-wave/)
- [`path/palette/palette.shade.ts`](https://typeshade.dev/ko/guide/examples/palette/)
- [`path/bouncing-balls/bouncing-balls.shade.ts`](https://typeshade.dev/ko/guide/examples/bouncing-balls/)
- [`gallery/capsule-corp-namek-class/capsule-corp-namek-class.shade.ts`](https://typeshade.dev/ko/guide/examples/capsule-corp-namek-class/)
- [`gallery/hillshade-twin/hillshade-twin.shade.ts`](https://typeshade.dev/ko/guide/examples/hillshade-twin/)
- [`gallery/julia-twin/julia-twin.shade.ts`](https://typeshade.dev/ko/guide/examples/julia-twin/)
- [`gallery/kaleidoscope-twin/kaleidoscope-twin.shade.ts`](https://typeshade.dev/ko/guide/examples/kaleidoscope-twin/)
- [`gallery/mandelbrot-twin/mandelbrot-twin.shade.ts`](https://typeshade.dev/ko/guide/examples/mandelbrot-twin/)
- [`gallery/path-tracer/path-tracer.shade.ts`](https://typeshade.dev/ko/guide/examples/path-tracer/)
- [`gallery/plasma-twin/plasma-twin.shade.ts`](https://typeshade.dev/ko/guide/examples/plasma-twin/)
- [`gallery/rt-renderer-class/rt-renderer-class.shade.ts`](https://typeshade.dev/ko/guide/examples/rt-renderer-class/)
- [`gallery/starfield-twin/starfield-twin.shade.ts`](https://typeshade.dev/ko/guide/examples/starfield-twin/)
- [`gallery/tunnel-twin/tunnel-twin.shade.ts`](https://typeshade.dev/ko/guide/examples/tunnel-twin/)
- [`gallery/voronoi-twin/voronoi-twin.shade.ts`](https://typeshade.dev/ko/guide/examples/voronoi-twin/)
- [`gallery/fp64-sine-sweep-twin/fp64-sine-sweep-twin.shade.ts`](https://typeshade.dev/ko/guide/examples/fp64-sine-sweep-twin/)
- [`gallery/higher-order/higher-order.shade.ts`](https://typeshade.dev/ko/guide/examples/higher-order/)
- [`gallery/inferred-returns/inferred-returns.shade.ts`](https://typeshade.dev/ko/guide/examples/inferred-returns/)
- [`gallery/loop-kernel/loop-kernel.shade.ts`](https://typeshade.dev/ko/guide/examples/loop-kernel/)
- [`gallery/orbit-inout/orbit-inout.shade.ts`](https://typeshade.dev/ko/guide/examples/orbit-inout/)
- [`gallery/shadow-compare/shadow-compare.shade.ts`](https://typeshade.dev/ko/guide/examples/shadow-compare/)

## 함께 보기

- [함수](https://typeshade.dev/ko/reference/functions/)
- [내장 함수 표](https://typeshade.dev/ko/guide/language/builtins/#maths)
- [`Math.sin`](https://typeshade.dev/ko/reference/math/sin/)
- [`typeshade/core/ir`의 `sin()`](https://typeshade.dev/ko/api/sin/)
