toxiclibs - tangent spline
in
Contributed Library Questions
•
1 year ago
If you click you add points. From that it creates some kind of curve.
What i want is to draw the tangent as well.
It should be possible to calculate it by it's neighbors i suppose.
I only don't know how to do it since a Iterator does not support previous().
Or is it possible to loop over this without a Iterator as well?
could someone help?
- import toxi.geom.*;
- ArrayList<Vec2D> deformVectors = new ArrayList<Vec2D>();
- Spline2D spline = new Spline2D();
- void setup() {
- size(400, 400);
- smooth();
- }
- void draw() {
- background(255);
- stroke(255, 0, 0);
- noFill();
- beginShape();
- for (Iterator i=spline.pointList.iterator(); i.hasNext();) {
- Vec2D v = (Vec2D)i.next();
- vertex(v.x, v.y);
- }
- endShape();
- stroke(0, 0, 255);
- if (deformVectors.size() > 2) {
- for (Iterator i = spline.getDecimatedVertices(5, false).iterator(); i.hasNext();) {
- Vec2D v = (Vec2D)i.next();
- line(v.x-2, v.y, v.x+2, v.y);
- line(v.x, v.y-2, v.x, v.y+2);
- // tangent ?
- }
- }
- }
- void mousePressed() {
- deformVectors.add(new Vec2D(mouseX, mouseY));
- spline = new Spline2D();
- for (Vec2D v : deformVectors) {
- spline.add(v);
- }
- }
1