slightly optimize Vec.Rotated
This commit is contained in:
parent
86f0b0f8ca
commit
b0f81a6c7d
5
vec.go
5
vec.go
|
@ -27,7 +27,7 @@ import (
|
||||||
// u := pixel.V(2, 3)
|
// u := pixel.V(2, 3)
|
||||||
// v := pixel.V(8, 1)
|
// v := pixel.V(8, 1)
|
||||||
// if u.X() < 0 {
|
// if u.X() < 0 {
|
||||||
// fmt.Println("this won't happend")
|
// fmt.Println("this won't happen")
|
||||||
// }
|
// }
|
||||||
// x := u.Unit().Dot(v.Unit())
|
// x := u.Unit().Dot(v.Unit())
|
||||||
type Vec complex128
|
type Vec complex128
|
||||||
|
@ -78,7 +78,8 @@ func (u Vec) Scaled(c float64) Vec {
|
||||||
|
|
||||||
// Rotated returns a vector u rotated by the given angle in radians.
|
// Rotated returns a vector u rotated by the given angle in radians.
|
||||||
func (u Vec) Rotated(angle float64) Vec {
|
func (u Vec) Rotated(angle float64) Vec {
|
||||||
return u * V(math.Cos(angle), math.Sin(angle))
|
sin, cos := math.Sincos(angle)
|
||||||
|
return u * V(cos, sin)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Dot returns the dot product of vectors u and v.
|
// Dot returns the dot product of vectors u and v.
|
||||||
|
|
Loading…
Reference in New Issue