# Using Vertex in for loop to generate a curve

**URL:** <https://discourse.processing.org/t/using-vertex-in-for-loop-to-generate-a-curve/29964>\
**Category:** Coding Questions\
**Created:** [May 8, 2021, 4:07pm UTC](https://discourse.processing.org/t/using-vertex-in-for-loop-to-generate-a-curve/29964 "2021-05-08T16:07:02Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![ChadKagan](https://avatars.discourse-cdn.com/v4/letter/c/ecae2f/32.png) [@ChadKagan](https://discourse.processing.org/u/ChadKagan)\
**Post date:** [May 8, 2021, 4:07pm UTC](https://discourse.processing.org/t/using-vertex-in-for-loop-to-generate-a-curve/29964/1 "2021-05-08T16:07:02Z")

</div>

Hello,  
We are trying to draw a curve based on a formula that takes control points clicked on a canvas and generates a cubic B Spline curve. Our functions generate a series of points that should lie on the curve, but the vertex function will not draw the curve.

Our code can be seen here: [p5.js Web Editor](https://editor.p5js.org/Ckagan1120/sketches/ZmC8S5idJ)

When evaluating the code, focus on the the CubicBSpline\_1 function as well as the Draw\_BSpline\_1 function, and click 3 points on the canvas to see their results.

We greatly appreciate your help!

---

<div class="post-metadata">

**Author:** ![micuat](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/micuat/32/19407_2.png) [@micuat](https://discourse.processing.org/u/micuat)\
**Post date:** [May 8, 2021, 5:43pm UTC](https://discourse.processing.org/t/using-vertex-in-for-loop-to-generate-a-curve/29964/2 "2021-05-08T17:43:59Z")

</div>

Hi! Welcome to the forum!

Sorry but what is the question? to add curves?

Also the category Processing is for the Java platform so you should change it to p5.js 🙂

---

<div class="post-metadata">

**Author:** ![ChadKagan](https://avatars.discourse-cdn.com/v4/letter/c/ecae2f/32.png) [@ChadKagan](https://discourse.processing.org/u/ChadKagan)\
**Post date:** [May 8, 2021, 6:01pm UTC](https://discourse.processing.org/t/using-vertex-in-for-loop-to-generate-a-curve/29964/4 "2021-05-08T18:01:22Z")

</div>

Hello!

We are trying to generate a curve (in the draw\_BSpline\_1 function) using the points generated in the cubicBSpline\_1 function. The print(tempPoint) command in the draw function yields the points that we would like to use to generate the curve, but the vertex command is not making the curve. We have been working on this for a while and have no idea why the curve won’t generate.

Thanks a lot for your help.

---

<div class="post-metadata">

**Author:** ![micuat](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/micuat/32/19407_2.png) [@micuat](https://discourse.processing.org/u/micuat)\
**Post date:** [May 8, 2021, 7:11pm UTC](https://discourse.processing.org/t/using-vertex-in-for-loop-to-generate-a-curve/29964/5 "2021-05-08T19:11:56Z")

</div>

I checked the code, and I see in some lines you do something like

```javascript
vertex(tempPoint_i);

```

but actually `tempPoint` are objects. You need to decompose it to

```javascript
vertex(tempPoint_i.x._data[0], tempPoint_i.y._data[0]);

```

---

<div class="post-metadata">

**Author:** ![ChadKagan](https://avatars.discourse-cdn.com/v4/letter/c/ecae2f/32.png) [@ChadKagan](https://discourse.processing.org/u/ChadKagan)\
**Post date:** [May 8, 2021, 8:43pm UTC](https://discourse.processing.org/t/using-vertex-in-for-loop-to-generate-a-curve/29964/6 "2021-05-08T20:43:27Z")

</div>

Thank you so much! That got us through the issue we’ve been stuck on for a long time. Now it presents more problems, though. I may be back here if we can’t get through it, but we’ll try our best. Thanks again!
