Skip to content

Add optional standard Y-axis coordinate system #142

@shanemmattner

Description

@shanemmattner

Add optional standard Y-axis coordinate system

Problem

KiCAD uses an inverted Y-axis (like computer graphics):

  • Higher Y values = lower on screen (Y=120 is below Y=100)
  • Lower Y values = higher on screen (Y=100 is above Y=120)

This is opposite from standard math/physics where +Y goes up. This creates several issues:

  1. Cognitive load: Users must mentally flip coordinates when designing
  2. LLM performance: Language models trained on standard coordinate systems struggle with inverted Y-axis
  3. Code readability: Circuit descriptions like "place R2 below R1" require counter-intuitive higher Y values
  4. Educational barrier: New users from math/science backgrounds find this confusing

Proposed Solution

Add a global configuration option to use standard Y-axis orientation:

import kicad_sch_api as ksa

# Enable standard Y-axis (higher Y = higher on screen)
ksa.config.positioning.use_standard_y_axis = True

# Now Y increases upward (like standard math)
sch.components.add('Device:R', 'R1', '10k', position=(100, 100))  # Higher on screen
sch.components.add('Device:R', 'R2', '10k', position=(100, 80))   # Lower on screen (smaller Y)

Implementation Details

When use_standard_y_axis = True:

  1. All input Y coordinates are flipped before being written to KiCAD format
  2. All output Y coordinates are flipped when reading from KiCAD format
  3. The KiCAD file format remains unchanged (still uses inverted Y-axis)
  4. Only affects the Python API interface

Technical Approach

Add Y-axis conversion in the core positioning methods:

def _convert_y(y: float, invert: bool = False) -> float:
    """Convert Y coordinate based on axis configuration."""
    if config.positioning.use_standard_y_axis:
        # Flip Y-axis to/from KiCAD's inverted system
        # Need a reference point - could use schematic bounds or origin
        return -y if invert else y
    return y

Benefits

  1. Improved LLM performance: AI models can reason about circuits using standard coordinates
  2. Better UX: More intuitive for users from math/science/engineering backgrounds
  3. Backward compatible: Default behavior unchanged (inverted Y-axis matches KiCAD)
  4. Educational: Easier to teach and learn circuit generation

Considerations

  • Need to define a Y-axis origin/reference point for the flip
  • Should work seamlessly with grid units
  • All positioning methods must be updated consistently
  • Documentation should explain both modes

Related

This complements existing positioning improvements:

  • Grid units configuration (#existing-issue)
  • Parametric positioning with p() helper
  • Auto-routing API

Use Cases

Circuit generation by LLMs:

# LLM can now use natural language → standard coordinates
"Place R2 below R1"R2.y < R1.y  (standard Y-axis)
vs.
"Place R2 below R1"R2.y > R1.y  (inverted Y-axis - confusing!)

Educational examples:

# Draw voltage divider from top to bottom
sch.components.add('power:VCC', position=(50, 100))  # Top (high Y)
sch.components.add('Device:R', 'R1', position=(50, 80))
sch.components.add('Device:R', 'R2', position=(50, 60))
sch.components.add('power:GND', position=(50, 40))   # Bottom (low Y)
# Natural top-to-bottom ordering with decreasing Y values

Priority

Medium-High - This would significantly improve:

  • AI/LLM-assisted circuit generation
  • User experience for programmatic schematic creation
  • Educational adoption of the library

Not urgent for current users who are accustomed to KiCAD conventions, but valuable for expanding the user base and AI applications.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions