843 B
843 B
title | tags | created | published |
---|---|---|---|
Vector | note vector math | 2023-08-29T11:59:28Z | true |
2D
Angle
atan2(y, x)
Cross
x * y2 - y * x2
Distance
(a - b).Length()
Dot
x * x2 + y * y2
From angle
x = cos(angle)
y = sin(angle)
Length
sqrt(x * x + y * y)
Normalize
length := x * x + y * y
if length == 0 {
return
}
length = sqrt(length)
x /= length
y /= length
3D
Cross
( y * z2 - z * y2,
z * x2 - x * z2,
x * y2 - y * x2 )
Distance
(a - b).Length()
Dot
x * x2 + y * y2 + z * z2
Length
sqrt(x * x + y * y + z * z)
Normalize
length := x * x + y * y + z * z
if length == 0 {
return
}
length = sqrt(length)
x /= length
y /= length
z /= length