[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Help needed to plot parametric curves



On Sat, 1 Apr 2006, Nathaniel J. Schwartz wrote:

> I am new to programming, math and of course ePiX, but I'd like to plot
> the cycloid curve for a paper I'm doing.
>
> However, I can't figure out how to set up the function. I may be way off
> track here, but I made a function that returns points like so:
>
> P cycloid(double a, double t)
> {
>      double x = a*(t - Sin(t));
>      double y = a*(1 - Cos(t));
>      P xy = (x, y);
>      return xy;
> }
>
Dear Nathaniel,

The sample document may be of some help. In fact, it contains a cycloid
plot on pages 12-13! :)

Your function will work as is, but can also be simplified a bit:

P cycloid(double a, double t)
{
  return a*P(t - Sin(t), 1 - Cos(t));
}

To plot curves, you'll need to create a "domain" and plot "slices", see
the sample document. If you only want to plot for a few values of "a",
it's probably easier to do something like this:

double a=1;
P cycloid(double t)
{
  return a*P(t - Sin(t), 1 - Cos(t));
}
...
int main()
{
...
  plot(cycloid, 0, 4*M_PI, 120);

  a = 0.8;
  plot(cycloid, 0, 4*M_PI, 120);
...
}

Best,
Andy

Andrew D. Hwang			ahwang@mathcs.holycross.edu
Department of Math and CS	http://math.holycross.edu/~ahwang
College of the Holy Cross	(508) 793-2458 (Office: 320 Swords)
Worcester, MA, 01610-2395	(508) 793-3530 (fax)