|
![](/i/fill.gif) |
Dylan:
When I was modeling the new sanctuary that my church built I found a
need to define many walls (planes). I read the blueprints and discovered
that with the many oddly angled planar surfaces it had, I needed to find
a way to give me the planes based on three points. The three points were
based on an arbitrary coordinate system that I defined for the
blueprint. All I needed to do was to specify the three coordinates and
the program spits out the normal and the distance from my origin. I have
included the source code below. It compiles under Borland C++ 5.0, I
believe, and hopefully under anything else. It's just basic C stuff. I
have the .exe if you want it. I hope this is useful to you.
Jon Berndt
--- start ---
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
main()
{
float pt[3][3];
float vec[2][3];
float res[3];
float len;
float len2;
float len2root;
int i, j;
start:
printf("\nEnter x, y, z coords of plane base vector start point: ");
scanf("%f %f %f",&pt[0][0],&pt[0][1], &pt[0][2]);
printf("\nEnter x, y, z coords of plane base vector end point: ");
scanf("%f %f %f", &pt[1][0],&pt[1][1], &pt[1][2]);
printf("\nEnter x, y, z coords of plane second vector end point: ");
scanf("%f %f %f",&pt[2][0],&pt[2][1], &pt[2][2]);
for (j=1;j<3;j++) {
for (i=0;i<3;i++) {
vec[j-1][i] = pt[j][i] - pt[0][i];
}
}
res[0] = vec[0][1]*vec[1][2] - vec[0][2]*vec[1][1];
res[1] = vec[0][2]*vec[1][0] - vec[0][0]*vec[1][2];
res[2] = vec[0][0]*vec[1][1] - vec[0][1]*vec[1][0];
len = res[0]*pt[0][0] + res[1]*pt[0][1] + res[2]*pt[0][2];
len2 = res[0]*res[0] + res[1]*res[1] + res[2]*res[2];
len2root = sqrt(len2);
printf("For a plane with collinear points:\n\n");
printf(" %7.3f %7.3f %7.3f\n", pt[0][0], pt[0][1], pt[0][2]);
printf(" %7.3f %7.3f %7.3f\n", pt[1][0], pt[1][1], pt[1][2]);
printf(" %7.3f %7.3f %7.3f\n\n", pt[2][0], pt[2][1], pt[2][2]);
printf("The normal is:\n\n");
printf(" (%7.3f)i + (%7.3f)j + (%7.3f)k\n\n",res[0]/len2root,
res[1]/len2root, res[2]/len2root);
printf("Distance from origin is: %7.3f\n\n", len/len2root);
goto start;
}
--- end ---
Dylan Beattie wrote:
>
> I've always thought when making 'warped' boxes that if you could define
> a plane in terms of three points that lie *on* the plane and one that
> lies outside it, it would be a lot easier to use CSG's of six planes or
> more to create complex solid shapes. Calculating normals or using
> rotations is time-consuming and it makes my brain hurt after a while -
> with a 3+1 point plane, you'd just give the locations of three corners
> of each side, and another point to indicate which side is the inside and
> which is the outside. The eight-point metabox would probably be easier,
> but the 3+1 plane would possibly be more versatile. Opinions?
Post a reply to this message
Attachments:
Download 'smime.p7s.dat' (3 KB)
|
![](/i/fill.gif) |