private void GenerateBaseValues() { if (fromDegrees) { radians = (degrees * M.PI) / 180; } else { degrees = (radians * 180) / M.PI; } //If allowed, use time as input. t = (float)EditorApplication.timeSinceStartup; if (useTime) { radians = t; degrees = degrees = (radians * 180) / M.PI; } //Clamp the values to a readable range radians = M.Repeat(radians, 2 * M.PI); degrees = M.Repeat(degrees, 360); //local variables for simplicity sine = M.Sin(radians); cosine = M.Cos(radians); tangent = M.Tan(radians); }
private void DrawGraph() { //Draw Graph of the curves G.color = C.white; V3 offset = V3.down * 2 + V3.right * -1; G.DrawRay(offset + V3.up * .5f, V3.down * 1); G.DrawRay(offset + V3.down * .5f, V3.right * 2); G.color = C.gray; G.DrawRay(offset + V3.up * .5f, V3.right * 2); G.DrawRay(offset, V3.right * 2); G.DrawRay(offset + V3.up * .5f + V3.right * M.Repeat(radians / M.PI, 2), V3.down * 1); //Draw Sine G.color = C.red; offset = V3.down * 2 + V3.right * -1; V3 last = new V3(0, 0, 0) + offset; for (int i = 1; i <= 360; i++) { V3 point = new V3((float)i / 180, M.Sin(M.Deg2Rad * i) * .5f, 0) + offset; G.DrawLine(last, point); last = point; } //Draw Cosine G.color = C.blue; offset = V3.down * 2 + V3.right * -1; last = new V3(0, .5f, 0) + offset; for (int i = 1; i <= 360; i++) { V3 point = new V3((float)i / 180, M.Cos(M.Deg2Rad * i) * .5f, 0) + offset; G.DrawLine(last, point); last = point; } //Draw Tangent if (showTan) { G.color = C.yellow; offset = V3.down * 2 + V3.right * -1; last = new V3(0, .5f, 0) + offset; for (int i = 1; i <= 360; i++) { V3 point = new V3((float)i / 180, M.Tan(M.Deg2Rad * i) * .5f, 0) + offset; G.DrawLine(last, point); last = point; } } }
public static float PingPong(float t, float length) { t = Mathf.Repeat(t, length * 2f); return(length - Mathf.Abs(t - length)); }