Class GeometryXnaExtensions
- Assembly
- Thunder.UnitsNET.Vectors.Geometry.MonoGame.dll
Extension methods for converting Thunder.UnitsNET.Vectors.Geometry shapes to XNA/MonoGame rendering primitives.
All conversions take a unit and pixelScale parameter so
the caller can explicitly control how physical distances map to screen pixels — for example,
unit = LengthUnit.Meter, pixelScale = Ratio.FromDecimalFractions(64.0) means 1 metre = 64 pixels.
Convenience overloads without scale default to pixelScale = 1.0 (one unit = one pixel).
Overloads without unit default to LengthUnit.Meter.
public static class GeometryXnaExtensions
- Inheritance
-
GeometryXnaExtensions
- Inherited Members
Methods
GetXnaCenter(Circle2)
Returns the centre of circle as an XNA Microsoft.Xna.Framework.Vector2,
with components expressed in unit and multiplied by
scale (pixels per unit).
public static Vector2 GetXnaCenter(this Circle2 circle)
Parameters
circleCircle2The circle to convert.
Returns
- Vector2
The centre as a screen-space Microsoft.Xna.Framework.Vector2.
Examples
var circle = new Circle2(LengthPoint2.FromMeters(5, 3), Radius.FromMeters(2));
Vector2 center = circle.GetXnaCenter(LengthUnit.Meter, Ratio.FromDecimalFractions(64.0)); // (320, 192)
GetXnaCenter(Circle2, LengthUnit)
Returns the centre of circle as an XNA Microsoft.Xna.Framework.Vector2,
with components expressed in unit and multiplied by
scale (pixels per unit).
public static Vector2 GetXnaCenter(this Circle2 circle, LengthUnit unit)
Parameters
circleCircle2The circle to convert.
unitLengthUnitThe length unit to express the position in.
Returns
- Vector2
The centre as a screen-space Microsoft.Xna.Framework.Vector2.
Examples
var circle = new Circle2(LengthPoint2.FromMeters(5, 3), Radius.FromMeters(2));
Vector2 center = circle.GetXnaCenter(LengthUnit.Meter, Ratio.FromDecimalFractions(64.0)); // (320, 192)
GetXnaCenter(Circle2, LengthUnit, Ratio)
Returns the centre of circle as an XNA Microsoft.Xna.Framework.Vector2,
with components expressed in unit and multiplied by
scale (pixels per unit).
public static Vector2 GetXnaCenter(this Circle2 circle, LengthUnit unit, Ratio scale)
Parameters
circleCircle2The circle to convert.
unitLengthUnitThe length unit to express the position in.
scaleRatioPixels per unit (e.g. 64.0 means 1 metre = 64 px).
Returns
- Vector2
The centre as a screen-space Microsoft.Xna.Framework.Vector2.
Examples
var circle = new Circle2(LengthPoint2.FromMeters(5, 3), Radius.FromMeters(2));
Vector2 center = circle.GetXnaCenter(LengthUnit.Meter, Ratio.FromDecimalFractions(64.0)); // (320, 192)
GetXnaCenter(Ellipse2)
Returns the centre of ellipse as an XNA Microsoft.Xna.Framework.Vector2,
with components expressed in unit and multiplied by
scale.
public static Vector2 GetXnaCenter(this Ellipse2 ellipse)
Parameters
ellipseEllipse2The ellipse to convert.
Returns
- Vector2
The centre as a screen-space Microsoft.Xna.Framework.Vector2.
GetXnaCenter(Ellipse2, LengthUnit)
Returns the centre of ellipse as an XNA Microsoft.Xna.Framework.Vector2,
with components expressed in unit and multiplied by
scale.
public static Vector2 GetXnaCenter(this Ellipse2 ellipse, LengthUnit unit)
Parameters
ellipseEllipse2The ellipse to convert.
unitLengthUnitThe length unit to express the position in.
Returns
- Vector2
The centre as a screen-space Microsoft.Xna.Framework.Vector2.
GetXnaCenter(Ellipse2, LengthUnit, Ratio)
Returns the centre of ellipse as an XNA Microsoft.Xna.Framework.Vector2,
with components expressed in unit and multiplied by
scale.
public static Vector2 GetXnaCenter(this Ellipse2 ellipse, LengthUnit unit, Ratio scale)
Parameters
ellipseEllipse2The ellipse to convert.
unitLengthUnitThe length unit to express the position in.
scaleRatioPixels per unit.
Returns
- Vector2
The centre as a screen-space Microsoft.Xna.Framework.Vector2.
GetXnaCenter(Rectangle2)
Returns the centre of rect as an XNA Microsoft.Xna.Framework.Vector2,
with components expressed in unit and multiplied by
scale.
public static Vector2 GetXnaCenter(this Rectangle2 rect)
Parameters
rectRectangle2The rectangle to convert.
Returns
- Vector2
The centre as a screen-space Microsoft.Xna.Framework.Vector2.
GetXnaCenter(Rectangle2, LengthUnit)
Returns the centre of rect as an XNA Microsoft.Xna.Framework.Vector2,
with components expressed in unit and multiplied by
scale.
public static Vector2 GetXnaCenter(this Rectangle2 rect, LengthUnit unit)
Parameters
rectRectangle2The rectangle to convert.
unitLengthUnitThe length unit to express the position in.
Returns
- Vector2
The centre as a screen-space Microsoft.Xna.Framework.Vector2.
GetXnaCenter(Rectangle2, LengthUnit, Ratio)
Returns the centre of rect as an XNA Microsoft.Xna.Framework.Vector2,
with components expressed in unit and multiplied by
scale.
public static Vector2 GetXnaCenter(this Rectangle2 rect, LengthUnit unit, Ratio scale)
Parameters
rectRectangle2The rectangle to convert.
unitLengthUnitThe length unit to express the position in.
scaleRatioPixels per unit.
Returns
- Vector2
The centre as a screen-space Microsoft.Xna.Framework.Vector2.
GetXnaCorners(Rectangle2)
Returns the four corners of rect as an array of XNA
Microsoft.Xna.Framework.Vector2 values in the order [TopLeft, TopRight, BottomLeft, BottomRight],
with components expressed in unit and multiplied by
scale.
Works correctly for rotated rectangles. Use this to draw a rotated quad with a line-strip or polygon renderer.
public static Vector2[] GetXnaCorners(this Rectangle2 rect)
Parameters
rectRectangle2The rectangle to convert.
Returns
- Vector2[]
A Microsoft.Xna.Framework.Vector2 array of length 4: [TopLeft, TopRight, BottomLeft, BottomRight].
Examples
var rect = new Rectangle2(LengthPoint2.Origin, LengthVector2.FromMeters(4, 2));
Vector2[] corners = rect.GetXnaCorners(LengthUnit.Meter, Ratio.FromDecimalFractions(64.0));
// corners[0] = TopLeft, corners[1] = TopRight, etc.
GetXnaCorners(Rectangle2, LengthUnit)
Returns the four corners of rect as an array of XNA
Microsoft.Xna.Framework.Vector2 values in the order [TopLeft, TopRight, BottomLeft, BottomRight],
with components expressed in unit and multiplied by
scale.
Works correctly for rotated rectangles. Use this to draw a rotated quad with a line-strip or polygon renderer.
public static Vector2[] GetXnaCorners(this Rectangle2 rect, LengthUnit unit)
Parameters
rectRectangle2The rectangle to convert.
unitLengthUnitThe length unit to express positions in.
Returns
- Vector2[]
A Microsoft.Xna.Framework.Vector2 array of length 4: [TopLeft, TopRight, BottomLeft, BottomRight].
Examples
var rect = new Rectangle2(LengthPoint2.Origin, LengthVector2.FromMeters(4, 2));
Vector2[] corners = rect.GetXnaCorners(LengthUnit.Meter, Ratio.FromDecimalFractions(64.0));
// corners[0] = TopLeft, corners[1] = TopRight, etc.
GetXnaCorners(Rectangle2, LengthUnit, Ratio)
Returns the four corners of rect as an array of XNA
Microsoft.Xna.Framework.Vector2 values in the order [TopLeft, TopRight, BottomLeft, BottomRight],
with components expressed in unit and multiplied by
scale.
Works correctly for rotated rectangles. Use this to draw a rotated quad with a line-strip or polygon renderer.
public static Vector2[] GetXnaCorners(this Rectangle2 rect, LengthUnit unit, Ratio scale)
Parameters
rectRectangle2The rectangle to convert.
unitLengthUnitThe length unit to express positions in.
scaleRatioPixels per unit.
Returns
- Vector2[]
A Microsoft.Xna.Framework.Vector2 array of length 4: [TopLeft, TopRight, BottomLeft, BottomRight].
Examples
var rect = new Rectangle2(LengthPoint2.Origin, LengthVector2.FromMeters(4, 2));
Vector2[] corners = rect.GetXnaCorners(LengthUnit.Meter, Ratio.FromDecimalFractions(64.0));
// corners[0] = TopLeft, corners[1] = TopRight, etc.
GetXnaPolyline(Arc2, int?)
Returns the arc as an array of XNA Microsoft.Xna.Framework.Vector2 polyline points,
with positions expressed in unit and multiplied by
scale.
The point count is determined by CalculateArcSegments(int?)'s
automatic segment count, which scales with the arc angle. Pass
segmentCount to override.
public static Vector2[] GetXnaPolyline(this Arc2 arc, int? segmentCount = null)
Parameters
arcArc2The arc to convert.
segmentCountint?Optional override for the number of line segments. When null, the segment count is chosen automatically based on the arc angle.
Returns
- Vector2[]
A Microsoft.Xna.Framework.Vector2 array representing the arc polyline, from the start position to the end position.
Examples
var circle = new Circle2(LengthPoint2.Origin, Radius.FromMeters(1));
var arc = new Arc2(circle, Direction2.East, Angle.FromDegrees(90));
Vector2[] points = arc.GetXnaPolyline(LengthUnit.Meter, Ratio.FromDecimalFractions(64.0));
GetXnaPolyline(Arc2, LengthUnit, int?)
Returns the arc as an array of XNA Microsoft.Xna.Framework.Vector2 polyline points,
with positions expressed in unit and multiplied by
scale.
The point count is determined by CalculateArcSegments(int?)'s
automatic segment count, which scales with the arc angle. Pass
segmentCount to override.
public static Vector2[] GetXnaPolyline(this Arc2 arc, LengthUnit unit, int? segmentCount = null)
Parameters
arcArc2The arc to convert.
unitLengthUnitThe length unit to express positions in.
segmentCountint?Optional override for the number of line segments. When null, the segment count is chosen automatically based on the arc angle.
Returns
- Vector2[]
A Microsoft.Xna.Framework.Vector2 array representing the arc polyline, from the start position to the end position.
Examples
var circle = new Circle2(LengthPoint2.Origin, Radius.FromMeters(1));
var arc = new Arc2(circle, Direction2.East, Angle.FromDegrees(90));
Vector2[] points = arc.GetXnaPolyline(LengthUnit.Meter, Ratio.FromDecimalFractions(64.0));
GetXnaPolyline(Arc2, LengthUnit, Ratio, int?)
Returns the arc as an array of XNA Microsoft.Xna.Framework.Vector2 polyline points,
with positions expressed in unit and multiplied by
scale.
The point count is determined by CalculateArcSegments(int?)'s
automatic segment count, which scales with the arc angle. Pass
segmentCount to override.
public static Vector2[] GetXnaPolyline(this Arc2 arc, LengthUnit unit, Ratio scale, int? segmentCount = null)
Parameters
arcArc2The arc to convert.
unitLengthUnitThe length unit to express positions in.
scaleRatioPixels per unit.
segmentCountint?Optional override for the number of line segments. When null, the segment count is chosen automatically based on the arc angle.
Returns
- Vector2[]
A Microsoft.Xna.Framework.Vector2 array representing the arc polyline, from the start position to the end position.
Examples
var circle = new Circle2(LengthPoint2.Origin, Radius.FromMeters(1));
var arc = new Arc2(circle, Direction2.East, Angle.FromDegrees(90));
Vector2[] points = arc.GetXnaPolyline(LengthUnit.Meter, Ratio.FromDecimalFractions(64.0));
GetXnaPolyline(Sector2, int?)
Returns the sector as a closed Microsoft.Xna.Framework.Vector2 polygon: centre → arc points → back to centre. This is suitable for filled polygon or line-strip rendering.
The arc resolution is chosen automatically; pass arcSegmentCount
to override.
public static Vector2[] GetXnaPolyline(this Sector2 sector, int? arcSegmentCount = null)
Parameters
sectorSector2The sector to convert.
arcSegmentCountint?Optional override for arc segment count. When null, chosen automatically.
Returns
- Vector2[]
A closed Microsoft.Xna.Framework.Vector2 array: [center, arcStart, …, arcEnd, center].
Examples
var circle = new Circle2(LengthPoint2.Origin, Radius.FromMeters(1));
var sector = new Sector2(circle, Direction2.East, Direction2.North, ArcDirection.CounterClockwise);
Vector2[] polygon = sector.GetXnaPolyline(LengthUnit.Meter, Ratio.FromDecimalFractions(64.0));
GetXnaPolyline(Sector2, LengthUnit, int?)
Returns the sector as a closed Microsoft.Xna.Framework.Vector2 polygon: centre → arc points → back to centre. This is suitable for filled polygon or line-strip rendering.
The arc resolution is chosen automatically; pass arcSegmentCount
to override.
public static Vector2[] GetXnaPolyline(this Sector2 sector, LengthUnit unit, int? arcSegmentCount = null)
Parameters
sectorSector2The sector to convert.
unitLengthUnitThe length unit to express positions in.
arcSegmentCountint?Optional override for arc segment count. When null, chosen automatically.
Returns
- Vector2[]
A closed Microsoft.Xna.Framework.Vector2 array: [center, arcStart, …, arcEnd, center].
Examples
var circle = new Circle2(LengthPoint2.Origin, Radius.FromMeters(1));
var sector = new Sector2(circle, Direction2.East, Direction2.North, ArcDirection.CounterClockwise);
Vector2[] polygon = sector.GetXnaPolyline(LengthUnit.Meter, Ratio.FromDecimalFractions(64.0));
GetXnaPolyline(Sector2, LengthUnit, Ratio, int?)
Returns the sector as a closed Microsoft.Xna.Framework.Vector2 polygon: centre → arc points → back to centre. This is suitable for filled polygon or line-strip rendering.
The arc resolution is chosen automatically; pass arcSegmentCount
to override.
public static Vector2[] GetXnaPolyline(this Sector2 sector, LengthUnit unit, Ratio scale, int? arcSegmentCount = null)
Parameters
sectorSector2The sector to convert.
unitLengthUnitThe length unit to express positions in.
scaleRatioPixels per unit.
arcSegmentCountint?Optional override for arc segment count. When null, chosen automatically.
Returns
- Vector2[]
A closed Microsoft.Xna.Framework.Vector2 array: [center, arcStart, …, arcEnd, center].
Examples
var circle = new Circle2(LengthPoint2.Origin, Radius.FromMeters(1));
var sector = new Sector2(circle, Direction2.East, Direction2.North, ArcDirection.CounterClockwise);
Vector2[] polygon = sector.GetXnaPolyline(LengthUnit.Meter, Ratio.FromDecimalFractions(64.0));
GetXnaRadii(Ellipse2)
Returns the semi-major and semi-minor axis lengths of ellipse
as a tuple of screen-space float values, expressed in
unit and multiplied by scale.
The first element is the semi-major axis (the longer half-axis) and the second is the semi-minor axis (the shorter half-axis).
public static (float semiMajor, float semiMinor) GetXnaRadii(this Ellipse2 ellipse)
Parameters
ellipseEllipse2The ellipse to convert.
Returns
Examples
var center = LengthPoint2.FromMeters(0, 0);
var ellipse = new Ellipse2(center, Length.FromMeters(4), Length.FromMeters(2), Direction2.East);
var (rx, ry) = ellipse.GetXnaRadii(LengthUnit.Meter, Ratio.FromDecimalFractions(64.0)); // (256f, 128f)
GetXnaRadii(Ellipse2, LengthUnit)
Returns the semi-major and semi-minor axis lengths of ellipse
as a tuple of screen-space float values, expressed in
unit and multiplied by scale.
The first element is the semi-major axis (the longer half-axis) and the second is the semi-minor axis (the shorter half-axis).
public static (float semiMajor, float semiMinor) GetXnaRadii(this Ellipse2 ellipse, LengthUnit unit)
Parameters
ellipseEllipse2The ellipse to convert.
unitLengthUnitThe length unit to express radii in.
Returns
Examples
var center = LengthPoint2.FromMeters(0, 0);
var ellipse = new Ellipse2(center, Length.FromMeters(4), Length.FromMeters(2), Direction2.East);
var (rx, ry) = ellipse.GetXnaRadii(LengthUnit.Meter, Ratio.FromDecimalFractions(64.0)); // (256f, 128f)
GetXnaRadii(Ellipse2, LengthUnit, Ratio)
Returns the semi-major and semi-minor axis lengths of ellipse
as a tuple of screen-space float values, expressed in
unit and multiplied by scale.
The first element is the semi-major axis (the longer half-axis) and the second is the semi-minor axis (the shorter half-axis).
public static (float semiMajor, float semiMinor) GetXnaRadii(this Ellipse2 ellipse, LengthUnit unit, Ratio scale)
Parameters
ellipseEllipse2The ellipse to convert.
unitLengthUnitThe length unit to express radii in.
scaleRatioPixels per unit.
Returns
Examples
var center = LengthPoint2.FromMeters(0, 0);
var ellipse = new Ellipse2(center, Length.FromMeters(4), Length.FromMeters(2), Direction2.East);
var (rx, ry) = ellipse.GetXnaRadii(LengthUnit.Meter, Ratio.FromDecimalFractions(64.0)); // (256f, 128f)
GetXnaRadius(Capsule2)
Returns the capsule's radius as a screen-space float, expressed in
unit and multiplied by scale.
public static float GetXnaRadius(this Capsule2 capsule)
Parameters
capsuleCapsule2The capsule to convert.
Returns
- float
The radius in screen-space pixels.
GetXnaRadius(Capsule2, LengthUnit)
Returns the capsule's radius as a screen-space float, expressed in
unit and multiplied by scale.
public static float GetXnaRadius(this Capsule2 capsule, LengthUnit unit)
Parameters
capsuleCapsule2The capsule to convert.
unitLengthUnitThe length unit to express the radius in.
Returns
- float
The radius in screen-space pixels.
GetXnaRadius(Capsule2, LengthUnit, Ratio)
Returns the capsule's radius as a screen-space float, expressed in
unit and multiplied by scale.
public static float GetXnaRadius(this Capsule2 capsule, LengthUnit unit, Ratio scale)
Parameters
capsuleCapsule2The capsule to convert.
unitLengthUnitThe length unit to express the radius in.
scaleRatioPixels per unit.
Returns
- float
The radius in screen-space pixels.
GetXnaRadius(Circle2)
Returns the radius of circle as a float,
expressed in unit and multiplied by scale.
public static float GetXnaRadius(this Circle2 circle)
Parameters
circleCircle2The circle to convert.
Returns
- float
The radius as a screen-space pixel distance.
Examples
var circle = new Circle2(LengthPoint2.Origin, Radius.FromMeters(3));
float r = circle.GetXnaRadius(LengthUnit.Meter, Ratio.FromDecimalFractions(64.0)); // 192f
GetXnaRadius(Circle2, LengthUnit)
Returns the radius of circle as a float,
expressed in unit and multiplied by scale.
public static float GetXnaRadius(this Circle2 circle, LengthUnit unit)
Parameters
circleCircle2The circle to convert.
unitLengthUnitThe length unit to express the radius in.
Returns
- float
The radius as a screen-space pixel distance.
Examples
var circle = new Circle2(LengthPoint2.Origin, Radius.FromMeters(3));
float r = circle.GetXnaRadius(LengthUnit.Meter, Ratio.FromDecimalFractions(64.0)); // 192f
GetXnaRadius(Circle2, LengthUnit, Ratio)
Returns the radius of circle as a float,
expressed in unit and multiplied by scale.
public static float GetXnaRadius(this Circle2 circle, LengthUnit unit, Ratio scale)
Parameters
circleCircle2The circle to convert.
unitLengthUnitThe length unit to express the radius in.
scaleRatioPixels per unit.
Returns
- float
The radius as a screen-space pixel distance.
Examples
var circle = new Circle2(LengthPoint2.Origin, Radius.FromMeters(3));
float r = circle.GetXnaRadius(LengthUnit.Meter, Ratio.FromDecimalFractions(64.0)); // 192f
GetXnaRotation(Ellipse2)
Returns the rotation of ellipse as a float in
radians, suitable for use as an XNA rotation parameter.
public static float GetXnaRotation(this Ellipse2 ellipse)
Parameters
ellipseEllipse2The ellipse to convert.
Returns
- float
The rotation angle of the ellipse's major axis in radians.
GetXnaSpineEnd(Capsule2)
Returns the end of the capsule's spine (the centre of the second semicircle) as
an XNA Microsoft.Xna.Framework.Vector2, with components in unit multiplied
by scale.
public static Vector2 GetXnaSpineEnd(this Capsule2 capsule)
Parameters
capsuleCapsule2The capsule to convert.
Returns
- Vector2
The spine end in screen-space pixels.
GetXnaSpineEnd(Capsule2, LengthUnit)
Returns the end of the capsule's spine (the centre of the second semicircle) as
an XNA Microsoft.Xna.Framework.Vector2, with components in unit multiplied
by scale.
public static Vector2 GetXnaSpineEnd(this Capsule2 capsule, LengthUnit unit)
Parameters
capsuleCapsule2The capsule to convert.
unitLengthUnitThe length unit to express the position in.
Returns
- Vector2
The spine end in screen-space pixels.
GetXnaSpineEnd(Capsule2, LengthUnit, Ratio)
Returns the end of the capsule's spine (the centre of the second semicircle) as
an XNA Microsoft.Xna.Framework.Vector2, with components in unit multiplied
by scale.
public static Vector2 GetXnaSpineEnd(this Capsule2 capsule, LengthUnit unit, Ratio scale)
Parameters
capsuleCapsule2The capsule to convert.
unitLengthUnitThe length unit to express the position in.
scaleRatioPixels per unit.
Returns
- Vector2
The spine end in screen-space pixels.
GetXnaSpineStart(Capsule2)
Returns the start of the capsule's spine (the centre of the first semicircle) as
an XNA Microsoft.Xna.Framework.Vector2, with components in unit multiplied
by scale.
To render a capsule, draw a rounded rectangle using the two spine endpoints and the radius: two semicircles centred at each endpoint plus a rectangle between them.
public static Vector2 GetXnaSpineStart(this Capsule2 capsule)
Parameters
capsuleCapsule2The capsule to convert.
Returns
- Vector2
The spine start in screen-space pixels.
GetXnaSpineStart(Capsule2, LengthUnit)
Returns the start of the capsule's spine (the centre of the first semicircle) as
an XNA Microsoft.Xna.Framework.Vector2, with components in unit multiplied
by scale.
To render a capsule, draw a rounded rectangle using the two spine endpoints and the radius: two semicircles centred at each endpoint plus a rectangle between them.
public static Vector2 GetXnaSpineStart(this Capsule2 capsule, LengthUnit unit)
Parameters
capsuleCapsule2The capsule to convert.
unitLengthUnitThe length unit to express the position in.
Returns
- Vector2
The spine start in screen-space pixels.
GetXnaSpineStart(Capsule2, LengthUnit, Ratio)
Returns the start of the capsule's spine (the centre of the first semicircle) as
an XNA Microsoft.Xna.Framework.Vector2, with components in unit multiplied
by scale.
To render a capsule, draw a rounded rectangle using the two spine endpoints and the radius: two semicircles centred at each endpoint plus a rectangle between them.
public static Vector2 GetXnaSpineStart(this Capsule2 capsule, LengthUnit unit, Ratio scale)
Parameters
capsuleCapsule2The capsule to convert.
unitLengthUnitThe length unit to express the position in.
scaleRatioPixels per unit.
Returns
- Vector2
The spine start in screen-space pixels.
GetXnaVertices(Polygon2)
Returns the vertices of polygon as an array of XNA
Microsoft.Xna.Framework.Vector2 values, with positions expressed in unit
and multiplied by scale.
The vertices are in the same order as Vertices. Pass this array to a polygon renderer or line-strip draw call.
public static Vector2[] GetXnaVertices(this Polygon2 polygon)
Parameters
polygonPolygon2The polygon to convert.
Returns
- Vector2[]
A Microsoft.Xna.Framework.Vector2 array with the same number of elements as Vertices.
Examples
var center = LengthPoint2.Origin;
var hex = Polygon2.CreateRegular(center, Length.FromMeters(2), 6);
Vector2[] verts = hex.GetXnaVertices(LengthUnit.Meter, Ratio.FromDecimalFractions(64.0));
// verts has 6 elements
GetXnaVertices(Polygon2, LengthUnit)
Returns the vertices of polygon as an array of XNA
Microsoft.Xna.Framework.Vector2 values, with positions expressed in unit
and multiplied by scale.
The vertices are in the same order as Vertices. Pass this array to a polygon renderer or line-strip draw call.
public static Vector2[] GetXnaVertices(this Polygon2 polygon, LengthUnit unit)
Parameters
polygonPolygon2The polygon to convert.
unitLengthUnitThe length unit to express positions in.
Returns
- Vector2[]
A Microsoft.Xna.Framework.Vector2 array with the same number of elements as Vertices.
Examples
var center = LengthPoint2.Origin;
var hex = Polygon2.CreateRegular(center, Length.FromMeters(2), 6);
Vector2[] verts = hex.GetXnaVertices(LengthUnit.Meter, Ratio.FromDecimalFractions(64.0));
// verts has 6 elements
GetXnaVertices(Polygon2, LengthUnit, Ratio)
Returns the vertices of polygon as an array of XNA
Microsoft.Xna.Framework.Vector2 values, with positions expressed in unit
and multiplied by scale.
The vertices are in the same order as Vertices. Pass this array to a polygon renderer or line-strip draw call.
public static Vector2[] GetXnaVertices(this Polygon2 polygon, LengthUnit unit, Ratio scale)
Parameters
polygonPolygon2The polygon to convert.
unitLengthUnitThe length unit to express positions in.
scaleRatioPixels per unit.
Returns
- Vector2[]
A Microsoft.Xna.Framework.Vector2 array with the same number of elements as Vertices.
Examples
var center = LengthPoint2.Origin;
var hex = Polygon2.CreateRegular(center, Length.FromMeters(2), 6);
Vector2[] verts = hex.GetXnaVertices(LengthUnit.Meter, Ratio.FromDecimalFractions(64.0));
// verts has 6 elements
GetXnaVertices(Triangle2)
Returns the three vertices of triangle as an array of XNA
Microsoft.Xna.Framework.Vector2 values in the order [A, B, C], with components expressed in
unit and multiplied by scale.
public static Vector2[] GetXnaVertices(this Triangle2 triangle)
Parameters
triangleTriangle2The triangle to convert.
Returns
- Vector2[]
A Microsoft.Xna.Framework.Vector2 array of length 3: [A, B, C].
Examples
var tri = new Triangle2(
LengthPoint2.FromMeters(0, 0),
LengthPoint2.FromMeters(4, 0),
LengthPoint2.FromMeters(2, 3));
Vector2[] verts = tri.GetXnaVertices(LengthUnit.Meter, Ratio.FromDecimalFractions(64.0));
GetXnaVertices(Triangle2, LengthUnit)
Returns the three vertices of triangle as an array of XNA
Microsoft.Xna.Framework.Vector2 values in the order [A, B, C], with components expressed in
unit and multiplied by scale.
public static Vector2[] GetXnaVertices(this Triangle2 triangle, LengthUnit unit)
Parameters
triangleTriangle2The triangle to convert.
unitLengthUnitThe length unit to express positions in.
Returns
- Vector2[]
A Microsoft.Xna.Framework.Vector2 array of length 3: [A, B, C].
Examples
var tri = new Triangle2(
LengthPoint2.FromMeters(0, 0),
LengthPoint2.FromMeters(4, 0),
LengthPoint2.FromMeters(2, 3));
Vector2[] verts = tri.GetXnaVertices(LengthUnit.Meter, Ratio.FromDecimalFractions(64.0));
GetXnaVertices(Triangle2, LengthUnit, Ratio)
Returns the three vertices of triangle as an array of XNA
Microsoft.Xna.Framework.Vector2 values in the order [A, B, C], with components expressed in
unit and multiplied by scale.
public static Vector2[] GetXnaVertices(this Triangle2 triangle, LengthUnit unit, Ratio scale)
Parameters
triangleTriangle2The triangle to convert.
unitLengthUnitThe length unit to express positions in.
scaleRatioPixels per unit.
Returns
- Vector2[]
A Microsoft.Xna.Framework.Vector2 array of length 3: [A, B, C].
Examples
var tri = new Triangle2(
LengthPoint2.FromMeters(0, 0),
LengthPoint2.FromMeters(4, 0),
LengthPoint2.FromMeters(2, 3));
Vector2[] verts = tri.GetXnaVertices(LengthUnit.Meter, Ratio.FromDecimalFractions(64.0));
ToXnaRotation(Direction2)
Returns the angle of directional as a float in
radians, suitable for use as an XNA rotation parameter (e.g. in
SpriteBatch.Draw).
East (0°) maps to 0 radians, North (90°) maps to π/2 radians, and so on. Note that XNA's coordinate system has Y pointing downward; if your world uses Y-up you may need to negate this value at the call site.
public static float ToXnaRotation(this Direction2 directional)
Parameters
directionalDirection2The direction to convert.
Returns
Examples
float rot = Direction2.North.ToXnaRotation(); // MathF.PI / 2
// doctest-compile-only
float rot = Direction2.North.ToXnaRotation();
spriteBatch.Draw(texture, position, null, Color.White, rot, origin, 1f, SpriteEffects.None, 0f);