Polarlines_movement_toxiclibs
in
Contributed Library Questions
•
4 months ago
Hi,
I am trying to modify toxiclibs script polar lines
I have two points:
Red point - start;
Blue point - end;
The path of the point is linear function from red to blue point.
What I am seeking to do is to move red point along the path, when the red point reaches the end it bounces back and goes back in the point till it reaches start point the bounces again.
I know that there is possibility somehow to get the direction of this path.
My question:
How to find directionality or velocity vector from red to blue point?
And how to define boundaries that the point would only bounce from red to blue point?
Actually it is only simple movement called point on curve.
Maybe there is another script, that simplifies what I seeking: simple linear curve and point on it, and according to draw function and moves along a curve the bounces back when it reaches the end points?
- import toxi.geom.*;
- Vec2D velocity;
- void setup() {
- size(400, 400);
- smooth();
- velocity = new Vec2D(10, 10);
- }
- void draw() {
- background(255);
- translate(width/2, height/2);
- stroke(255, 0, 0);
- strokeWeight(2);
- // start point at radius 10, 0 degrees
- Vec2D a=new Vec2D(10, 0);
- // end point at mouse position
- Vec2D b=new Vec2D(350, 100).sub(width/2, height/2).toPolar();
- // force at least 1 full turn to create spiral
- b.y+=4*PI;
- // draw a line from a -> b in CARTESIAN space
- // transfer points into cartesian space
- a.toCartesian();
- b.toCartesian();
- stroke(0, 0, 255);
- // calculate intermediate points
- for (int i=0,num=10; i<num; i++) {
- // interpolation already happens in cartesian space
- // no further conversion needed
- Vec2D p=a.interpolateTo(b, (float)i/num);
- point(p.x, p.y);
- //ellipse movement start point
- ellipse(a.x, a.y, 10, 10);
- //ellipse movement end point
- if(i==9){
- stroke(255,0,0);
- ellipse(p.x, p.y, 10, 10);
- }
- }
- }
1