To LUGNET HomepageTo LUGNET News HomepageTo LUGNET Guide Homepage
 Help on Searching
 
Post new message to lugnet.cad.devOpen lugnet.cad.dev in your NNTP NewsreaderTo LUGNET News Traffic PageSign In (Members)
 CAD / Development / 9320
     
   
Subject: 
Math Problem Again
Newsgroups: 
lugnet.cad.dev
Date: 
Thu, 13 Nov 2003 23:53:56 GMT
Viewed: 
1784 times
  

You are given three 3d cooridates.
This makes a triangle in 3d space. The z values may all be three different, so
it may be rotated in almost*) any direction.

I am just interested of the plane; the surface it makes.

Now, we have a forth point, with only x and y values given. I wish to calculate
the z value where this line meets the plane from the triangle (* -> they will
meet, but not necesserily within the triangle)

If possible, I would like an Excel spreadsheet, but just the formula will do.

TIA,
/Tore

   
         
   
Subject: 
Re: Math Problem Again
Newsgroups: 
lugnet.cad.dev
Date: 
Fri, 14 Nov 2003 01:08:21 GMT
Viewed: 
1864 times
  

In lugnet.cad.dev, Tore Eriksson wrote:
You are given three 3d cooridates.
This makes a triangle in 3d space. The z values may all be three different, so
it may be rotated in almost*) any direction.

I am just interested of the plane; the surface it makes.

Now, we have a forth point, with only x and y values given. I wish to calculate
the z value where this line meets the plane from the triangle (* -> they will
meet, but not necesserily within the triangle)

If possible, I would like an Excel spreadsheet, but just the formula will do.

TIA,
/Tore



http://astronomy.swin.edu.au/~pbourke/geometry/planeeq/

tells you how to derive the equation of
a plane passing thru the three points
(x1,y1,z1)
(x2,y2,z2)
(x3,y3,z3)

The standard equation of a plane in 3 space is
A.x + B.y + C.z + D = 0                  (where the "." means times)

So given three points in space
(x1,y1,z1),
(x2,y2,z2),
(x3,y3,z3)

you can work out the the equation of the plane through
these points (on which your triangle lies) by working out some
matrix determinants which, if this means nothing to you, boils down to
this -
Calculate A,B,C,D from these equations,

A = y1 .(z2 - z3) + y2 .(z3 - z1) + y3 .(z1 - z2)
B = z1 .(x2 - x3) + z2 .(x3 - x1) + z3 .(x1 - x2)
C = x1 .(y2 - y3) + x2 .(y3 - y1) + x3 .(y1 - y2)
- D = x1 .(y2.z3 - y3.z2) + x2.(y3.z1 - y1.z3) + x3.(y1.z2 - y2.z1)

