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

Re: ePiX comments (what else?)



On 30 Aug 2002, Jay Belanger wrote:
Jay,

Glad to hear ePiX is working for you! I'll re-write the sections about
lengths in the manual, but your guess is correct: "unitlength" sets the
LaTeX unitlength, and "picture" sets the size of the LaTeX picture.

Regarding an "actual_size" function, is there a particular syntax that
seems natural to you, e.g., actual_size("4.5x3in")?

>
> There seem to be a few constructs that I would think would be pretty
> basic, but don't seem to be built in.  (One such thing is a curve
> which goes through a specified sequence of points.)
>
Do you have a specific curve in mind (e.g., a Lagrange polynomial, a
connect-the-dots path, a spline...)?

>
> 1) Is there a way of turning an integer to a string?  I want to take,
>    say, 3, and get back (not print) "3".
Kernighan and Ritchie (2nd ed) have this as an example, pp. 62--64. They
implement the conversion as two short functions; code is copied below.
(On a tangent, there are library functions for performing the reverse
conversion, should you ever need to.)

> 2) I needed a picture of an unpleasant function, and tried to draw the
>    graph of sin(1/x); it doesn't seem to be working, either it doesn't
>    look good, or if I put in a lot of sample points, it doesn't show
>    up.  Is there any way of drawing this in ePiX?
>
Try using "adplot", which attempts to place sample points at equally
spaced locations with respect to arc length along the graph. (sin(1/x)
was the test function for adaptive plotting:) If this doesn't give
acceptable results, you might try splitting the graph over two or more
intervals, to put more points where the oscillation is large. It may help
to use sin(recip(x)) instead of sin(1/x); the graph is nearly identical,
but you won't get "nan" (not a number) errors in the output if x=0 happens
to be a sample value. (Of course, if you split the graph over multiple
intervals, it's a good idea to use the endpoints to bound the graph away
from the origin anyway.) Finally, there's a limit on the number of points
a plot can contain; TeX often runs out of memory around 300 points, and
I've had xdvi refuse to display figures with more than about 700 points.
That may be why you're getting no output when the number of points is
large. Please post if you can't get an acceptable picture...

--Andy

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

--- Some C++ fragments, modified slightly from K&R ---

#include <string.h>

/* reverse: reverse string s in place */
void reverse (char s[])
{
  int c;

  for (int i=0, int j = strlen(s)-1; i<j; i++, j--)
    {
      c = s[i];
      s[i] = s[j];
      s[j] = c;
    }
}

/* itoa (int to array): convert n to characters in s */
void itoa(int n, char s[])
{
  int sign = n;
  int i = 0;
  if (sign < 0)
    n = -n;

  do /* generate digits in reverse order */
  {
    s[i++] = n % 10 + '0';
  } while ((n /= 10) > 0);

  if (sign < 0)
    s[i++] = '-';
  s[i] = '\0';
  reverse(s);
}

---
This works because '0' is the character representing 0 in ASCII, and the
integers are consecutive characters, so (n % 10 + '0') is n (mod 10) plus
the character '0', namely the last digit of n as a character. The "while"
condition (n /= 10) does integer division, effectively discarding the last
digit.