[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: A QUESTION (drawing cubes)
On Thu, 3 Nov 2005, sanjay norway wrote:
> I want to make a cube and want to put some slabs (3d
> rectangular objects) in it.
>
> I tried to proceed as follows:
> 1. path(P(0,0,0),P(6,0,0),....,P(6,6,6));
> //It may create a cube.
> 2. Now put a slab of dimension 6 by 6 by 1
> path(P(0,0,1),P(6,0,1),.....,P(6,6,2));
>
> I would appreciate if I can get help in making such a
> picture.
>
Unfortunately, ePiX-1 isn't very good at doing what you want; you must
build up the figure in layers (back to front) manually for object hiding
to work.. (ePiX-2 will do this sort of thing much more easily.)
For your purposes, it's probably best to write a function that draws a
slab given a pair of opposite corners. Depending on your needs, you could
draw the entire frame, just the visible portion of the frame (assuming
filled but unshaded faces), or filled, gray-shaded faces (this is
relatively easy since slabs are convex). The attached file slab.xp
contains a quick hack for the wireframe.
You might also want to try ePiX-2.0pre (still in a very preliminary
state). The file slab2.xp contains a first attempt at slabs, using the
current input syntax.
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)
/* -*-ePiX-*- */
#include "epix.h"
using namespace ePiX;
void slab(P pt0, P pt1)                                                        
{
  double min_x = min(pt0.x1(), pt1.x1()), max_x = max(pt0.x1(), pt1.x1());
  double min_y = min(pt0.x2(), pt1.x2()), max_y = max(pt0.x2(), pt1.x2());
  double min_z = min(pt0.x3(), pt1.x3()), max_z = max(pt0.x3(), pt1.x3());
  rect(P(min_x,min_y,min_z), P(max_x,max_y,min_z));
  rect(P(min_x,min_y,min_z), P(max_x,min_y,max_z));
  rect(P(max_x,max_y,min_z), P(min_x,max_y,max_z));
  rect(P(min_x,min_y,max_z), P(max_x,max_y,max_z));
}
double MAX=10;
int main() 
{
  bounding_box(P(-MAX,-MAX),P(MAX,MAX));
  unitlength("1in");
  picture(6,6);
  begin();
  camera.at(P(20,5,10));
  slab(P(0,0,0), P(6,6,6));
  bold();
  slab(P(0,0,1), P(6,6,2));
  end();
}
/* -*-ePiX-*- */
#include "epix2.h"
using namespace ePiX2;
//#define FACE_COLOR
//#define EDGE_COLOR
// to be put into some initialization code eventually
namespace ePiX2{
  double epix_angle_units = M_PI/180; // angles in degrees
}
double MAX=10; // Cartesian size of bounding box
int main() { 
  // declare a blank (3-D) "slate"
  Picture world; 
  // analogous to old "bounding_box"
  world.bounding_box(Pair(-MAX,-MAX), Pair(MAX,MAX));
  // same as old "picture"
  picture(Pair(6,6));
  world.lens(perspective);
  Cube block0(Point(0,0,0), Point(6,6,6));
  Cube block1(Point(0,0,0), Point(6,6,1));
#ifdef FACE_COLOR
  block1.red(0.8);
#endif
#ifdef EDGE_COLOR
  block0.green0();
  block1.red0(0.8);
#endif
  block0.skeleton();  // show edges only
  block1.rotate(45, E_1());
  block1 += E_3();
  world << block0 << block1;
  world.photo();
  world.print();
  return 0;
}
- References:
- A QUESTION
- From: sanjay norway <norway_1976@yahoo.com>