14

Is there a built in type Point3 in .Net? Some kind of this

public class Point3D
{
    public double X { get; set; }
    public double Y { get; set; }
    public double Z { get; set; }
}

but built in. It is not hard to implement it myself, but..

steavy
  • 1,483
  • 6
  • 19
  • 42

3 Answers3

11

System.Windows.Forms.DataVisualization.Charting has a class Point3D

  • float X, Y, Z
  • System.Windows.Forms.DataVisualization.dll (WinForms)
  • .NET Framework >= 4.0

System.Windows.Media.Media3D has a struct Point3D

  • double X, Y, Z
  • PresentationCore.dll (WPF)
  • .NET Framework >= 3.0
  • .NET Core >= 3.0

I know that Vector3D is not a Point3D, but if you just want a struct with X, Y, Z:

System.Windows.Media.Media3D has a struct Vector3D

  • double X, Y, Z
  • PresentationCore.dll (WPF)
  • .NET Framework >= 3.0
  • .NET Core >= 3.0

System.Numerics has a struct Vector3

  • float X, Y, Z
  • System.Numerics.dll
  • .NET Framework >= 4.6
  • .NET Core >= 1.0

Only System.Numerics.Vector3 does NOT depend on WinForms or WPF!

Jinjinov
  • 2,554
  • 4
  • 26
  • 45
  • Perhaps worth noting, `System.Windows.Media.Media3D` also contains `Matrix3D` and `Quaternion`, so if you intend to do any transformations on your points, it's probably the correct choice. – primo May 21 '22 at 10:17
  • is there any benefit to using these structures vs rolling my own? – john k Mar 09 '23 at 03:03
  • @johnktejik you can use many useful methods like https://learn.microsoft.com/en-us/dotnet/api/system.numerics.vector3?view=net-8.0#methods – Jinjinov Mar 09 '23 at 13:14
10

System.Windows.Forms.DataVisualization.Charting has Point3D class.

Represents the coordinates of a three-dimensional (3D) data point. This class is used when performing custom drawing with 3D charts.

  • X     Gets or sets the X coordinate of a 3D point.
  • Y     Gets or sets the Y coordinate of a 3D point.
  • Z     Gets or sets the Z coordinate of a 3D point.

Also has Point3D structure.

Represents an x-, y-, and z-coordinate point in 3-D space.

ToolmakerSteve
  • 18,547
  • 14
  • 94
  • 196
Soner Gönül
  • 97,193
  • 102
  • 206
  • 364
  • 11
    True enough. But if your code does not already use one of these libraries, it would be silly to add a dependency on them for such a simple data-storage class. Just define it yourself. – Cody Gray - on strike Apr 07 '13 at 10:39
  • I realize I'm late to the party on this one but another advantage of you own class is that you can make it handle unit conversions if necessary. – Terry Tyson Sep 17 '19 at 14:22
  • @TerryTyson - or use a built-in class, and define extension methods. – ToolmakerSteve Nov 04 '21 at 18:28
3
  • DirectX has a Microsoft.DirectX.Vector3 Structure, but will it be overkill for your application?
  • XNA has class Microsoft.XNA.Framework.Vector3
  • Unity3D has a Vector3 class for Representation of 3D vectors and points.
  • OpenTK also represents a 3D vector using three single-precision floating-point numbers.
David
  • 15,894
  • 22
  • 55
  • 66