Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download

open-axiom repository from github

24005 views
1
/*
2
Copyright (C) 1991-2002, The Numerical Algorithms Group Ltd.
3
All rights reserved.
4
Copyright (C) 2007-2008, Gabriel Dos Reis.
5
All rights reserved.
6
7
Redistribution and use in source and binary forms, with or without
8
modification, are permitted provided that the following conditions are
9
met:
10
11
- Redistributions of source code must retain the above copyright
12
notice, this list of conditions and the following disclaimer.
13
14
- Redistributions in binary form must reproduce the above copyright
15
notice, this list of conditions and the following disclaimer in
16
the documentation and/or other materials provided with the
17
distribution.
18
19
- Neither the name of The Numerical Algorithms Group Ltd. nor the
20
names of its contributors may be used to endorse or promote products
21
derived from this software without specific prior written permission.
22
23
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
24
IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
25
TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
26
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
27
OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
28
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
29
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
30
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
31
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
32
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
33
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34
*/
35
36
#define _MESH3D_C
37
#include "openaxiom-c-macros.h"
38
39
#include <math.h>
40
41
#include "header.h"
42
#include "all_3d.H1"
43
44
/***************************************************************************
45
*** void getMeshNormal(x0,y0,z0,x1,y1,z1,x2,y2,z2,zMin,zRange,Normal); ***
46
***************************************************************************/
47
48
void
49
getMeshNormal(float x0,float y0,float z0,float x1,float y1,float z1,
50
float x2,float y2,float z2,float zMin,float zRange,float Normal[3])
51
{
52
float Ax,Ay,Az,Bx,By,Bz,
53
UnitFactor;
54
55
Ax = x0-x1; Ay = y0-y1; Az = z0-z1;
56
Bx = x2-x1; By = y2-y1; Bz = z2-z1;
57
58
/* compute cross product */
59
60
Normal[0] = (Ay*Bz - Az*By);
61
Normal[1] = (Az*Bx - Ax*Bz);
62
Normal[2] = (Ax*By - Ay*Bx);
63
64
/* normalize normal vector */
65
66
UnitFactor = sqrt(Normal[0]*Normal[0] +
67
Normal[1]*Normal[1] +
68
Normal[2]*Normal[2]);
69
if (UnitFactor > 0.0) {
70
Normal[0] /= UnitFactor;
71
Normal[1] /= UnitFactor;
72
Normal[2] /= UnitFactor;
73
} else {
74
Normal[0] = 0.0;
75
Normal[1] = 0.0;
76
Normal[2] = 0.0;
77
}
78
79
} /* getMeshNormal() */
80
81
82
/***********************************
83
**** void normalizeVector(v) ****
84
***********************************/
85
86
void
87
normalizeVector(float *v)
88
{
89
/* v should be a triple (ignoring the rest of the array if necessary) */
90
91
float UnitFactor;
92
93
UnitFactor = sqrt(v[0]*v[0] + v[1]*v[1] + v[2]*v[2]);
94
if (UnitFactor != 0.0) {
95
v[0] /= UnitFactor;
96
v[1] /= UnitFactor;
97
v[2] /= UnitFactor;
98
} else {
99
v[0] = v[1] = v[2] = 0.0;
100
}
101
102
} /* normalizeVector() */
103
104
105
/************************************
106
**** void dotProduct(a,b,size) ****
107
************************************/
108
109
float
110
dotProduct(float * a,float *b,int size)
111
{
112
int i;
113
float f=0;
114
115
for (i=0; i<size; i++)
116
f += (a[i]*b[i]);
117
return(f);
118
119
} /* dotProduct() */
120
121
122