Skip to main content

Line Angle

Overview

This transform estimates the local orientation of a tracked polyline at each time, using a midpoint and arc-length window shared by both calculation modes, and reports the angle in a user-defined measured X/Y frame.

Detailed Description

The Line Angle transform quantifies local orientation of a polyline in 2D for each time sample. You choose a midpoint along cumulative arc length (0 = first vertex, 1 = last), and a window width (also as a fraction of total arc length). The window is centered on the midpoint and slides so it always lies on the polyline (for example, near the tip a wide window shifts toward the base instead of extending past 100%).

Any fractional position is resolved with linear interpolation between the two bracketing vertices along the polyline (the same rule as arc-length interpolation elsewhere in the toolbox).

Direct points uses the secant between the interpolated endpoints of the window. Polynomial fit resamples inside that window, fits x(u) and y(u) in local parameter u ∈ [0,1], and uses the tangent (dx/du, dy/du) from the polynomial coefficients evaluated at the midpoint’s local parameter.

Angles are reported in a measured coordinate frame: you supply world-space directions for positive measured X and positive measured Y. The implementation orthonormalizes (Gram–Schmidt) so that (_x) follows your X direction and (_y) is perpendicular, forming a right-handed basis. The output angle uses atan2 in that basis (defaults match world +X / +Y).

There are two methods for calculating the angle:

  • Direct Points: Secant chord across the slid window, expressed in the measured basis.
  • Polynomial Fit: Local polynomial on the window; tangent from derivatives at the midpoint, same basis.

Note

The figure below (hidden in HTML builds) uses older schematic code (vertex-pair tangent and global polynomial). The implementation follows the windowed arc-length description above.

Neuroscience Use Cases

In neuroscience, this transform can be used to analyze a variety of data:

  • Whisker Tracking: The angle of a tracked whisker relative to the animal’s head can be calculated to study sensory input and motor control.
  • Limb Tracking: The angle of a limb segment (e.g., the forearm) can be calculated to analyze reaching movements or other motor behaviors.
  • Tongue Tracking: The angle of the tongue during licking or other oral movements can be quantified.

Parameters

This transform has the following parameters:

  • position: Fraction along cumulative arc length (0.0–1.0) for the midpoint where the angle is attributed.
  • window: Full width of the arc-length window (0.0–1.0), shared by both methods. A value of 0.2 with midpoint 0.2 nominally spans 10%–30% before sliding.
  • method: Direct Points (secant in the window) or Polynomial Fit (local fit in the window, tangent from coefficients).
  • polynomial_order: Polynomial degree when using Polynomial Fit (typical values 2–3).
  • axis_x_x, axis_x_y: World-vector direction of positive measured X (defaults 1, 0).
  • axis_y_x, axis_y_y: World-vector direction of positive measured Y (defaults 0, 1; orthogonalized to X).

Example Configuration

Here is a complete example of a JSON configuration file that could be used to run this transformation. This example uses the midpoint at 50% of arc length, a 20% window, and the default world axes.

[
{
    "transformations": {
        "metadata": {
            "name": "Line Angle Pipeline",
            "description": "Test line angle calculation on line data",
            "version": "1.0"
        },
        "steps": [
            {
                "step_id": "1",
                "transform_name": "Calculate Line Angle",
                "phase": "analysis",
                "input_key": "test_line",
                "output_key": "line_angles",
                "parameters": {
                    "position": 0.5,
                    "window": 0.2,
                    "method": "Direct Points",
                    "polynomial_order": 3,
                    "axis_x_x": 1.0,
                    "axis_x_y": 0.0,
                    "axis_y_x": 0.0,
                    "axis_y_y": 1.0
                }
            }
        ]
    }
}
]