# Help with making vector array with specified coordinates

**URL:** <https://discourse.processing.org/t/help-with-making-vector-array-with-specified-coordinates/17671>\
**Category:** Beginners\
**Created:** [February 9, 2020, 7:49pm UTC](https://discourse.processing.org/t/help-with-making-vector-array-with-specified-coordinates/17671 "2020-02-09T19:49:44Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dangeroustuber](https://avatars.discourse-cdn.com/v4/letter/d/dec6dc/32.png) [@Dangeroustuber](https://discourse.processing.org/u/Dangeroustuber)\
**Post date:** [February 9, 2020, 7:49pm UTC](https://discourse.processing.org/t/help-with-making-vector-array-with-specified-coordinates/17671/1 "2020-02-09T19:49:45Z")

</div>

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

```auto
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:

```auto
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

```auto
[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.

---

<div class="post-metadata">

**Author:** ![LuckSmith](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/lucksmith/32/5805_2.png) [@LuckSmith](https://discourse.processing.org/u/LuckSmith)\
**Post date:** [February 9, 2020, 9:10pm UTC](https://discourse.processing.org/t/help-with-making-vector-array-with-specified-coordinates/17671/2 "2020-02-09T21:10:19Z")

</div>

Hi,

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

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [February 10, 2020, 1:01am UTC](https://discourse.processing.org/t/help-with-making-vector-array-with-specified-coordinates/17671/3 "2020-02-10T01:01:11Z")

</div>

> [@Dangeroustuber](#):
>
> I don’t believe this is correct because this seems to be a three dimensions.

f you prefer just _x_ & _y_ only, you can use Java’s bundled classes Point or Point2D.Float:

1. [Point (Java SE 11 & JDK 11 )](http://Docs.Oracle.com/en/java/javase/11/docs/api/java.desktop/java/awt/Point.html)
2. [Point2D.Float (Java SE 11 & JDK 11 )](http://Docs.Oracle.com/en/java/javase/11/docs/api/java.desktop/java/awt/geom/Point2D.Float.html)

However, they don’t have as many methods as Processing’s own PVector:

> **[PVector / Reference](https://processing.org/reference/PVector.html)**
>
> A class to describe a two or three dimensional vector, specifically a Euclidean (also known as geometric) vector. A vector is an entity that has both magnitude and direction. The datatype, however, st…

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

> **[GitHub - shiffman/Box2D-for-Processing: Processing JBox2D helper library and...](https://github.com/shiffman/Box2D-for-Processing)**
>
> Processing JBox2D helper library and examples. Contribute to shiffman/Box2D-for-Processing development by creating an account on GitHub.

Which wraps the library JBox2D and its classes like Vec2:

> <https://github.com/jbox2d/jbox2d/blob/master/jbox2d-library/src/main/java/org/jbox2d/common/Vec2.java>

Another worth mentioning library is HE-Mesh:

> **[GitHub - wblut/HE\_Mesh](https://github.com/wblut/HE_Mesh)**
>
> Contribute to wblut/HE\_Mesh development by creating an account on GitHub.

Which got 2d coord container class WB\_Vector2D:

> <https://github.com/wblut/HE_Mesh/blob/master/src/core/wblut/geom/WB_Vector2D.java>

> <https://github.com/wblut/HE_Mesh/blob/master/src/core/wblut/geom/WB_MutableCoordinate2D.java>

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [February 10, 2020, 2:31pm UTC](https://discourse.processing.org/t/help-with-making-vector-array-with-specified-coordinates/17671/4 "2020-02-10T14:31:44Z")

</div>

Here is an example

Chrisir

```auto

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

void setup() {
  size(670, 670); 
  println(gradients) ;
  println();
  printArray(gradients) ;

  translate(300, 300); 
  stroke(0); 
  for (PVector pv : gradients) {
    line(0, 0, 
      pv.x*120, pv.y*120);
  }
  //
}

```
