VB6Parse / Library / Math / tan

VB6 Library Reference

VB6 Tan Function

The Tan function returns the tangent of an angle specified in radians.

Syntax

Tan(number)

Parameters

Returns

Returns a Double representing the tangent of the angle.

Remarks

Typical Uses

  1. Trigonometric calculations
  2. Geometry and graphics
  3. Physics and engineering formulas
  4. Calculating slopes and angles
  5. Animation and simulation
  6. Signal processing
  7. Scientific computation
  8. Converting between coordinate systems

Basic Examples

Example 1: Tangent of 45 degrees

result = Tan(45 * 3.14159265358979 / 180)
' result = 1

Example 2: Tangent of Pi/4 radians

result = Tan(3.14159265358979 / 4)
' result = 1

Example 3: Using with Atn

angle = Atn(1)
result = Tan(angle)
' result = 1

Example 4: Handling Null

result = Tan(Null)
' result = Null

Common Patterns

Pattern 1: Convert degrees to radians

Function DegreesToRadians(degrees As Double) As Double
DegreesToRadians = degrees * 3.14159265358979 / 180
End Function
result = Tan(DegreesToRadians(60))

Pattern 2: Calculate slope from angle

Function SlopeFromAngle(angleRadians As Double) As Double
SlopeFromAngle = Tan(angleRadians)
End Function

Pattern 3: Use in triangle calculations

Function OppositeFromAdjacent(adjacent As Double, angleRadians As Double) As Double
OppositeFromAdjacent = adjacent * Tan(angleRadians)
End Function

Pattern 4: Animation rotation

angle = t * 3.14159265358979 / 180
y = Tan(angle) * x

Pattern 5: Periodic function

For i = 0 To 360 Step 45
Debug.Print Tan(i * 3.14159265358979 / 180)
Next i

Pattern 6: Error handling for undefined values

On Error Resume Next
result = Tan(3.14159265358979 / 2)
If Err.Number <> 0 Then
Debug.Print "Overflow error"
End If
On Error GoTo 0

Pattern 7: Use with arrays

For i = LBound(arr) To UBound(arr)
arr(i) = Tan(arr(i))
Next i

Pattern 8: Inverse calculation

angle = Atn(Tan(x))

Pattern 9: Normalize angle

angle = angle Mod (2 * 3.14159265358979)
result = Tan(angle)

Pattern 10: Use in coordinate conversion

y = r * Tan(theta)

Advanced Usage

Example 1: Trigonometric Table

For i = 0 To 90 Step 15
Debug.Print "Tan(" & i & ") = " & Tan(i * 3.14159265358979 / 180)
Next i

Example 2: Slope Calculation

Function Slope(degrees As Double) As Double
Slope = Tan(degrees * 3.14159265358979 / 180)
End Function

Example 3: Handling Undefined Values

On Error Resume Next
result = Tan(3.14159265358979 / 2)
If Err.Number <> 0 Then
result = Null
End If
On Error GoTo 0

Example 4: Use in Physics Formula

' Calculate projectile height
height = distance * Tan(angleRadians)

Error Handling

Performance Notes

Best Practices

  1. Always use radians, not degrees.
  2. Convert degrees to radians as needed.
  3. Handle possible overflow for undefined values.
  4. Use error handling for edge cases.
  5. Test with a range of values.
  6. Use with Atn for inverse calculations.
  7. Document expected input range.
  8. Avoid using with multiples of π/2.
  9. Use with arrays for batch calculations.
  10. Normalize angles for periodicity.

Comparison Table

Function Purpose Input Returns
Tan Tangent radians Double
Atn Arctangent number Double
Sin Sine radians Double
Cos Cosine radians Double

Platform Notes

Limitations

← Back to Math | View all functions