| 1 |
|
1 |
/*****************************************************************
|
| 2 |
|
|
|
| 3 |
|
|
geo_int_stra_plane.c Type:Func
|
| 4 |
|
|
|
| 5 |
|
|
Intersection straight plane
|
| 6 |
|
|
|
| 7 |
|
|
Date de creation : Tue Jul 8 09:36:37 1997
|
| 8 |
|
|
|
| 9 |
|
|
Derniere version : Thu Jul 10 10:03:31 1997
|
| 10 |
|
|
|
| 11 |
|
|
|
| 12 |
|
|
|
| 13 |
|
|
Vincent FRANCOIS
|
| 14 |
|
|
|
| 15 |
|
|
*****************************************************************/
|
| 16 |
|
|
|
| 17 |
|
|
|
| 18 |
|
|
|
| 19 |
|
|
|
| 20 |
|
|
|
| 21 |
|
|
/**************************/
|
| 22 |
|
|
/* include */
|
| 23 |
|
|
#include <stdio.h>
|
| 24 |
|
|
#include <string.h>
|
| 25 |
|
|
#include <math.h>
|
| 26 |
|
|
#include "const.h"
|
| 27 |
|
|
#include "memoire.h"
|
| 28 |
|
|
#include "struct.h"
|
| 29 |
|
|
#include "prototype.h"
|
| 30 |
|
|
|
| 31 |
|
|
|
| 32 |
|
|
|
| 33 |
|
|
/**************************/
|
| 34 |
|
|
/* variables globales */
|
| 35 |
|
|
|
| 36 |
|
|
|
| 37 |
|
|
|
| 38 |
|
|
/**************************/
|
| 39 |
|
|
/* programme principal */
|
| 40 |
|
|
|
| 41 |
|
|
int geo_int_stra_plane(struct s_edge *edge,struct s_straight *straight,float x1,float y1,float z1,float x2,float y2,float z2,float x3,float y3,float z3,float *x,float *y,float *z)
|
| 42 |
|
|
{
|
| 43 |
|
|
struct s_par_straight *param;
|
| 44 |
|
|
float ox[4],oy[4],oz[4],deno,t,tt,ttt,delta,res[4];
|
| 45 |
|
|
int n1,n2;
|
| 46 |
|
|
|
| 47 |
|
|
param=straight->param;
|
| 48 |
|
|
/* definition du plan */
|
| 49 |
|
|
ox[0]=x2-x1;ox[1]=y2-y1;ox[2]=z2-z1;
|
| 50 |
|
|
oy[0]=x3-x1;oy[1]=y3-y1;oy[2]=z3-z1;
|
| 51 |
|
|
PVEC(oz,ox,oy);
|
| 52 |
|
|
oz[3]=(-oz[0]*x1-oz[1]*y1-oz[2]*z1);
|
| 53 |
|
|
|
| 54 |
|
|
/* resolution */
|
| 55 |
|
|
deno=oz[0]*param->dir[0]+oz[1]*param->dir[1]+oz[2]*param->dir[2];
|
| 56 |
|
|
if (EGAL(deno,0.0,0.0001)) return(0);
|
| 57 |
|
|
t=oz[0]*param->root[0]+oz[1]*param->root[1]+oz[2]*param->root[2]+oz[3];
|
| 58 |
|
|
t=(-t)/deno;
|
| 59 |
|
|
|
| 60 |
|
|
|
| 61 |
|
|
/* validation de la resolution */
|
| 62 |
|
|
if ((edge->t2>0.) && ((t<edge->t1) || (t>edge->t2+edge->t1))) return(0);
|
| 63 |
|
|
if ((edge->t2<0.) && ((t>edge->t1) || (t<edge->t2+edge->t1))) return(0);
|
| 64 |
|
|
*x=param->root[0]+t*param->dir[0];
|
| 65 |
|
|
*y=param->root[1]+t*param->dir[1];
|
| 66 |
|
|
*z=param->root[2]+t*param->dir[2];
|
| 67 |
|
|
|
| 68 |
|
|
delta=ox[0]*oy[1]-ox[1]*oy[0];
|
| 69 |
|
|
if (EGAL(delta,0.0,0.0001))
|
| 70 |
|
|
{
|
| 71 |
|
|
delta=ox[0]*oy[2]-ox[2]*oy[0];
|
| 72 |
|
|
if (EGAL(delta,0.0,0.0001))
|
| 73 |
|
|
{
|
| 74 |
|
|
delta=ox[1]*oy[2]-ox[2]*oy[1];
|
| 75 |
|
|
n1=1;n2=2;
|
| 76 |
|
|
}
|
| 77 |
|
|
else
|
| 78 |
|
|
{
|
| 79 |
|
|
n1=0;n2=2;
|
| 80 |
|
|
}
|
| 81 |
|
|
}
|
| 82 |
|
|
else
|
| 83 |
|
|
{
|
| 84 |
|
|
n1=0;n2=1;
|
| 85 |
|
|
}
|
| 86 |
|
|
res[0]=*x-x1;res[1]=*y-y1;res[2]=*z-z1;
|
| 87 |
|
|
|
| 88 |
|
|
tt=(res[n1]*oy[n2]-res[n2]*oy[n1])/delta;
|
| 89 |
|
|
ttt=(ox[n1]*res[n2]-ox[n2]*res[n1])/delta;
|
| 90 |
|
|
if ((tt<0.)||(tt>=1.)) return(0);
|
| 91 |
|
|
if ((ttt<0.)||(ttt>=1.)) return(0);
|
| 92 |
|
|
return(1);
|
| 93 |
|
|
|
| 94 |
|
|
|
| 95 |
|
|
}
|