github.com/egonelbre/exp@v0.0.0-20240430123955-ed1d3aa93911/pixel/cmc/v.go (about) 1 package main 2 3 type V struct{ X, Y, Z float32 } 4 5 func S(v V, s float32) V { return V{v.X * s, v.Y * s, v.Z * s} } 6 func L(v V) float32 { return Sqrt(v.X*v.X + v.Y*v.Y + v.Z*v.Z) } 7 func N(v V, s float32) V { return S(v, s/L(v)) } 8 9 func Rx(v V, s float32) V { 10 sn, cs := Sincos(s) 11 return V{v.X, v.Y*cs - v.Z*sn, v.Y*sn + v.Z*cs} 12 } 13 14 func Ry(v V, s float32) V { 15 sn, cs := Sincos(s) 16 return V{v.Z*cs - v.X*sn, v.Y, v.Z*sn + v.X*cs} 17 } 18 19 func P(v, C V) (r V) { 20 r.Z = (v.Z*0.5 + 30) / 30 21 r.X = C.X - v.X*r.Z*10 22 r.Y = C.Y - v.Y*r.Z*10 23 r.Z = C.Z + r.Z*3 24 return r 25 }