rotate2D

a 2D vector by a given angle.

110 total functionsUpdated: Invalid Date

rotate2D

a 2D vector by a given angle.

Parameters

NameTypeDescription
vvec2<f32>Input 2D vector to rotate.
anglef32Rotation angle in radians.

Returns

vec2<f32>2D vector.

WGSL Code

fn rotate2D(v: vec2<f32>, angle: f32) -> vec2<f32> {
let c = cos(angle);
let s = sin(angle);
return vec2(v.x * c - v.y * s, v.x * s + v.y * c);
}

About wgsl-fns

A JavaScript library providing WGSL utility functions as strings for WebGPU shader development. Includes mathematical utilities, noise generation, signed distance fields, and color manipulation functions.

Install:npm install wgsl-fns
Import:import { rotate2D, getFns } from 'wgsl-fns'
Usage:getFns(['rotate2D'])