# How to calculate good-looking bezier control points in 3D?

**URL:** <https://discourse.processing.org/t/how-to-calculate-good-looking-bezier-control-points-in-3d/28504>\
**Category:** Beginners\
**Created:** [March 13, 2021, 4:37pm UTC](https://discourse.processing.org/t/how-to-calculate-good-looking-bezier-control-points-in-3d/28504 "2021-03-13T16:37:43Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![tea\_tree](https://avatars.discourse-cdn.com/v4/letter/t/d6d6ee/32.png) [@tea\_tree](https://discourse.processing.org/u/tea_tree)\
**Post date:** [March 13, 2021, 4:37pm UTC](https://discourse.processing.org/t/how-to-calculate-good-looking-bezier-control-points-in-3d/28504/1 "2021-03-13T16:37:43Z")

</div>

I’d like to draw Bezier curves algorithmically, i.e. I’d like the control points to be functions of two data points. Assuming the following Bezier curve:

![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/e/eee69a93ad4df92f1497fb605460d90887a9868a.png)

I imagine P0, P1, and P2 form an obtuse triangle where the angle at P1, say β, is somewhere around 115 degrees. How do I find point P1 given that points P0 and P2 are determined by my data?

---

<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:** [March 13, 2021, 8:35pm UTC](https://discourse.processing.org/t/how-to-calculate-good-looking-bezier-control-points-in-3d/28504/2 "2021-03-13T20:35:30Z")

</div>

Do you really mean 3D?

This assume your plane / floor is in x/z and height is y

```auto
P1.x = (P0.x + P2.x) / 2;  
P1.y = P0.y - 140; 
P1.z = (P0.z + P2.z) / 2;

```

---

<div class="post-metadata">

**Author:** ![tea\_tree](https://avatars.discourse-cdn.com/v4/letter/t/d6d6ee/32.png) [@tea\_tree](https://discourse.processing.org/u/tea_tree)\
**Post date:** [March 13, 2021, 9:31pm UTC](https://discourse.processing.org/t/how-to-calculate-good-looking-bezier-control-points-in-3d/28504/3 "2021-03-13T21:31:15Z")

</div>

Yeah, I mean 3D. I know my drawing is 2D but that’s just for simplicity.

Your points work in principle but depending on how far apart the points are, I sometimes get a very heavy curvature and sometimes almost no curvature at all. Is there a way to make point P1 to be a function of the distance of P0 and P2? This way, I hope, the angle/curvature will be maintained.

---

<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:** [March 13, 2021, 9:43pm UTC](https://discourse.processing.org/t/how-to-calculate-good-looking-bezier-control-points-in-3d/28504/4 "2021-03-13T21:43:34Z")

</div>

unfortunately the angle is not sufficient to determine the position of P1 even in 2D  
[https://www.mathsisfun.com/geometry/circle-theorems.html](https://www.mathsisfun.com/geometry/circle-theorems.html)

so you need to set more constraints. for example, P0P1 == P1P2. But again this is not sufficient in 3D. To deal with these situations, for example, Catmull-Rom uses adjacent points as control points (implemented as `curveVertex` in processing)

> **[Centripetal Catmull–Rom spline](https://en.wikipedia.org/wiki/Centripetal_Catmull%E2%80%93Rom_spline)**
>
> In computer graphics, centripetal Catmull–Rom spline is a variant form of Catmull-Rom spline, originally formulated by Edwin Catmull and Raphael Rom, which can be evaluated using a recursive algorithm proposed by Barry and Goldman. It is a type of interpolating spline (a curve that goes through its control points) defined by four control points 
>   
>     
>       
>         
>           
> P
>           
>           
> 0
>           
>         
> ,
>         
>           
> Let 
> ...

---

<div class="post-metadata">

**Author:** ![tea\_tree](https://avatars.discourse-cdn.com/v4/letter/t/d6d6ee/32.png) [@tea\_tree](https://discourse.processing.org/u/tea_tree)\
**Post date:** [March 13, 2021, 9:55pm UTC](https://discourse.processing.org/t/how-to-calculate-good-looking-bezier-control-points-in-3d/28504/5 "2021-03-13T21:55:31Z")

</div>

Ah perfect, thanks! This is closer to what I’m looking for. Taking my 2D example from above, how could one create a line that just curves ever-so-slightly from a straight line between P0 and P2?

I have tried the following:

```auto
beginShape();
curveVertex(P0.x, P0.y, P0.z);
curveVertex(P2.x, P2.y, P2.z);
endShape();

```

I get curved lines from point P0 to P2 but they are bent very strongly and I’m wondering how I can tune down the curvature a bit, again not using a constant but by imputing a helpful in-between point (e.g. P1) that reduces the curvature.

---

<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:** [March 13, 2021, 10:26pm UTC](https://discourse.processing.org/t/how-to-calculate-good-looking-bezier-control-points-in-3d/28504/6 "2021-03-13T22:26:08Z")

</div>

I haven’t tried but `curveTightness` might do the job:  
[https://processing.org/reference/curveTightness\_.html](https://processing.org/reference/curveTightness_.html)

---

<div class="post-metadata">

**Author:** ![tea\_tree](https://avatars.discourse-cdn.com/v4/letter/t/d6d6ee/32.png) [@tea\_tree](https://discourse.processing.org/u/tea_tree)\
**Post date:** [March 13, 2021, 10:33pm UTC](https://discourse.processing.org/t/how-to-calculate-good-looking-bezier-control-points-in-3d/28504/7 "2021-03-13T22:33:24Z")

</div>

I came across it in this exact moment. It does do the job! Apparently, the apparent tightness depends on how far the points are apart. So I’m experimenting with 1/distanceBetweenPoints, 1/distanceBetweenPoints^2, etc. It seems to be working well.
