# Help with making vector array with specified coordinates

Hello. I would like help implementing this idea from C# code to processing

``````private Point[] grads = new Point[] {
new Point(0, 1), new Point(1, 1), new Point(1, 0), new Point(1, -1),
new Point(0, -1), new Point(-1, -1), new Point(-1, 0), new Point(-1, 1),};

``````

This is the piece of C# code

A PVector array where i can define a new PVector and set the coordiantes of x and y. i want to make 8 vectors where i define x and y.
i tried this but i do not believe it is correct:

``````PVector[] gradients = {
new PVector(0, 1),
new PVector(1, 1),
new PVector(1,0),
new PVector(1,-1),
new PVector(0,-1),
new PVector(-1,-1),
new PVector(-1,0),
new PVector(-1,1),
};
``````

if you do println(gradients) in setup you get this output

``````[ 0.0, 1.0, 0.0 ] [ 1.0, 1.0, 0.0 ] [ 1.0, 0.0, 0.0 ] [ 1.0, -1.0, 0.0 ] [ 0.0, -1.0, 0.0 ] [ -1.0, -1.0, 0.0 ] [ -1.0, 0.0, 0.0 ] [ -1.0, 1.0, 0.0 ]

``````

I donâ€™t believe this is correct because this seems to be a three dimensions.

Thank you for any help.

1 Like

Hi,

thatâ€™s ok, a PVector always has a z, but as long as it is zero, it does not affect any calculations.

3 Likes

f you prefer just x & y only, you can use Javaâ€™s bundled classes Point or Point2D.Float:

However, they donâ€™t have as many methods as Processingâ€™s own PVector:

But Processing got some 3rd-party libs w/ their own 2D coord container like Box2D-for-Processing:

Which wraps the library JBox2D and its classes like Vec2:

Another worth mentioning library is HE-Mesh:

Which got 2d coord container class WB_Vector2D:

1 Like

Here is an example

Chrisir

``````

new PVector(0, 1),
new PVector(1, 1),
new PVector(1, 0),
new PVector(1, -1),
new PVector(0, -1),
new PVector(-1, -1),
new PVector(-1, 0),
new PVector(-1, 1),
};

void setup() {
size(670, 670);