# How to map points onto a shape in P3D mode?

**URL:** <https://discourse.processing.org/t/how-to-map-points-onto-a-shape-in-p3d-mode/19488>\
**Category:** Coding Questions\
**Created:** [April 7, 2020, 2:07am UTC](https://discourse.processing.org/t/how-to-map-points-onto-a-shape-in-p3d-mode/19488 "2020-04-07T02:07:11Z")\
**Posts on this page:** 1\
**Showing post:** 2

<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:** [April 7, 2020, 3:43am UTC](https://discourse.processing.org/t/how-to-map-points-onto-a-shape-in-p3d-mode/19488/2 "2020-04-07T03:43:33Z")

</div>

Hello,

I have never worked with the bezier() function in 3D so I took this out for a spin.

Here is an example I worked through to understand this:

```auto
float x1, y1, z1, x2, y2, z2;

void setup() 
  {
  size(1000, 800, P3D);
  }

void draw() 
  {
  background(255);
  //noStroke();
  strokeWeight(3);
  //translate(350, 600, -50);
  rotateX(PI/8);
  
  rectMode(CENTER);
  rect(width/2, height/2, 700, 100);
 
  noFill();
  float zOff = map(mouseY, 0, height, 300, 0); // Move mouse up and down
  
  //left point
  x1 = width/4;
  y1 = height/2;
  z1 = 0;
 
  //right point 
  x2 = 3*width/4;
  y2 = height/2;
  z2 = 0;
  
  //manual lerping
  float a = (x2-x1)/3;
  float b = (y2-y1)/3;
  
 pushMatrix();    
  stroke(#F05252);
  bezier(x1, y1, z1, // First point
         x1 + a, y1 + b, z1 + zOff, // First intermediate point
         x2 - a, y2 - b, z2 + zOff, // Second intermediate point
         x2, y2, z2); // Final point
 popMatrix();   
  }

```

I gave a lot of thougt to where the points were along the axis.

I did some manual lerping in my example.

There is a function for this:  
[https://processing.org/reference/lerp\_.html](https://processing.org/reference/lerp_.html)

Linear interpolation:

> **[Linear interpolation](https://en.wikipedia.org/wiki/Linear_interpolation)**
>
> In mathematics, linear interpolation is a method of curve fitting using linear polynomials to construct new data points within the range of a discrete set of known data points.
> If the two known points are given by the coordinates 
>   
>     
>       
> (
>         
> x
>           
> 0
>           
>         
> ,
>         
> y
>           
> 0
>           
>         
> )
>       
>     
> {\\displaystyle (x\_{0},y\_{0})}
>   
> and 
>   
>     
>       
> (
>         
> ...

I hope this helps.

`:)`

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

I may have to try this with my related post [here](https://discourse.processing.org/t/trying-curve-on-a-sphere-cant-seem-to-get-the-rise-and-fall-of-the-curve-right/19355/4) (no code please).

---

_[View the full topic](https://discourse.processing.org/t/how-to-map-points-onto-a-shape-in-p3d-mode/19488)._
