epix-users
[Top][All Lists]
Advanced

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

Re: [ePiX-users] drawing cylinder with epix


From: Andrew D. Hwang
Subject: Re: [ePiX-users] drawing cylinder with epix
Date: Thu, 27 Sep 2007 21:56:07 -0400 (EDT)

On Wed, 26 Sep 2007, Math Plot wrote:

I am new to the epix. So, my question may be too naive for you.

Not at all, though the question belongs here on the user list, not on the development list. :)

We want to draw cylinder in two positions: horizontal and vertical. The top and bottom of cylinder may be circle or ellipse. We also want to emphasize the liquid level inside the cylinder with some color.

The approach to take depends on your needs. For example,

* Do you want to draw stylized test tubes (graduated cylinders, etc.) or simply "bare" cylinders partly filled with fluid?

* Do you need true 3-D to draw tubes in various spatial orientations, or can you use a partially shaded 2-D outline?


The simplest but least flexible approach is to make a quick sketch (with pencil and paper), then to translate this into 2-D drawing commands. A first attempt at test tubes is included below. (The results look all right to me, but the code is neither pretty nor robust.)

It may be worth writing a "tube" class whose parameters (position, radius, length, amount and color of fluid, etc.) are set by member functions. This buys flexibility at the expense of effort and programing knowledge.

Hope that's helpful in getting started; feel free to ask if you have more
questions.

Andrew D. Hwang                 address@hidden
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)

/* -*-ePiX-*- */
#include "epix.h"
using namespace ePiX;

// Stylized test tube of given radius, height, and fluid level; bottom of // tube is a semi-circle with given center. The "ratio" controls fake
// perspective.
void test_tube(const P& ctr, double rad, double ht,
               double level, double ratio=0.1)
{
  plain();
  fill();
  // draw (2-D) outline of liquid, for shading
  path liquid(ctr, P(rad,0), P(0,rad), -M_PI, 0); // bottom of tube
  liquid += path(ctr+P(rad,0), ctr+P(rad,level)); // side of tube

  // will cover this with an ellipse momentarily
  liquid += path(ctr+P(rad,level), ctr+P(-rad, level));

  liquid += path(ctr+P(-rad,level), ctr+P(-rad,0)); // other side
  liquid.close().fill().draw();

  ellipse(ctr+P(0,level), P(rad, 2*rad*ratio)); // top surface of liquid

  // re-draw tube outline
  nofill();
  bold();
  ellipse_bottom(ctr, P(rad, rad));
  line(ctr+P(rad,0), ctr+P(rad,ht));
  line(ctr+P(-rad,0), ctr+P(-rad,ht));
  ellipse(ctr+P(0,ht), P(rad, ratio*rad));

  // and lip at top
  bbold();
  ellipse(ctr+P(0,ht), P(rad+0.0125, ratio*rad));
}

int main()
{
  picture(P(-1,-3), P(1,3), "2x6in");

  begin();
  pst_format();

  fill(Red(1.8));
  test_tube(P(-0.75, -2.5), 0.25, 5, 3);

  fill(Blue(1.8));
  test_tube(P(0.5, -2.5), 0.5, 4, 1.5);

  end();
}




reply via email to

[Prev in Thread] Current Thread [Next in Thread]