# Help with classes and hexagon

**URL:** <https://discourse.processing.org/t/help-with-classes-and-hexagon/22510>\
**Category:** Coding Questions\
**Created:** [July 9, 2020, 2:34pm UTC](https://discourse.processing.org/t/help-with-classes-and-hexagon/22510 "2020-07-09T14:34:04Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jensemand](https://avatars.discourse-cdn.com/v4/letter/j/b38774/32.png) [@jensemand](https://discourse.processing.org/u/jensemand)\
**Post date:** [July 9, 2020, 2:34pm UTC](https://discourse.processing.org/t/help-with-classes-and-hexagon/22510/1 "2020-07-09T14:34:04Z")

</div>

Hi I have tried to make a hexagon by using vectors however when I try to put the shape into a class (so I later can make a grid where I can detect in which one my mouse is in) but the problem is I can’t display my shape. Down below is my code and if you can find the mistake… please tell me where it is. It would be of great help. THANK YOU 🙂

> form hexagon;  
> void setup(){  
> hexagon=new form();  
> size(800,800);  
> }  
> void draw(){  
> background(255);  
> line(width/2,0,width/2,height);  
> line(0,height/2,width,height/2);  
> hexagon.display();  
> }  
> class form{  
> PVector center;  
> PVector b;  
> float angle;  
> float a;  
> int npoints;  
> int r=15;  
> form(){  
> npoints=6;  
> angle=TWO\_PI/npoints;  
> //PVector center=new PVector(width/2,height/2);  
> }  
> void display(){  
> PVector center=new PVector(width/2,height/2);  
> line(0,0,center.x,center.y);  
> beginShape();  
> for (a=0; a\<TWO\_PI; a+=angle){  
> b=center.add(center.x+ cos(a)\*r,center.y+ sin(a)\*r);  
> vertex(b.x,b.y);  
> }  
> endShape(CLOSE);  
> }  
> }

---

<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:** [July 9, 2020, 3:05pm UTC](https://discourse.processing.org/t/help-with-classes-and-hexagon/22510/2 "2020-07-09T15:05:58Z")

</div>

You add center twice in the PVector

---

<div class="post-metadata">

**Author:** ![Spaceman1](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/spaceman1/32/9970_2.png) [@Spaceman1](https://discourse.processing.org/u/Spaceman1)\
**Post date:** [July 9, 2020, 6:04pm UTC](https://discourse.processing.org/t/help-with-classes-and-hexagon/22510/3 "2020-07-09T18:04:01Z")

</div>

I think there are two mistakes in the display function  
`PVector center=new PVector(width/2,height/2);`  
You define the variable center again which is unnecessary, but does not affect the functionality of the code.

`b=center.add(center.x+ cos(a)*r,center.y+ sin(a)*r);`

The function alrready adds the x and y of center there is no need to do this yourself.
