FAQ
Cover
This is the archive Discourse for the Processing (ALPHA) software.
Please visit the new Processing forum for current information.

   Processing 1.0 _ALPHA_
   Programming Questions & Help
   Programs
(Moderators: fry, REAS)
   HELP! connecting two boxes
« Previous topic | Next topic »

Pages: 1 
   Author  Topic: HELP! connecting two boxes  (Read 816 times)
Martin

122417302122417302martingomez_listsmg1ph WWW Email
HELP! connecting two boxes
« on: Mar 12th, 2003, 7:11pm »

um... ben, i think this one goes to you...
 
Code:
void setup()
{
  size(200,200);
  fill(255);
  smooth();
}
 
int r = 0;
 
void loop()
{
  translate(width/2,height/2);
  rotateY(radians(r));
   
  push();
  translate(-30,-30,-30);
  box(25);
  pop();
   
  push();
  translate(30,30,30);
  box(25);
  pop();
   
  if(r < 360) { r++; }
  else { r = 0; }  
   
  /***** how do i connect the two boxes *****
  ************ with a single line? **********
 
  translate(-30,-30,-30);
  line(0,0,10,10);
  translate(30,30,30);
  line(... blah.
   
  */
}

 
josh nimoy mentioned the use of applymatrix and other methods borrowed from opengl ... would anyone out there care to expound? thanks!
 
_martin
Guest
Email
Re: HELP! connecting two boxes
« Reply #1 on: Mar 13th, 2003, 6:05am »

should i go for 3d space through 2d projection? if i go for that, how should i handle the views? are there methods in processing for doing this?
 
how do i draw that dang line? hmmm...
 
_martin
Guest
Email
Re: HELP! connecting two boxes
« Reply #2 on: Mar 13th, 2003, 6:10am »

don't you just find it funny and/or amusing that if you ask someone who does 3d stuff how to do it, you get a reply: "why should i know how to do it? the software does it for me (referring to 3dsmax)." and say... "3dsmax does it this way... if you're doing multiple translations, you assign a parent and a child. the child follows the parent. you can draw the line you want with that but don't ask me about the algorithm / math behind it." ...
 
benelek

35160983516098 WWW Email
Re: HELP! connecting two boxes
« Reply #3 on: Mar 13th, 2003, 6:55am »

about the 3d imager who doesnt know the underlying algrithms...
 
u know, if u showed them a graph/other application/representation of the algorithms u mention, they'd probably be able to recognise the connection.
 
furthermore, if they had a visual way of extending/decomposing the behavior, such as what we were talking about with code visualisation, they'd probably be able to work in as much detail as someone who does the same stuff in code.
 
that's not to say that there arent people out there who just dont know their stuff
 
-jacob
 
_martin
Guest
Email
Re: HELP! connecting two boxes
« Reply #4 on: Mar 13th, 2003, 6:57am »

is there any method in processing for it to throw me the world space coordinates of an object space's origin?
 
benelek

35160983516098 WWW Email
Re: HELP! connecting two boxes
« Reply #5 on: Mar 13th, 2003, 7:11am »

Martin, the following kind-of works:
 
Code:
void setup()
{
  size(200,200);
  fill(255);
  smooth();
}
 
int r = 0;
 
void loop()
{
  translate(width/2,height/2);
  rotateY(radians(r));
   
  push();
  translate(-30,-30,-30);
  box(25);
  pop();
   
  push();
  translate(30,30,30);
  box(25);
  pop();
 
  push();
  rotate(HALF_PI/4.0);
  rotateY(-HALF_PI/4.0);
  float theDist = sqrt(sq(30)*3);
  line(-theDist,0,theDist,0);
  pop();
   
  if(r < 360) { r++; }
  else { r = 0; }  
   
}
 
_martin
Guest
Email
Re: HELP! connecting two boxes
« Reply #6 on: Mar 13th, 2003, 8:19am »

hi benelek, how did you figure out the math? quite hard coded... hmmm... i did a lil playing around...  
 
Code:
void setup()
{
  size(200,200);
  fill(255);
  smooth();
}
 
int r = 0;
// int w = 80; // try this
// int w = 50; // try this
int w = 10;
// int w = 30; // try this
int u = -1 * w;
 
