Trigonometric
MathThe Trigonometric block evaluates analytical trigonometric and inverse trigonometric functions on input signals. It provides seven standard functions—sine (sin), cosine (cos), tangent (tan), arcsine (asin), arccosine (acos), arctangent (atan), and two-argument four-quadrant arctangent (atan2). In accordance with standard scientific and engineering conventions, all angular inputs and outputs are expressed in radians. When atan2 is selected, the block dynamically provides a second input port to enable full four-quadrant vector phase angle recovery.
Mathematical Model
The block computes the output signal as a function of the primary input (and optional secondary input for atan2):
The mathematical behavior for each selectable function is defined as follows:
- Sine (
sin):
```latex
y(t) = \sin(u(t)), \quad u \in \mathbb{R}, \quad y \in [-1, 1]
```
- Cosine (
cos):
```latex
y(t) = \cos(u(t)), \quad u \in \mathbb{R}, \quad y \in [-1, 1]
```
- Tangent (
tan):
```latex
y(t) = \tan(u(t)) = \frac{\sin(u(t))}{\cos(u(t))}, \quad u \ne \pm \frac{\pi}{2} + k\pi
```
Exhibits vertical asymptotes where .
- Arcsine (
asin):
```latex
y(t) = \arcsin(\operatorname{clamp}(u(t), -1, 1)) \in \left[-\frac{\pi}{2}, \frac{\pi}{2}\right]
```
Input is automatically clamped to to prevent NaN generation.
- Arccosine (
acos):
```latex
y(t) = \arccos(\operatorname{clamp}(u(t), -1, 1)) \in [0, \pi]
```
Input is automatically clamped to to prevent NaN generation.
- Arctangent (
atan):
```latex
y(t) = \arctan(u(t)) \in \left(-\frac{\pi}{2}, \frac{\pi}{2}\right), \quad u \in \mathbb{R}
```
- Four-Quadrant Arctangent (
atan2):
```latex
y(t) = \operatorname{atan2}(u(t), u_2(t)) \in (-\pi, \pi]
```
where is the -coordinate (in) and is the -coordinate (in2). Correctly resolves the angle of the vector in all four quadrants without division-by-zero singularities when .
Inputs & Outputs
| Direction | ID | Label | Type | Status |
|---|---|---|---|---|
| → In | in |
Input | number | Required |
| → In | in2 |
X (atan2) | number | Required |
| ← Out | out |
Output | number | Output |
Parameters
| Parameters | Label | Type | Default | Description |
|---|---|---|---|---|
function |
Function | select | sin |
Usage Examples
Example 1: Direct-Quadrature (d-q) Park Transformation for AC Motors
In Field-Oriented Control (FOC) of permanent magnet synchronous motors, stationary stator currents () are rotated into rotor coordinates () using rotor electrical angle . Feeding into two Trigonometric blocks configured for sin and cos provides the harmonic projection matrices: and .
Example 2: Full Phase Angle Recovery via atan2
Computing true heading angle from 2-axis magnetometer flux density measurements (). Selecting function = "atan2" activates the secondary in2 port. Connecting to in and to in2 recovers the true continuous orientation angle across all four quadrants over the range radians without quadrant ambiguity or divide-by-zero singularities when .
Remarks & Best Practices
- Radian Angular Convention: All functions strictly utilize radians for angular arguments and outputs. To interface with degrees, multiply incoming degree values by using a Gain block (), and scale outgoing radians by ().
- Automatic Domain Clamping in Inverse Functions: For
asinandacos, the simulation engine automatically clamps input values to the valid mathematical domain . This prevents floating-point domain errors when numerical overshoot momentarily yields values like . - Tangent Singularity Protection: The
tanfunction approaches at odd multiples of . For physical models where input angles pass through these asymptotes, cascade aSaturationblock after the Trigonometric block to prevent downstream solver step-size collapse. - Hardware-Accelerated WASM Execution: Mapped directly to native WebAssembly floating-point math instructions (
f64.sin,f64.cos), delivering execution latency per step.
Related Components
- SignalGenerator: Generates continuous time-varying sinusoidal waveforms directly.
- MathFunction: General mathematical functions (, , , ).
- Gain: Scales angular signals between degrees and radians.
- Saturation: Clamps signals to protect against tangent singularities.