We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpPrograms › retrieve each point of a line
Page Index Toggle Pages: 1
retrieve each point of a line (Read 639 times)
retrieve each point of a line
Jan 23rd, 2008, 7:15am
 
hi all,

I have a simple 2D line defined by (x1, y1) and (x2, y2). I wish I could easily retrieve the (int) coordinates of each point (pixel) on this line.

Is there a better way than using my own line-algorithm?
Re: retrieve each point of a line
Reply #1 - Jan 23rd, 2008, 4:50pm
 
actually they should be accessible somewhere? until found, i'm using my hacked together vector class....

 public float length() {
   return PApplet.sqrt(x*x + y*y);
 }

 public Vector normalize() {
   return divide(length());
 }

 public Vector divide(float _divisor) {
   return new Vector(x/_divisor, y/_divisor);
 }
 
 public Vector sameDirWithLength(float _length) {
   return normalize().multiply(_length);
 
 }
Re: retrieve each point of a line
Reply #2 - Jan 23rd, 2008, 8:45pm
 
Given parametric "t" on [0..1], then:
float x = lerp(x1,x2,t);
float y = lerp(y1,y2,t);
(or convert to int as desired)
Page Index Toggle Pages: 1