Maregas
Maregas

Reputation: 33

C# Convert Vector3d/Point3d to double[]

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];

Upvotes: 2

Views: 1552

Answers (2)

René Vogt
René Vogt

Reputation: 43886

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};

Upvotes: 2

Sergey Kalinichenko
Sergey Kalinichenko

Reputation: 726619

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};

Upvotes: 2

Related Questions