Thunder.UnitsNET.Vectors.Geometry.MonoGame 0.2.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package Thunder.UnitsNET.Vectors.Geometry.MonoGame --version 0.2.0
                    
NuGet\Install-Package Thunder.UnitsNET.Vectors.Geometry.MonoGame -Version 0.2.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Thunder.UnitsNET.Vectors.Geometry.MonoGame" Version="0.2.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Thunder.UnitsNET.Vectors.Geometry.MonoGame" Version="0.2.0" />
                    
Directory.Packages.props
<PackageReference Include="Thunder.UnitsNET.Vectors.Geometry.MonoGame" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Thunder.UnitsNET.Vectors.Geometry.MonoGame --version 0.2.0
                    
#r "nuget: Thunder.UnitsNET.Vectors.Geometry.MonoGame, 0.2.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Thunder.UnitsNET.Vectors.Geometry.MonoGame@0.2.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Thunder.UnitsNET.Vectors.Geometry.MonoGame&version=0.2.0
                    
Install as a Cake Addin
#tool nuget:?package=Thunder.UnitsNET.Vectors.Geometry.MonoGame&version=0.2.0
                    
Install as a Cake Tool

Thunder.UnitsNET.Vectors.Geometry.MonoGame

MonoGame / XNA integration for Thunder.UnitsNET.Vectors.Geometry.

Provides extension methods to convert unit-aware 2D geometry shapes — circles, rectangles, triangles, ellipses, arcs, sectors, capsules, and polygons — to XNA/MonoGame rendering primitives. Scaling is explicit: you always supply the unit and pixels-per-unit factor, keeping physics dimensions and screen pixels cleanly separated.

Quick start

// dotnet add package Thunder.UnitsNET.Vectors.Geometry
// dotnet add package Thunder.UnitsNET.Vectors.Geometry.MonoGame

using Thunder.UnitsNET.Vectors.Geometry;
using Thunder.UnitsNET.Vectors.Geometry.MonoGame;
using UnitsNet;
using UnitsNet.Units;
using Microsoft.Xna.Framework;

const double ppm = 64.0; // 64 pixels per metre

// Circle: get centre + radius for a circle-draw call
var circle = new Circle2(LengthVector2.FromMeters(5, 3), Radius.FromMeters(2));
Vector2 center = circle.GetXnaCenter(LengthUnit.Meter, ppm);   // (320, 192)
float   radius = circle.GetXnaRadius(LengthUnit.Meter, ppm);   // 128f

// Rectangle: get the four corners for a rotated-quad renderer
var rect = new Rectangle2(
    LengthVector2.FromMeters(0, 0),
    LengthVector2.FromMeters(4, 2),
    Directional.FromDegrees(30));
Vector2[] corners = rect.GetXnaCorners(LengthUnit.Meter, ppm);

// Triangle: get vertex array
var tri = new Triangle2(
    LengthVector2.FromMeters(0, 0),
    LengthVector2.FromMeters(3, 0),
    LengthVector2.FromMeters(1.5, 2));
Vector2[] verts = tri.GetXnaVertices(LengthUnit.Meter, ppm);

// Arc: get polyline for a line-strip renderer
var arc = new Arc2(
    new Circle2(LengthVector2.FromMeters(0, 0), Radius.FromMeters(5)),
    Directional.East,
    Angle.FromDegrees(90));
Vector2[] arcPoints = arc.GetXnaPolyline(LengthUnit.Meter, ppm);

// Polygon
var hex = Polygon2.CreateRegular(LengthVector2.FromMeters(0, 0), Length.FromMeters(3), 6);
Vector2[] hexVerts = hex.GetXnaVertices(LengthUnit.Meter, ppm);

// Directional → XNA rotation float (radians)
float rot = Directional.North.ToXnaRotation(); // MathF.PI / 2

Conversion API

GeometryXnaExtensions

All methods follow the pattern GetXnaXxx(LengthUnit unit, double scale) with convenience overloads that default scale = 1.0 and/or unit = LengthUnit.Meter.

Circle2
Method Returns Notes
GetXnaCenter(unit, scale) Vector2 Centre in screen pixels
GetXnaRadius(unit, scale) float Radius in screen pixels
Rectangle2
Method Returns Notes
GetXnaCenter(unit, scale) Vector2 Centre in screen pixels
GetXnaCorners(unit, scale) Vector2[4] [TopLeft, TopRight, BottomLeft, BottomRight]; supports rotation
Triangle2
Method Returns Notes
GetXnaVertices(unit, scale) Vector2[3] [A, B, C]
Ellipse2
Method Returns Notes
GetXnaCenter(unit, scale) Vector2 Centre in screen pixels
GetXnaRadii(unit, scale) (float semiMajor, float semiMinor) Both axes in screen pixels
GetXnaRotation() float Rotation of major axis in radians
Arc2
Method Returns Notes
GetXnaPolyline(unit, scale, segmentCount?) Vector2[] Line-strip from start to end of arc
Sector2
Method Returns Notes
GetXnaPolyline(unit, scale, arcSegmentCount?) Vector2[] Closed polygon: [center, arcStart, …, arcEnd, center]
Capsule2
Method Returns Notes
GetXnaSpineStart(unit, scale) Vector2 Centre of first semicircle
GetXnaSpineEnd(unit, scale) Vector2 Centre of second semicircle
GetXnaRadius(unit, scale) float Capsule radius in screen pixels
Polygon2
Method Returns Notes
GetXnaVertices(unit, scale) Vector2[] Same count and order as Vertices
Directional
Method Returns Notes
ToXnaRotation() float Angle in radians (East=0, North=π/2)

Scale parameter

scale is "pixels per unit". Examples:

  • 64.0 → 1 metre = 64 pixels (tile-based game)
  • 1.0 → 1 metre = 1 pixel (already in screen units)
  • 100.0 → 1 metre = 100 pixels

Pass your pixels-per-unit constant at the call site rather than storing it as a global.

MonoGame dependency note

MonoGame.Framework.DesktopGL is declared as PrivateAssets="all" in this package. Add your own platform-specific MonoGame package to your game project.

Source repository

thunder-unitsnet-vectors

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.2.10 0 4/15/2026
0.2.9 0 4/15/2026
0.2.8 0 4/15/2026
0.2.1 0 4/15/2026
0.2.0 20 4/14/2026