We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpOpenGL and 3D Libraries › Math Help needed - thin 3D-plate
Page Index Toggle Pages: 1
Math Help needed - thin 3D-plate (Read 1475 times)
Math Help needed - thin 3D-plate
Jan 23rd, 2010, 6:02am
 
Hello all,

I need a function similar to James'
http://processing.org/discourse/yabb2/num_1262458611.html#4

which does the following:

get four 3D-points x,y,z which denote the four corners of retangle of given thickness called "MyThickness".

greetings,

Chrisir

Re: Math Help needed - thin 3D-plate
Reply #1 - Jan 23rd, 2010, 8:28am
 
Create a method that accepts 4 PVector objects to represent the corners then inside this method call the drawLine() method created by James four times one for each side.

Something like should do the trick.

Code:


void drawBox(PVector c1, PVector c2, PVector c3, PVector c4, float weight, int strokeColour){
  drawLine(c1, c2, weight, strokeColour);
  drawLine(c2, c3, weight, strokeColour);
  drawLine(c3, c4, weight, strokeColour);
  drawLine(c4, c1, weight, strokeColour);
}

// method created by James Carruthers (parameters have been
// changed to PVectors and 'color' to int)
void drawLine(PVector p1, PVector p2, float weight, int strokeColour)
{
 PVector v1 = PVector.sub(p2, p1);
 float rho = sqrt(pow(v1.x,2)+pow(v1.y,2)+pow(v1.z,2));
 float phi = acos(v1.z/rho);
 float the = atan2(v1.y,v1.x);
 v1.mult(0.5);
 
 pushMatrix();
 translate(x1,y1,z1);
 translate(v1.x, v1.y, v1.z);
 rotateZ(the);
 rotateY(phi);
 noStroke();
 fill(strokeColour);
 box(weight,weight,p1.dist(p2)*1.2);
 popMatrix();
}


Alternatively since a rectangle with thickness is a box you can use the Shapes 3D library and the Box class now you're used to Tubes.
Smiley
Re: Math Help needed - thin 3D-plate
Reply #2 - Jan 23rd, 2010, 1:32pm
 
Hello Quark,

uhm...

Probably I have not been clear enough...

I need basically a solid plane defined by four corner-points in 3D.

The plane is inclined in space, but itself thin.

This what was I meant by "plate".

Technically it is of course a box (because it's not totally thin) but of unknown inclination.

I made a box with vertices for all 6 sides, but because the corners move in space, the order of the vertex-points gets confused. What happens then is that it isn't  a box but becomes turned inside out and so on.

Thanks!

Greeting,

Chris



Re: Math Help needed - thin 3D-plate
Reply #3 - Jan 23rd, 2010, 3:18pm
 
When you say thickness, what exactly do you mean?  Do you mean the box should rise above the four corner-points, or below, or be centered around those points?  

Also, to define a plane, you only need three points.  Since you want draw a rectangular portion of the plane, three points are also enough to figure out all of the edges of the rectangle.  In general the shape will be a parallelogram instead of a rectangle, unless you are careful to make the edges perpendicular when determining the three points.
Re: Math Help needed - thin 3D-plate
Reply #4 - Jan 23rd, 2010, 3:36pm
 


Hello,

1.
hald over the 4 points, other half underneath.

2.
It doesn't have to be rectangluar - just a 4-corner-plane.
I have the 4 points already....
I need only the plane.

Thanks!

Greetings, Chrisir

Re: Math Help needed - thin 3D-plate
Reply #5 - Jan 23rd, 2010, 4:04pm
 
Four points aren't necessarily all on the same plane because the fourth point might not be on the plane defined by the other three points.  Four points basically make two triangles that are joined on one edge, that may or may not be on the same plane.  Are you making sure that the four points are actually all on the same plane?

The approach I would take for this is to take the three points and find the two edges of the rectangle that are between these three points.  These will be two vectors.  Now find the cross product between those two vectors.  This will give you a vector perpendicular to the plane.  Normalize it, and then multiply it by half of the thickness.  Let's call that vector v. You need the fourth point now (which I'll assume you already have).  Now take each of the four points, and define the four points that make up the top face by adding v to your original four points, and then define the four points that make up the bottom face by subtracting v from your original four points.  Now you have all of the points you need to draw the six faces of the box.
Re: Math Help needed - thin 3D-plate
Reply #6 - Jan 23rd, 2010, 4:55pm
 
Hello!

Thank you very much!

I would like to show where this is getting at.

I posted it here
(not working in IE...)

http://openprocessing.org/visuals/?visualID=7112

Thanks!

Greetings!

Re: Math Help needed - thin 3D-plate
Reply #7 - Jan 24th, 2010, 4:37am
 
Basically you seem to want the equivalent of a piece of paper. You might look at the 3rd from last example beginShape(QUADS)) on this page

Ok so its 2D but vertax can also be take 3 values x/y/z when using P3D or OPENGL

Not forgetting what d.rifkin said about 4 points not being on a plane.
Re: Math Help needed - thin 3D-plate
Reply #8 - Jan 24th, 2010, 10:58am
 
Hello,

thank you all for your help!

The vertex-command doesn't help - I want to have it 3D-printed later and therefore need a "thickness".

Thank you !

Chrisir




Page Index Toggle Pages: 1