some improvments

This commit is contained in:
Adrian Zürcher
2026-01-01 11:00:23 +01:00
parent 8f313c00f0
commit ef0778c8b3
20 changed files with 305 additions and 385 deletions

View File

@@ -43,13 +43,13 @@ func (v Vector) Rotate(phi float64) Vector {
}
// Change the sign of the vector: -vector.
func (this Vector) Flip() Vector {
mag := this.Magnitude()
theta := this.GetPolarAngle()
func (v Vector) Flip() Vector {
mag := v.Magnitude()
theta := v.GetPolarAngle()
this.Dx = mag * math.Cos(theta+math.Pi)
this.Dy = mag * math.Sin(theta+math.Pi)
return this
v.Dx = mag * math.Cos(theta+math.Pi)
v.Dy = mag * math.Sin(theta+math.Pi)
return v
}
func (v Vector) FlipY() Vector {
@@ -62,19 +62,19 @@ func (v Vector) FlipX() Vector {
return v
}
func (this Vector) Scale(factor float64) Vector {
mag := this.Magnitude()
theta := this.GetPolarAngle()
func (v Vector) Scale(factor float64) Vector {
mag := v.Magnitude()
theta := v.GetPolarAngle()
this.Dx = factor * mag * math.Cos(theta)
this.Dy = factor * mag * math.Sin(theta)
return this
v.Dx = factor * mag * math.Cos(theta)
v.Dy = factor * mag * math.Sin(theta)
return v
}
func (this Vector) Magnitude() float64 {
return math.Sqrt(math.Pow(this.Dx, 2.0) + math.Pow(this.Dy, 2.0))
func (v Vector) Magnitude() float64 {
return math.Sqrt(math.Pow(v.Dx, 2.0) + math.Pow(v.Dy, 2.0))
}
func (this Vector) GetPolarAngle() float64 {
return math.Atan2(this.Dy, this.Dx)
func (v Vector) GetPolarAngle() float64 {
return math.Atan2(v.Dy, v.Dx)
}