cos = x, sin = y, z = ?
in
Programming Questions
•
1 year ago
what is common to use for the z axis, sin or cos?
And is the rest of my code correct, somehow i expect them to be a bit different?
(requires peasycam to run)
- import processing.opengl.*;
- import peasy.*;
- PeasyCam camera;
- // coordinates for the bezier
- float x1 = 72;
- float y1 = 127;
- float z1 = 200;
- float cx1 = 57;
- float cy1 = 190;
- float cz1 = 0;
- float cx2 = 517;
- float cy2 = 104;
- float cz2 = 0;
- float x2 = 283;
- float y2 = 273;
- float z2 = 80;
- void setup() {
- size(500, 500, OPENGL);
- smooth();
- camera = new PeasyCam(this, width/2, height/2, 0, int((height/2.0)/tan(PI*60.0/360)));
- }
- void draw() {
- background(0);
- lights();
- noFill();
- stroke(255);
- bezier(x1, y1, z1, cx1, cy1, cz1, cx2, cy2, cz2, x2, y2, z2);
- int steps = 10;
- PVector bp, bt; // bezierPoint, bezierTangent
- noStroke();
- fill(255, 0, 0);
- for (int i = 0; i <= steps; i++) {
- float t = i / (float)steps;
- bp = bezierPoint(x1, y1, z1, cx1, cy1, cz1, cx2, cy2, cz2, x2, y2, z2, t);
- bt = bezierTangent(x1, y1, z1, cx1, cy1, cz1, cx2, cy2, cz2, x2, y2, z2, t);
- float a1 = atan2(bt.y, bt.x);
- a1 += HALF_PI;
- // angle seen from xz
- float a2 = PApplet.atan2(bt.z, bt.x);
- a2 += PApplet.HALF_PI;
- stroke(0, 255, 0);
- line(bp.x, bp.y, bp.z, bp.x + cos(a1)*-8, bp.y + sin(a1)*-8, bp.z + sin(a2)*-8);
- }
- // handle lines
- stroke(0, 0, 255);
- line(x1, y1, z1, cx1, cy1, cz1);
- line(x2, y2, z2, cx2, cy2, cz2);
- }
- // . . . . . . . . . . . . . . . . . . . . . . . .
- PVector bezierPoint(float x1, float y1, float z1, float cx1, float cy1, float cz1, float cx2, float cy2, float cz2, float x2, float y2, float z2, float t) {
- PVector returnVector = new PVector();
- returnVector.x = bezierPoint(x1, cx1, cx2, x2, t);
- returnVector.y = bezierPoint(y1, cy1, cy2, y2, t);
- returnVector.z = bezierPoint(z1, cz1, cz2, z2, t);
- return returnVector;
- }
- // . . . . . . . . . . . . . . . . . . . . . . . .
- PVector bezierTangent(float x1, float y1, float z1, float cx1, float cy1, float cz1, float cx2, float cy2, float cz2, float x2, float y2, float z2, float t) {
- PVector returnVector = new PVector();
- returnVector.x = bezierTangent(x1, cx1, cx2, x2, t);
- returnVector.y = bezierTangent(y1, cy1, cy2, y2, t);
- returnVector.z = bezierTangent(z1, cz1, cz2, z2, t);
- return returnVector;
- }
1