2

I need a double[] and I have a Point3d or a Vector3d. How can I convert a Point or a Vector to a double[]? I create the Point and the Vector with following Code:

Point3d pos1 = new Point3d();
Point3d pos2 = new Point3d();
GetPosition(out pos1, out pos2);
Vector3d a = new Vector3d(pos1.X, pos1.Y, pos1.Z);

double[] move_mapped = new double[3];
Maregas
  • 33
  • 4
  • 4
    Possible duplicate of [All possible C# array initialization syntaxes](https://stackoverflow.com/questions/5678216/all-possible-c-sharp-array-initialization-syntaxes) – Blake Thingstad Dec 14 '17 at 15:00

2 Answers2

2

You can use [] initializer syntax, like this:

double[] move_mapped = new double[] {
    pos1.X, pos1.Y, pos1.Z
};

The same syntax works for Vector3d. You can also use a "shortcut" syntax:

var move_mapped = new[] {a.X, a.Y, a.Z};
Sergey Kalinichenko
  • 714,442
  • 84
  • 1,110
  • 1,523
2

As simple as you instantiated the Vector3d:

double[] move_mapped = new double[] {pos1.X, pos1.Y, pos1.Z};

or with the shorter array initializer

double[] move_mapped = {pos1.X, pos1.Y, pos1.Z};
René Vogt
  • 43,056
  • 14
  • 77
  • 99