Skip to content

Commit

Permalink
refactor(rotateDeg): move V3F function in the correct segment
Browse files Browse the repository at this point in the history
  • Loading branch information
KarolosLykos committed Oct 26, 2023
1 parent d05fa72 commit 63a5fb2
Showing 1 changed file with 28 additions and 28 deletions.
56 changes: 28 additions & 28 deletions rotateDeg.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,34 +67,6 @@ func (v V3F[T]) RotateDeg(degrees float64, axis axis) V3F[T] {
}
}

// V3I

// RotateDeg rotates the vector counterclockwise by the specified number of degrees, around axis and returns a new V3F vector.
func (v V3I[T]) RotateDeg(degrees float64, axis axis) V3F[float64] {
d := degrees * degToRadFactor

switch axis {
case zAxis:
return V3F[float64]{
X: math.Cos(d)*float64(v.X) - math.Sin(d)*float64(v.Y),
Y: math.Sin(d)*float64(v.X) + math.Cos(d)*float64(v.Y),
Z: float64(v.Z),
}
case yAxis:
return V3F[float64]{
X: math.Cos(d)*float64(v.X) - math.Sin(d)*float64(v.Y),
Y: float64(v.Y),
Z: -math.Sin(d)*float64(v.X) + math.Cos(d)*float64(v.Z),
}
default:
return V3F[float64]{
X: float64(v.X),
Y: math.Cos(d)*float64(v.Y) - math.Sin(d)*float64(v.Z),
Z: -math.Sin(d)*float64(v.Z) + math.Cos(d)*float64(v.Z),
}
}
}

// RotateDegInPlace modifies v by rotating the vector counterclockwise by the specified number of degrees, around axis.
func (v *V3F[T]) RotateDegInPlace(degrees float64, axis axis) {
d := degrees * degToRadFactor
Expand Down Expand Up @@ -126,3 +98,31 @@ func (v *V3F[T]) RotateDegInPlace(degrees float64, axis axis) {
v.Z = z
}
}

// V3I

// RotateDeg rotates the vector counterclockwise by the specified number of degrees, around axis and returns a new V3F vector.
func (v V3I[T]) RotateDeg(degrees float64, axis axis) V3F[float64] {
d := degrees * degToRadFactor

switch axis {
case zAxis:
return V3F[float64]{
X: math.Cos(d)*float64(v.X) - math.Sin(d)*float64(v.Y),
Y: math.Sin(d)*float64(v.X) + math.Cos(d)*float64(v.Y),
Z: float64(v.Z),
}
case yAxis:
return V3F[float64]{
X: math.Cos(d)*float64(v.X) - math.Sin(d)*float64(v.Y),
Y: float64(v.Y),
Z: -math.Sin(d)*float64(v.X) + math.Cos(d)*float64(v.Z),
}
default:
return V3F[float64]{
X: float64(v.X),
Y: math.Cos(d)*float64(v.Y) - math.Sin(d)*float64(v.Z),
Z: -math.Sin(d)*float64(v.Z) + math.Cos(d)*float64(v.Z),
}
}
}

0 comments on commit 63a5fb2

Please sign in to comment.