Having worked these out (i.e. this has given you the A,B,C,D in
A.x + B.y + C.z + D = 0) just plug in your fourth point's x and y co-ords
(say x4 and y4) into this equation i.e. let x=x4 and let y=y4
This gives you the equation for z4 that you are looking for viz.
A.x4 + B.y4 +C.z4 +D =0 (where now the only thing you don't know is z4)
rearranging this is just
z4=(-D -A.x4 - B.x4)/C


Then again, it's late :)

   
         
     
Subject: 
Re: Math Problem Again
Newsgroups: 
lugnet.cad.dev
Date: 
Fri, 14 Nov 2003 01:41:31 GMT
Viewed: 
1829 times
  

In lugnet.cad.dev, Ronan Webb wrote:

8<------

z4=(-D -A.x4 - B.x4)/C


Then again, it's late :)

Yes, it's very late. I'd better get myself some sleep first, and have a look at
it tomorrow.


Thanks a lot!
/Tore

   
         
   
Subject: 
Re: Math Problem Again
Newsgroups: 
lugnet.cad.dev
Date: 
Fri, 14 Nov 2003 04:26:06 GMT
Viewed: 
1965 times
  

In lugnet.cad.dev, Ronan Webb wrote:
In lugnet.cad.dev, Tore Eriksson wrote:
You are given three 3d cooridates.

(snip) <
If possible, I would like an Excel spreadsheet, but just the formula will do.

TIA,
/Tore



http://astronomy.swin.edu.au/~pbourke/geometry/planeeq/

(snip) <
Having worked these out (i.e. this has given you the A,B,C,D in
A.x + B.y + C.z + D = 0) just plug in your fourth point's x and y co-ords
(say x4 and y4) into this equation i.e. let x=x4 and let y=y4
This gives you the equation for z4 that you are looking for viz.
A.x4 + B.y4 +C.z4 +D =0 (where now the only thing you don't know is z4)
rearranging this is just
z4=(-D -A.x4 - B.x4)/C


Then again, it's late :)

Hey!  cool!   where was this info when I wrote my calculator program?  It would have made it alot easier. The calculator grew into a slightly different purpose though. it was for helping determine where to trim lines and quads at intersection points.

The last formula had a typo, here it is corrected.
z4=(-D -A.x4 - B.y4)/C

Tore, I will email you the spreadsheet I put this information into.

Paul

   
         
     
Subject: 
Re: Math Problem Again
Newsgroups: 
lugnet.cad.dev
Date: 
Fri, 14 Nov 2003 11:43:18 GMT
Viewed: 
1941 times
  

In lugnet.cad.dev, Paul Easter wrote:
In lugnet.cad.dev, Ronan Webb wrote:
In lugnet.cad.dev, Tore Eriksson wrote:
You are given three 3d cooridates.

(snip) <
If possible, I would like an Excel spreadsheet, but just the formula will do.

TIA,
/Tore



http://astronomy.swin.edu.au/~pbourke/geometry/planeeq/

(snip) <
Having worked these out (i.e. this has given you the A,B,C,D in
A.x + B.y + C.z + D = 0) just plug in your fourth point's x and y co-ords
(say x4 and y4) into this equation i.e. let x=x4 and let y=y4
This gives you the equation for z4 that you are looking for viz.
A.x4 + B.y4 +C.z4 +D =0 (where now the only thing you don't know is z4)
rearranging this is just
z4=(-D -A.x4 - B.x4)/C


Then again, it's late :)

Hey!  cool!   where was this info when I wrote my calculator program?  It would have made it alot easier. The calculator grew into a slightly different purpose though. it was for helping determine where to trim lines and quads at intersection points.

The last formula had a typo, here it is corrected.
z4=(-D -A.x4 - B.y4)/C

Yes, I saw that, too.

Tore, I will email you the spreadsheet I put this information into.

Paul

Thanks for the offer, but I have already made a working spreadsheet. :)
Now, all I have to do is try to automate it with some VBS.


/Tore

   
         
   
Subject: 
calc_z4.c (Was: Math Problem Again)
Newsgroups: 
lugnet.cad.dev
Date: 
Thu, 22 Oct 2009 22:42:19 GMT
Viewed: 
16743 times
  

In lugnet.cad.dev, Paul Easter wrote:
In lugnet.cad.dev, Ronan Webb wrote:
In lugnet.cad.dev, Tore Eriksson wrote:
You are given three 3d cooridates.

(snip) <
If possible, I would like an Excel spreadsheet, but just the formula will do.

TIA,
/Tore



http://astronomy.swin.edu.au/~pbourke/geometry/planeeq/

(snip) <
Having worked these out (i.e. this has given you the A,B,C,D in
A.x + B.y + C.z + D = 0) just plug in your fourth point's x and y co-ords
(say x4 and y4) into this equation i.e. let x=x4 and let y=y4
This gives you the equation for z4 that you are looking for viz.
A.x4 + B.y4 +C.z4 +D =0 (where now the only thing you don't know is z4)
rearranging this is just
z4=(-D -A.x4 - B.x4)/C


Then again, it's late :)

Hey!  cool!   where was this info when I wrote my calculator program?  It would have made it alot easier. The calculator grew into a slightly different purpose though. it was for helping determine where to trim lines and quads at intersection points.

The last formula had a typo, here it is corrected.
z4=(-D -A.x4 - B.y4)/C

Tore, I will email you the spreadsheet I put this information into.

Paul

Sorry guys, just wanted to store this function in a safer place than my hard
drive. :)
I just don't want to remake it again...!
Feel free to copy/paste/edit/port if you need it!
/Tore


// calc_z4 by Tore Eriksson
// credits to Ronan Webb for the superb formula
double calc_z4(double x1,double y1,double z1,
       double x2,double y2,double z2,
       double x3,double y3,double z3,
       double x4,double y4)
{
double a,b,c,minus_d,z4;
a = y1*(z2-z3) + y2*(z3-z1) + y3*(z1-z2);
b = z1*(x2-x3) + z2*(x3-x1) + z3*(x1-x2);
c = x1*(y2-y3) + x2*(y3-y1) + x3*(y1-y2);
minus_d = x1*(y2*z3-y3*z2) + x2*(y3*z1-y1*z3) + x3*(y1*z2-y2*z1);
z4 = (minus_d - a*x4 - b*y4)/c;
return z4;
}

   
         
   
Subject: 
Re: calc_z4.c (Was: Math Problem Again)
Newsgroups: 
lugnet.cad.dev
Date: 
Fri, 23 Oct 2009 08:31:51 GMT
Viewed: 
16791 times
  

// calc_z4 by Tore Eriksson
// credits to Ronan Webb for the superb formula
double calc_z4(double x1,double y1,double z1,
       double x2,double y2,double z2,
       double x3,double y3,double z3,
       double x4,double y4)
{
double a,b,c,minus_d,z4;
a = y1*(z2-z3) + y2*(z3-z1) + y3*(z1-z2);
b = z1*(x2-x3) + z2*(x3-x1) + z3*(x1-x2);
c = x1*(y2-y3) + x2*(y3-y1) + x3*(y1-y2);
minus_d = x1*(y2*z3-y3*z2) + x2*(y3*z1-y1*z3) + x3*(y1*z2-y2*z1);
z4 = (minus_d - a*x4 - b*y4)/c;
return z4;
}

You also need a touch of code to catch when c=0 so that z4 is undefined ;)

Tim

   
         
   
Subject: 
Re: calc_z4.c (Was: Math Problem Again)
Newsgroups: 
lugnet.cad.dev
Date: 
Fri, 23 Oct 2009 23:41:57 GMT
Viewed: 
17241 times
  

In lugnet.cad.dev, Timothy Gould wrote:
// calc_z4 by Tore Eriksson
// credits to Ronan Webb for the superb formula
double calc_z4(double x1,double y1,double z1,
       double x2,double y2,double z2,
       double x3,double y3,double z3,
       double x4,double y4)
{
  double a,b,c,minus_d,z4;
  a = y1*(z2-z3) + y2*(z3-z1) + y3*(z1-z2);
  b = z1*(x2-x3) + z2*(x3-x1) + z3*(x1-x2);
  c = x1*(y2-y3) + x2*(y3-y1) + x3*(y1-y2);
  if(c==0)
  {
    err=11;
    c=1;
  }
  minus_d = x1*(y2*z3-y3*z2) + x2*(y3*z1-y1*z3) + x3*(y1*z2-y2*z1);
  z4 = (minus_d - a*x4 - b*y4)/c;
  return z4;
}

You also need a touch of code to catch when c=0 so that z4 is undefined ;)

