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 › line across an ellipse
Page Index Toggle Pages: 1
line across an ellipse (Read 2595 times)
line across an ellipse
Jun 14th, 2010, 11:12am
 
I found this code for making random lines across a circle, but I don't know how to alter it to make lines across an ellipse.  Any help will be appreciated.

Quote:
  float theta = random(TWO_PI);
  float sx = cos(theta)*radius;
  float sy = sin(theta)*radius;

  float delta = theta + PI + random(-anglerange,anglerange);
  float sx2 = cos(delta)*radius;
  float sy2 = sin(delta)*radius;


  Line L = new Line(new PVector(sx,sy), new PVector(sx2,sy2));
  Lines.add(L);

Re: line across an ellipse
Reply #1 - Jun 14th, 2010, 12:42pm
 
Effectively  an ellipse has 2 radii which if we call the radiusX and radiusY then you can use

Code:
  float theta = random(TWO_PI);
 float sx = cos(theta)*radiusX;
 float sy = sin(theta)*radiusY;

float delta = theta + PI + random(-anglerange,anglerange);
 float sx2 = cos(delta)*radiusX;
 float sy2 = sin(delta)*radiusY;
Re: line across an ellipse
Reply #2 - Jun 14th, 2010, 1:57pm
 
perfect, thank you.

I should have been able to figure that out.
Re: line across an ellipse
Reply #3 - Jun 14th, 2010, 3:01pm
 
I appreciate the help.  I'm wondering how hard it would be to so the same with a sphere.
Re: line across an ellipse
Reply #4 - Jun 14th, 2010, 3:27pm
 
Just thinking aloud here, but any point on a sphere can be defined by two circles perpendicular to each other: i.e. set a random rotation on one axis around one circle and from that point rotate around the other axis...  though I'm sure there's a much more elegant mathematical solution.  In fact google gives plenty of results on this.  This is one for the maths geeks whilst this gives a more obvious option to implement...
Page Index Toggle Pages: 1