How to map points onto a shape in P3D mode?

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:

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

Linear interpolation:

I hope this helps.

:)

I may have to try this with my related post here (no code please).

1 Like