void loop()
{
  translate(width/2,height/2);
  rotateY(radians(r));
 
  push();
  translate(w,w,w);
  box(25);
  pop();
 
  push();
  translate(u,u,u);
  box(25);
  pop();
 
  push();
  rotate(HALF_PI/4.0);
  rotateY(-HALF_PI/4.0);
  float theDist = sqrt(sq(u)*3);
  line(-theDist,0,theDist,0);
  pop();
 
  push();
  rotate(HALF_PI/4.0);
  rotateY(-HALF_PI/4.0);
  theDist = sqrt(sq(w)*3);
  line(-theDist,0,theDist,0);
  pop();
 
 
if(r < 360) { r++; }
else { r = 0; }
 
}
 
benelek

35160983516098 WWW Email
Re: HELP! connecting two boxes
« Reply #7 on: Mar 13th, 2003, 4:46pm »

ah, i see the problem.
 
but i'll start with the math
 
figuring out the distance between the two points in 2D is sqrt(sq(diffX)+sq(diffY))... in 3D, it's sqrt(sq(diffX)+sq(diffY)+sq(diffZ)).
 
then u have to rotate the drawing plane so ur drawing in the line from one center to another. this one's where the problem occurs, so i'll wait till at least 6 in the morning to start on it...
 
-jacob
 
benelek

35160983516098 WWW Email
Re: HELP! connecting two boxes
« Reply #8 on: Mar 14th, 2003, 7:46am »

ok, here ya go. after a bit of wakefulness, this one actually works.
 
it turns out that only the 2D distance is necessary. check out the following:
 
Code:
void setup()  
{  
  size(200,200);  
  fill(255);  
  smooth();  
}  
 
float r = 0;  
// int w = 80; // try this  
// int w = 50; // try this  
int w = 40;  
// int w = 30; // try this  
int u = -1 * w;  
 
void loop()  
{  
  translate(width/2,height/2+20);  
  rotateY(radians(r));
 
  push();  
  translate(w,w,w);  
  box(25);  
  pop();  
 
  push();  
  translate(u,u,u);  
  box(25);  
  pop();  
 
 
  push();
  rotateY(-radians(45));  
  float the2Dist = sqrt(sq(w)*2);
  line(-the2Dist,-w,the2Dist,w);
  pop();  
 
 
if(r < 360) { r+=0.5; }  
else { r = 0; }  
 
}

 
this isnt a wonderful way of doing it anyway... u still have to do this calculation of distance. plus if the boxes are rotated by a different angle, u have to go into angle calculation. it's a bit like post-rationalisation... "post-calculation"
 
a q'n for Fry or Reas - say you've called rotateX(bla), and then draw a point, does Processing calculate the point's position on a "global" x,y,z axes in order to draw it? i don't know much about matrices, except that it's a bit of a magic word around here!
 
-jacob
 
_martin
Guest
Email
Re: HELP! connecting two boxes
« Reply #9 on: Mar 14th, 2003, 8:48am »

this is good benelek ... would u have any idea on how it could be applied universally? meaning, if i have diff x,y,z values for the two boxes, how would i connect them? still the triangular method that you did?
 
re: your question, yes, processing calculates the point's position. here's a sample ...
 
Code:
rotateY(radians(50));
for(int i = 0; i < 500; i+=5)
{
  point(50,i);
}

 
unless of course you've translated it first and made it into an object space...
 
did that make sense?
 
was thinking of doing a continuous set of points in establishing the connection.
 
benelek

35160983516098 WWW Email
Re: HELP! connecting two boxes
« Reply #10 on: Mar 14th, 2003, 12:17pm »

ahh... enjoy!
 
Code:
void setup()  
{  
  size(200,200);  
  fill(255);  
  smooth();  
}  
   
float r = 0;
 
int wX = -50;  
int wY = 50;  
int wZ = 0;
int uX = 50;  
int uY = -20;
int uZ = -35;  
   
void loop()  
{  
  translate(width/2,height/2);  
  rotateY(radians(r));  
   
  push();  //box 1.
  translate(wX,wY,wZ);  
  box(25);  
  int xDiff=(uX-wX);
  int yDiff=(uY-wY);
  int zDiff=(uZ-wZ);
  float theAngle = atan2(zDiff,xDiff);
  float the2Dist = sqrt(sq(xDiff)+sq(zDiff));
  rotateY(-theAngle);    
  line(0,0,the2Dist,yDiff);  
  pop();  
   
  push();  //box2
  translate(uX,uY,uZ);  
  box(25);
  pop();
   
   
if(r < 360) { r+=0.5; }  
else { r = 0; }  
   
}
 
Martin

122417302122417302martingomez_listsmg1ph WWW Email
Re: HELP! connecting two boxes
« Reply #11 on: Mar 14th, 2003, 1:13pm »

ah... very elaborate. thanks!
 
Pages: 1 

« Previous topic | Next topic »