Skip to content

Repository files navigation

MiniCAD

A personal project to explore CAD geometry, computational geometry, DXF parsing, coordinate transformations, and 2D CAD visualization using C# and .NET. This project is being developed from scratch as a learning project with the long-term goal of building a small CAD geometry/kernel-like system and a simple CAD viewer.

🚧 Work in Progress

MiniCAD is still under active development. Many features are incomplete and the architecture will continue to evolve as new geometry and CAD concepts are implemented.


MiniCAD Viewer

MiniCAD Viewer

MiniCAD.Viewer/ViewerUI.png

Procedure

Mathematics
    ↓
Computational Geometry
    ↓
CAD Data Structures
    ↓
DXF Parsing
    ↓
Coordinate Transformation
    ↓
Rendering
    ↓
Interactive Viewer

The current viewer can load a DXF file and display supported entities such as Lines and Circles.


Current Features

Geometry

Currently implemented or under development:

  • Point
  • Vector
  • Line
  • Circle
  • Triangle
  • Polygon
  • BoundingBox
  • 2D Matrix transformations
  • Translation
  • Rotation
  • Scaling
  • Mirroring
  • Distance calculations
  • Dot product
  • Cross product
  • Vector normalization
  • Angle calculations
  • Geometric containment tests
  • Intersection calculations

DXF

A basic DXF reader is currently being developed.

Current functionality includes:

  • Reading ASCII DXF files
  • Parsing DXF group code/value pairs
  • Reading LINE entities
  • Reading CIRCLE entities
  • Loading multiple entities from a single DXF file

Example:

DXF
 ├── LINE
 ├── CIRCLE
 ├── LINE
 ├── CIRCLE
 └── ...

These entities are converted into MiniCAD geometry objects and passed to the viewer.

Viewer

A simple WinForms-based 2D CAD viewer is currently implemented.

Current functionality:

  • Open DXF files through a file dialog
  • Display DXF Lines
  • Display DXF Circles
  • World-to-screen coordinate transformation
  • Camera zoom
  • Camera offset
  • Bounding-box based Fit All
  • Basic viewer UI

Architecture

The project is currently organized into several components:

MiniCAD
│
├── MiniCAD.Geometry
│   ├── Point.cs
│   ├── Vector.cs
│   ├── Line.cs
│   ├── Circle.cs
│   ├── Triangle.cs
│   ├── Polygon.cs
│   ├── BoundingBox.cs
│   └── Matrix2D.cs
│
├── MiniCAD.Geometry.Tests
│   ├── PointTests.cs
│   ├── VectorTests.cs
│   └── ...
│
├── MiniCAD.dxf
│   ├── DxfReader.cs
│   ├── DxfPair.cs
│   └── Samples
│
└── MiniCAD.Viewer
    ├── Form1.cs
    ├── Camera.cs
    └── ...

The overall architecture is evolving as the project grows.

Coordinate Transformation

MiniCAD uses a separation between world coordinates and screen coordinates.

World Coordinates
       │
       ▼
   Camera
       │
       ▼
World → Screen
       │
       ▼
   WinForms
       │
       ▼
     Viewer

The current camera supports:

  • Zoom
  • X/Y offset
  • World-to-screen transformation
  • Fit All calculation

The goal is to gradually evolve this into a more complete CAD-style camera/navigation system.

Testing

The geometry library is being developed using automated unit tests with xUnit.

Example:

[Theory]
[InlineData(1, 0, 1, 0, 0)]
[InlineData(1, 0, 0, 1, 90)]
[InlineData(1, 0, -1, 0, 180)]
[InlineData(0, 1, 1, 0, 0)]
public void AngleTo(double x1, double y1, double x2, double y2, double expected)
{
    Vector v1 = new Vector(x1, y1);
    Vector v2 = new Vector(x2, y2);
    double actualRadian = v1.AngleTo(v2);
    double actual = actualRadian * 180 / Math.PI;

    Assert.Equal(expected, actual, 0.001);
}

The test suite is being expanded as new geometry functionality is implemented.

What it is covering

This project is primarily a hands-on exploration of the concepts behind CAD and geometry software.

Areas being studied include:

  • Computational Geometry
  • Linear Algebra
  • Numerical Tolerance
  • Coordinate Systems
  • Geometric Transformations
  • Bounding Boxes
  • Intersection Algorithms
  • Curve Mathematics
  • CAD Data Formats
  • DXF
  • 2D Rendering
  • Camera Systems
  • Mesh Geometry
  • Boundary Representation (B-Rep)
  • NURBS

Roadmap

Phase 1 - Basic Geometry

  • Point
  • Vector
  • Line
  • Circle
  • Basic transformations
  • BoundingBox
  • Matrix2D
  • UnitTests

Phase 2 - DXF

  • DXF file reading
  • DXF pair parsing
  • LINE
  • CIRCLE
  • ARC
  • POLYLINE
  • SPLINE
  • DXF Writer

Phase 3 - Viewer

  • Windows Forms viewer
  • DXF loading
  • Basic rendering
  • Camera
  • World-to-screen transformation
  • Zoom
  • Offset / Pan
  • Mouse interaction
  • Selection
  • Grid
  • Coordinate system
  • Layers

Phase 4 — Computational Geometry

  • Polygon.Contains
  • Triangle.Contains
  • Line intersection
  • Line-Circle intersection
  • Circle-Circle intersection
  • Convex Hull
  • Curve intersection
  • Boolean geometry

Phase 5 — Advanced Geometry

  • Bezier Curves
  • Mesh
  • Half-edge data structure
  • B-Rep
  • NURBS
  • Surface evaluation

🚧 More features will be added continuously!

About

A personal CAD kernel and computational geometry project built from scratch in C#, featuring geometry algorithms, DXF processing, and CAD engine fundamentals.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages