~hidravfx-dev-team/hidravfx/trunk

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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
/****************************************************************************
Copyright (C) 2012 HidraVFX development team
            <https://launchpad.net/~hidravfx-dev-team>

This file is part of the HidraVFX project.

HidraVFX is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

HidraVFX is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with HidraVFX. If not, see <http://www.gnu.org/licenses/>.
****************************************************************************/

#include <math.h>
#include <mathplus.h>
#include <vertex.h>

void tpoint_swap(tpoint *a, tpoint *b)
{
  tpoint temp;

  temp.x = a->x;
  temp.y = a->y;
  temp.z = a->z;
  a->x = b->x;
  a->y = b->y;
  a->z = b->z;
  b->x = temp.x;
  b->y = temp.y;
  b->z = temp.z;
}

tpoint tpoint_2d(double xi,double yi)
{
  tpoint p;
  p.x = xi;
  p.y = yi;
  p.z = 0.0;
  return p;
}


tpoint tpoint_3d(double xi,double yi,double zi)
{
  tpoint p;
  p.x = xi;
  p.y = yi;
  p.z = zi;
  return p;
}

tpoint tpoint_copy(tpoint *a)
{
  tpoint p;
  p.x = a->x;
  p.y = a->y;
  p.z = a->z;
  return p;
}

tvertex tvertex_2d(double x0,double y0)
{
  tvertex v;
  v.x = x0;
  v.y = y0;
  v.z = 1.0;
  return v;
}

tvertex tvertex_3d(double x0,double y0,double z0)
{
  tvertex v;
  v.x = x0;
  v.y = y0;
  v.z = z0;
  return v;
}

tvertex tvertex_copy(tvertex *a)
{
  tvertex v;
  v.x = a->x;
  v.y = a->y;
  v.z = a->z;
  return v;
}

tvertex tvertex_null(void)
{
  tvertex v;
  v.x = 0.0;
  v.y = 0.0;
  v.z = 0.0;
  return v;
}

tvertex tvertex_sub(tvertex *v1, tvertex *v2)
{
  tvertex v;
  v.x = v1->x-v2->x;
  v.y = v1->y-v2->y;
  v.z = v1->z-v2->z;
  return v;
}

tvertex tvertex_add(tvertex *v1, tvertex *v2)
{
  tvertex v;
  v.x = v1->x+v2->x;
  v.y = v1->y+v2->y;
  v.z = v1->z+v2->z;
  return v;
}

tvertex tvertex_mul(tvertex *v1, tvertex *v2)
{
  tvertex v;
  v.x = v1->x*v2->x;
  v.y = v1->y*v2->y;
  v.z = v1->z*v2->z;
  return v;
}

double tvertex_length(tvertex *v)
{
  double l;
  l = sqrt(sqr(v->x)+sqr(v->y)+sqr(v->z));
  return l;
}