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-2010, 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 _STUFF3D_C
37
#include "openaxiom-c-macros.h"
38
39
#include "header.h"
40
41
#include <stdlib.h>
42
#include <unistd.h>
43
#include <math.h>
44
45
46
47
#include "Gfun.H1"
48
#include "spadcolors.h"
49
#include "util.H1"
50
51
#include "all_3d.H1"
52
/*****************************
53
*** traverse(n) ***
54
*** returns the nth point ***
55
*** in a point resevoir ***
56
*****************************/
57
58
viewTriple *
59
traverse (int n)
60
{
61
62
int i;
63
viewTriple *v;
64
65
v = splitPoints;
66
for (i=0; i<n; i++) v = v->next;
67
return(v);
68
69
} /* traverse */
70
71
72
/**************************/
73
/*** float absolute(x) ***/
74
/**************************/
75
76
float
77
absolute (float x)
78
{
79
80
if (x<0.0) return(-x);
81
else return(x);
82
83
}
84
85
86
87
88
/****************************/
89
/*** float get_random(x) ***/
90
/****************************/
91
92
float
93
get_random(void)
94
{
95
96
float x;
97
98
x = (float)(rand() % 100);
99
return(x);
100
101
}
102
103
104
105
106
/****************************/
107
/*** float norm_dist() ***/
108
/****************************/
109
110
triple
111
norm_dist(void)
112
{
113
114
float u1, u2, v1, v2, ss, rad;
115
triple pert;
116
117
ss = 2.0;
118
while (ss >= 1.0) {
119
u1 = get_random()/100.0;
120
u2 = get_random()/100.0;
121
v1 = 2.0*u1 - 1.0; v2 = 2.0*u2 - 1.0;
122
ss = v1*v1 + v2*v2;
123
}
124
if (ss == 0.0) ss += .1;
125
rad = -2.0*log(ss)/ss;
126
pert.x = v1 * sqrt(rad);
127
pert.y = v2 * sqrt(rad);
128
pert.z = 0; /* Don't leave uninitialized. */
129
130
return(pert);
131
}
132
133
134
135
/************************/
136
/*** void goodbye() ***/
137
/************************/
138
139
void
140
goodbye(int sig)
141
{
142
143
int Command;
144
145
PSClose(); /* free PS file and data structure space */
146
147
if (pixelSetFlag) FreePixels(dsply,colorMap,smoothConst);
148
if (!viewAloned) {
149
Command = viewportClosing;
150
check(write(Socket,&Command,intSize));
151
}
152
153
XCloseDisplay(dsply);
154
exit(0);
155
} /* goodbye */
156
157
158
159
160