drawing the tangent of a circle
in
Programming Questions
•
3 years ago
hi guys
i have banal problem.
i have a circumference and i want to draw the tangent in the first point.
i'm boiling my brain.
Vec3D is my class that extends PVector, but for now it does nothing.
the tangent drawn is a line that go in 0,0,0.
what happend???
: (
- import processing.opengl.*;
- import peasy.*;
- PeasyCam cam;
- Vec3D points[];
- Vec3D tangents[];
- Vec3D binormals[];
- Vec3D normals[];
- void setup() {
- size(600,600, OPENGL);
- cam = new PeasyCam(this, 800);
- points = new Vec3D[100];
- tangents = new Vec3D[100];
- binormals = new Vec3D[100];
- normals = new Vec3D[100];
- // points
- float theta = 0;
- for (int i=0; i<100; i++) {
- float x = cos(theta)*200;
- float y = sin(theta)*200;
- float z = 0;
- theta += 0.1;
- points[i] = new Vec3D(x,y,z);
- }
- // first frame:
- Vec3D p0 = points[0];
- Vec3D p1 = points[1];
- println(p0);
- println(p1);
- tangents[0] = getTangentBetweenTwoPoint(p1, p0);
- println(tangents[0]);
- }
- void draw() {
- background(0);
- // draw curve
- stroke(100);
- noFill();
- beginShape();
- for(int i=0; i<100; i++) {
- vertex(points[i].x, points[i].y, points[i].z);
- }
- endShape();
- //draw first frame
- beginShape();
- vertex(points[0].x, points[0].y, points[0].z);
- vertex(tangents[0].x, tangents[0].y, tangents[0].z);
- endShape();
- }
- Vec3D getTangentBetweenTwoPoint(Vec3D p1, Vec3D p2) {
- Vec3D r = new Vec3D(
- p1.x-p2.x,
- p1.y-p2.y,
- p1.z-p2.z);
- //r.normalize();
- return r;
- }
2