|
|
/*
On Thu, 16 Jul 1998 16:24:24 +0100, Dylan Beattie
<dmb### [at] ecssotonacuk-NOSPAM> 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.
*/
////////////////////////////
//
// File: plane3.inc
// Author: Ronald L. Parker
// Date: 16 July 1998
//
// Requires POV Version 3.1 or newer
//
// This macro creates a plane that passes through points A, B, and C and
// has a normal such that Outside is outside the plane. If you know a
// point inside the plane instead, use the inverse keyword in your object
// definition.
//
// Use of collinear points for A, B, and C will cause a degenerate normal.
//
// To use this macro, create an object like so:
// object {plane3(Q1,Q2,Q3,Q4) texture{ ... } }
//
// If you're not going to specify a texture or other modifiers such as
// inverse or hollow, you may leave off the enclosing object{}.
//
////////////////////////////
#macro plane3( A, B, C, Outside )
#local N=vnormalize(vcross(B-A,C-A));
#if ( vdot( Outside-A, N ) < 0 )
#declare N=-N;
#end
plane { N, vdot(A,N) }
#end
Post a reply to this message
|
|
|
|
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)
|
|