Tim

That shouldn't really be happening, unless someone enters a "triangle" that
isn't a triangle, for example with x1, x2, and x3 all = 0, or a line that isn't
referring to a polygon for some reason yet is processed as one.

Hmm, division by zero is not a thing to play with. I might add these 3 LOC's
anyway. Thanks for pointing this possible/hypothetical source of errors out.

/Tore

   
         
   
Subject: 
Re: calc_z4.c (Was: Math Problem Again)
Newsgroups: 
lugnet.cad.dev
Date: 
Sun, 25 Oct 2009 20:28:59 GMT
Viewed: 
17040 times
  

In lugnet.cad.dev, Tore Eriksson wrote:
That shouldn't really be happening, unless someone enters a "triangle" that
isn't a triangle, for example with x1, x2, and x3 all = 0, or a line that isn't
referring to a polygon for some reason yet is processed as one.

Actually, if the original triangle is (for example) in the Y-Z plane, then just
passing in an x4 that's different from x1, x2, and x3 will result in a failure.
The equivalent goes for an initial triangle in the X-Z plane.

--Travis

   
         
   
Subject: 
Re: calc_z4.c (Was: Math Problem Again)
Newsgroups: 
lugnet.cad.dev
Date: 
Mon, 26 Oct 2009 00:54:13 GMT
Viewed: 
17532 times
  

In lugnet.cad.dev, Travis Cobbs wrote:
In lugnet.cad.dev, Tore Eriksson wrote:
That shouldn't really be happening, unless someone enters a "triangle" that
isn't a triangle, for example with x1, x2, and x3 all = 0, or a line that isn't
referring to a polygon for some reason yet is processed as one.

Actually, if the original triangle is (for example) in the Y-Z plane, then just
passing in an x4 that's different from x1, x2, and x3 will result in a failure.
The equivalent goes for an initial triangle in the X-Z plane.

--Travis

True, but such triangles will not be visible in the 2-D front view of the UI and
therefor not clickable - unless the program is buggy. And if you can't click on
them, the function never has to encounter data from them. Hopefully...

/Tore

 

©2005 LUGNET. All rights reserved. - hosted by steinbruch.info GbR