-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplane.c
60 lines (45 loc) · 969 Bytes
/
plane.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include <math.h>
#include <stdlib.h>
#include <stdio.h>
#include "common.h"
#include "geom.h"
#include "plane.h"
#include "input.h"
static int fsign(CORD_TYPE x)
{
if(x>0) return 1;
if(x<0) return -1;
return 0;
}
void* readPlane()
{
plane* pl;
pl = malloc(sizeof(plane));
pl->a = readDouble();
pl->b = readDouble();
pl->c = readDouble();
pl->d = readDouble();
return pl;
}
int pointInPlane(point p, void* data)
{
plane* pl = (plane*)data;
CORD_TYPE a = 0;
a = pl->a*p.x + pl->b*p.y + pl->c*p.z + pl->d;
return (a <= 0);
}
int segPlaneCut(seg s, void* data, point* in, vec* n)
{
plane* pl;
point tp;
CORD_TYPE d1,d2;
pl = (plane*)data;
if(n != NULL) *n = coords2vec(pl->a,pl->b,pl->c);
d1 = pl->a*s.p.x + pl->b*s.p.y + pl->c*s.p.z + pl->d;
d2 = pl->a*s.q.x + pl->b*s.q.y + pl->c*s.q.z + pl->d;
if(fsign(d1)*fsign(d2) >= 0)
return 0;
tp = vecLinComb(d2/(d2-d1),s.p,d1/(d1-d2),s.q);
if(in != NULL) *in = tp;
return 1;
}