Measurement Tools
TerraLab provides a suite of measurement tools for precise angular measurements on the celestial sphere. All measurements account for spherical geometry and great circle distances.Available Tools
Four measurement tool types are available:- Ruler: Linear distance between two points
- Square: Fixed aspect ratio rectangle (1:1)
- Rectangle: Variable aspect ratio with rotation
- Circle: Circular area measurement
measurement_tools.py:20-24
Activating Measurement Tools
To activate a tool:tool_name is one of:
"ruler""square""rectangle""circle""none"to deactivate
- Escape: Cancel current measurement or deselect active tool
- Delete or Backspace: Delete selected measurement
Ruler Tool
Measures the great circle distance between two points on the celestial sphere.Usage
- Select ruler tool
- Click first point (endpoint A)
- Move mouse to see preview line
- Click second point (endpoint B) to finalize
Measurement Display
Technical Details
Distance Calculation:- Great circle arc interpolated with 72 points
- Uses
slerp_arc_points()for smooth spherical interpolation - Label positioned at arc midpoint
measurement_tools.py:437-448
Square Tool
Creates a square measurement frame with equal width and height.Usage
- Select square tool
- Click and drag from origin corner
- Release to finalize
- The larger dimension (width or height) is used for both
Measurement Display
Technical Details
Area Calculation:- Small-angle approximation:
area = width × height - Sufficient for typical measurement scales (< 30°)
- For exact spherical cap area, integration required
- Four corners computed in local tangent plane
- Projected to spherical coordinates
- Each edge rendered with 24 interpolation points
measurement_tools.py:478-516
Rectangle Tool
Creates a rectangular measurement frame with independent width/height and rotation capability.Usage
- Select rectangle tool
- Click and drag to define initial rectangle
- Use rotation handle to adjust orientation
- Drag corner handles to resize
- Drag body to move entire rectangle
Measurement Display
Rotation Control
Rectangle mode includes a rotation handle:- Handle appears above the top edge midpoint
- Offset distance:
height/2 + max(0.15°, 15% of max dimension) - Drag handle to rotate frame around center
- Rotation angle stored in
rotation_degproperty (-180° to +180°)
- Dashed line connects top edge midpoint to rotation handle
- Rendered with 8 interpolation points
measurement_tools.py:413-422
Technical Details
Local Coordinate System:- Center point defines local tangent plane origin
- X-axis: Azimuth direction (scaled by cos(altitude))
- Y-axis: Altitude direction
- Rotation applied before projection to sky coordinates
measurement_tools.py:654-657
Circle Tool
Measures circular areas on the sky, useful for estimating nebula sizes or galaxy extents.Usage
- Select circle tool
- Click center point
- Drag to edge point (defines radius)
- Release to finalize
Measurement Display
Handle Types
Center Handle:- Drag to move entire circle
- Preserves radius
- Drag to change radius
- Center remains fixed
Technical Details
Radius Calculation:- 128 interpolation points around circumference
- Each point computed via
destination_point(center, bearing, radius) - Bearing varies from 0° to 360°
measurement_tools.py:450-476
Interaction Modes
Creating Measurements
Drag mode:DRAG_CREATING
- Active while mouse button is held during initial creation
- Preview shown in real-time with reduced opacity (140 alpha)
- Finalized on mouse release
Selecting Measurements
Click on existing measurement to select:- Changes to golden highlight color
- Shows resize/rotation handles
- Enables delete and modification operations
- Body hit: Click within 8px of measurement stroke
- Handle hit: Click within 12px of handle center
- Handles prioritized over body
- Most recent measurement prioritized in overlap
measurement_tools.py:345-377
Moving Measurements
Drag mode:DRAG_MOVING
- Initiated by clicking measurement body (not handle)
- Camera-like inverse motion
- All vertices translated by delta altitude and azimuth
- Azimuth delta uses signed angular difference to handle 0°/360° wrap
measurement_tools.py:379-384
Resizing Measurements
Drag mode:DRAG_RESIZING
- Initiated by clicking and dragging a handle
- Active resize handle stored in
resize_handleproperty - Behavior varies by measurement type:
- Handle “a”: Move first endpoint
- Handle “b”: Move second endpoint
- Handle “center”: Move both center and edge (preserves radius)
- Handle “edge”: Change radius (center fixed)
- Handle “origin”: Move bottom-left corner
- Handle “corner”: Move top-right corner
- Handle “rotate”: Change orientation (rectangle only)
measurement_tools.py:386-422
Visual Styling
Line Rendering
Normal State:- Glow: White with 35% opacity, 3.0px width
- Core: White with full opacity, 1.0px width
- Glow: Golden-white (#FFFFB4) with 45% opacity, 3.2px width
- Core: Golden (#FFF578) with full opacity, 1.2px width
measurement_tools.py:278-296
Handle Rendering
Resize handles (displayed only when selected):- Circle shape, 4.0px radius
- Border: Golden (#FFF078), 1.1px width
- Fill: Black with 200 alpha
- Drawn only for selected measurement
measurement_tools.py:298-315
Label Boxes
Measurement labels appear in compact HUD boxes:- Background: Black with 205 alpha, 5px corner radius
- Text: White, multi-line support
- Padding: 6px horizontal, 4px vertical
- Max width: 320px (auto-sized to content)
- Positioned 8px offset from anchor point
measurement_tools.py:317-343
Data Format
Each measurement is stored as aMeasurementItem dataclass:
(altitude_deg, azimuth_deg)
Source: measurement_tools.py:32-39
Spherical Geometry Functions
Angular Distance
Destination Point
Arc Interpolation
Screen-to-Sky Projection
spherical_math.py (imported in measurement_tools.py:9-14)
Coordinate Normalization
All sky coordinates are normalized to valid ranges:measurement_tools.py:645-648
Performance Optimization
Hit Testing
Measurements tested in reverse order (most recent first) for intuitive selection behavior.Polyline Distance
Point-to-segment distance uses parametric line projection:- w = vector from segment start to test point
- v = segment direction vector
- t = clamped parameter [0,1]
measurement_tools.py:613-626
Polygon Fill Test
Ray-casting algorithm for point-in-polygon (circle and rectangle interiors):- Cast ray from point to infinity
- Count edge intersections
- Odd count = inside, even count = outside
measurement_tools.py:628-643
Integration with Main Canvas
Measurement tools integrate seamlessly with sky rendering:- Controller Instance: Created in
AstronomicalWidget - Event Routing: Mouse events delegated to controller when tool active
- Rendering: Called from main
paintEventafter star rendering - State Persistence: Measurements stored in controller’s
itemslist
Clear All
Delete Selected
Practical Applications
Astrophotography Planning:- Measure sensor FOV coverage of nebulae
- Plan mosaic panel layouts
- Estimate rotation for optimal framing
- Measure apparent separation of double stars
- Estimate planetary disk diameters
- Calculate eyepiece true field of view
- Demonstrate celestial coordinate systems
- Measure constellation dimensions
- Calculate lunar and solar diameters (~ 0.5°)
- Measure meteor trail lengths
- Estimate satellite transit paths
- Measure auroral arc heights and extents