# Issue trying to draw a cylinder

**URL:** https://discourse.processing.org/t/issue-trying-to-draw-a-cylinder/41984
**Category:** Coding Questions
**Created:** [May 13, 2023, 6:09pm UTC](https://discourse.processing.org/t/issue-trying-to-draw-a-cylinder/41984 "2023-05-13T18:09:18Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![alex119](https://avatars.discourse-cdn.com/v4/letter/a/e95f7d/32.png) [@alex119](https://discourse.processing.org/u/alex119)
#### Post date: [May 13, 2023, 6:09pm UTC](https://discourse.processing.org/t/issue-trying-to-draw-a-cylinder/41984/1 "2023-05-13T18:09:18Z")

</div>

Hello,

I am trying to draw a shape, like a cylinder, but the output is something like this:

 ![shape](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/3X/d/4/d4cd8adfa79c0bcc141df1e4689ded105889938b.png)

As you see, the last point is not matching the first point and I can’t figure out what I am doing wrong.  
Here is the code for this:

```auto
int rows = 12;
int cols = 7;

void setup() 
{
  size(1200, 800, P3D);

}

void draw()
{
  background(0);
  
  beginCamera();
  camera();
  rotateX(87);
  endCamera();
  
  
  lights();
  
  float angle = 0;
  
  stroke(255);
  fill(255, 0, 0);
  
  translate(width/2, height/2, 0.0);
  
  strokeWeight(2);
  stroke(0);
  for(int i = 0; i < rows - 1; i++)
  {
    beginShape(TRIANGLE_STRIP);
    for(int j = 0; j < cols; j++)
    {
      angle += TWO_PI/cols;
      vertex(j * 50 * sin(angle), i * 50, 50 * cos(angle));
      vertex(j * 50 * sin(angle), (i + 1) * 50, 50 * cos(angle));
      
      println("V1 -> X: " + j * 50 * sin(angle) + " Y: " + i * 50 + " Z: " + 50 * cos(angle));
      println("V2 -> X: " + j * 50 * sin(angle) + " Y: " + (i + 1) * 50 + " Z: " + 50 * cos(angle));
     }
    endShape();
    
  
  }
}

```

Hope you can help me solve this problem.  
Thank you! 😃

---

<div class="post-metadata">

### Author: ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)
#### Post date: [May 13, 2023, 6:22pm UTC](https://discourse.processing.org/t/issue-trying-to-draw-a-cylinder/41984/2 "2023-05-13T18:22:21Z")

</div>

Hello @alex119,

Give this a try:

```auto
    beginShape(TRIANGLE_STRIP);
    angle = 0;
    for (int j = 0; j <= cols; j++)
      {
      angle += TWO_PI/cols;
      vertex(5*50*sin(angle), i*50, 50*cos(angle));
      vertex(5*50 * sin(angle), (i + 1)*50, 50*cos(angle));
      }
    endShape()

```

Scrutinize changes.

 ![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/3X/1/4/14d21009f8b37fec824a2d6b49c0cd5930261740.png)

I did a very quick exploration… may need more work.

`:)`

---

<div class="post-metadata">

### Author: ![alex119](https://avatars.discourse-cdn.com/v4/letter/a/e95f7d/32.png) [@alex119](https://discourse.processing.org/u/alex119)
#### Post date: [May 13, 2023, 6:44pm UTC](https://discourse.processing.org/t/issue-trying-to-draw-a-cylinder/41984/3 "2023-05-13T18:44:14Z")

</div>

Wow, I don’t know why I used that “j” there.  
Thank you very much!

 ![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/3X/7/c/7c137838aec49c1887e67b697fdafde53167d4de.png)
