Re: Trigonometry problem

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



@Rick:
Your Function has a small bug somewhere, using it with
negative arguments. If you paste your Code into my
example form (commenting mine out) you can see this.

Good catch! Here is the revised function that eliminates the bug...

Private Function TriangleWave(ByVal Angle) As Single
Const PI As Double = 3.14159265358979
Const HALFPI As Double = PI / 2
TriangleWave = Sgn(Sin(Angle - HALFPI - (Angle < 0) * PI)) * _
(Abs((1 + 2 * Int((Abs(Angle) + HALFPI) / PI)) * _
HALFPI) - Abs(Angle) - HALFPI) / HALFPI
End Function


Rick


.