liba 0.1.15
An algorithm library based on C/C++
Loading...
Searching...
No Matches
plane.h
Go to the documentation of this file.
1
5
6#ifndef LIBA_PLANE_H
7#define LIBA_PLANE_H
8
9#include "a.h"
10#include "line3.h"
11
17
19#define a_plane_c(x) a_cast_s(a_plane, x)
20#define a_plane_(_, x) a_cast_s(a_plane _, x)
21
22typedef struct a_plane a_plane;
23
24#if defined(__cplusplus)
25namespace a
26{
27typedef struct a_plane plane;
28} /* namespace a */
29extern "C" {
30#endif /* __cplusplus */
31#if !defined A_HAVE_INLINE || defined(LIBA_PLANE_C)
33#undef A_INTERN
34#define A_INTERN A_PUBLIC extern
36#endif /* A_HAVE_INLINE */
37
38A_INTERN a_point3 const *a_plane_org(a_plane const *ctx);
39A_INTERN a_vector3 const *a_plane_dir(a_plane const *ctx);
40A_INTERN a_vector3 const *a_plane_u(a_plane const *ctx);
41A_INTERN a_vector3 const *a_plane_v(a_plane const *ctx);
42A_INTERN void a_plane_set_org(a_plane *ctx, a_real x, a_real y, a_real z);
43
44A_EXTERN int a_plane_set_dir(a_plane *ctx, a_real x, a_real y, a_real z);
45A_EXPORT int a_plane_set_uv(a_plane *ctx, a_vector3 const *u, a_vector3 const *v);
46A_EXPORT int a_plane_set_u(a_plane *ctx, a_vector3 const *n, a_vector3 const *u);
47A_EXPORT int a_plane_set_v(a_plane *ctx, a_vector3 const *n, a_vector3 const *v);
48A_EXTERN int a_plane_set(a_plane *ctx, a_point3 const *p, a_vector3 const *n);
49A_EXTERN int a_plane_set3(a_plane *ctx, a_point3 const *p1, a_point3 const *p2, a_point3 const *p3);
50A_EXTERN int a_plane_set4(a_plane *ctx, a_real a, a_real b, a_real c, a_real d);
51A_INTERN void a_plane_eval(a_plane const *ctx, a_real u, a_real v, a_point3 *res);
52A_EXTERN void a_plane_parm(a_plane const *ctx, a_point3 const *p, a_real *u, a_real *v);
53A_EXTERN a_real a_plane_proj(a_plane const *ctx, a_point3 const *p, a_point3 *res);
54
55A_EXTERN a_real a_plane_sdist(a_plane const *ctx, a_point3 const *rhs);
56A_EXTERN a_real a_plane_dist(a_plane const *ctx, a_point3 const *rhs);
57
58A_EXTERN int a_plane_int0(a_plane const *ctx, a_point3 const *rhs, a_real *u, a_real *v);
59A_EXTERN int a_plane_int1(a_plane const *ctx, a_line3 const *rhs, a_real min, a_real max, a_real *w);
60A_EXTERN int a_plane_int2(a_plane const *ctx, a_plane const *rhs, a_line3 *res);
61
62A_EXTERN void a_plane_rot2d(a_plane *ctx, a_real angle);
63
64#if !defined A_HAVE_INLINE || defined(LIBA_PLANE_C)
66#undef A_INTERN
67#define A_INTERN static A_INLINE
69#endif /* A_HAVE_INLINE */
70#if defined(__cplusplus)
71} /* extern "C" */
72#endif /* __cplusplus */
73
77struct a_plane
78{
79 a_point3 org;
80 a_vector3 dir_, u_, v_;
81#if defined(__cplusplus)
82 A_INLINE void set_org(a_real x, a_real y, a_real z)
83 {
84 a_plane_set_org(this, x, y, z);
85 }
86 A_INLINE a_vector3 const &dir() const { return dir_; }
87 A_INLINE int set_dir(a_real x, a_real y, a_real z)
88 {
89 return a_plane_set_dir(this, x, y, z);
90 }
91 A_INLINE int set_uv(a_vector3 const &u, a_vector3 const &v)
92 {
93 return a_plane_set_uv(this, &u, &v);
94 }
95 A_INLINE int set_u(a_vector3 const &n, a_vector3 const &u)
96 {
97 return a_plane_set_u(this, &n, &u);
98 }
99 A_INLINE int set_v(a_vector3 const &n, a_vector3 const &v)
100 {
101 return a_plane_set_v(this, &n, &v);
102 }
103 A_INLINE a_vector3 const &u() const { return u_; }
104 A_INLINE a_vector3 const &v() const { return v_; }
105 A_INLINE int set(a_point3 const &p, a_vector3 const &n)
106 {
107 return a_plane_set(this, &p, &n);
108 }
109 A_INLINE int set(a_point3 const &p1, a_point3 const &p2, a_point3 const &p3)
110 {
111 return a_plane_set3(this, &p1, &p2, &p3);
112 }
113 A_INLINE void eval(a_real u, a_real v, a_point3 &res) const
114 {
115 a_plane_eval(this, u, v, &res);
116 }
117 A_INLINE void parm(a_point3 const &p, a_real &u, a_real &v) const
118 {
119 a_plane_parm(this, &p, &u, &v);
120 }
121 A_INLINE a_real proj(a_point3 const &p, a_point3 &res) const
122 {
123 return a_plane_proj(this, &p, &res);
124 }
125 A_INLINE a_real sdist(a_point3 const &rhs) const
126 {
127 return a_plane_sdist(this, &rhs);
128 }
129 A_INLINE a_real dist(a_point3 const &rhs) const
130 {
131 return a_plane_dist(this, &rhs);
132 }
133 A_INLINE int int0(a_point3 const &rhs, a_real &u, a_real &v) const
134 {
135 return a_plane_int0(this, &rhs, &u, &v);
136 }
137 A_INLINE int int1(a_line3 const &rhs, a_real min, a_real max, a_real &w) const
138 {
139 return a_plane_int1(this, &rhs, min, max, &w);
140 }
141 A_INLINE int int2(a_plane const &rhs, a_line3 &res) const
142 {
143 return a_plane_int2(this, &rhs, &res);
144 }
145 A_INLINE void rot2d(a_real angle)
146 {
147 a_plane_rot2d(this, angle);
148 }
149#endif /* __cplusplus */
150};
151
152#if defined(LIBA_PLANE_C)
154#undef A_INTERN
155#define A_INTERN A_INLINE
157#endif /* LIBA_PLANE_C */
158#if defined(A_HAVE_INLINE) || defined(LIBA_PLANE_C)
159
160A_INTERN a_point3 const *a_plane_org(a_plane const *ctx)
161{
162 return &ctx->org;
163}
164A_INTERN a_vector3 const *a_plane_dir(a_plane const *ctx)
165{
166 return &ctx->dir_;
167}
168A_INTERN a_vector3 const *a_plane_u(a_plane const *ctx)
169{
170 return &ctx->u_;
171}
172A_INTERN a_vector3 const *a_plane_v(a_plane const *ctx)
173{
174 return &ctx->v_;
175}
176A_INTERN void a_plane_set_org(a_plane *ctx, a_real x, a_real y, a_real z)
177{
178 ctx->org.x = x;
179 ctx->org.y = y;
180 ctx->org.z = z;
181}
182
183A_INTERN void a_plane_eval(a_plane const *ctx, a_real u, a_real v, a_point3 *res)
184{
185 a_point3 const *const o = &ctx->org;
186 a_vector3 const *const a = &ctx->u_;
187 a_vector3 const *const b = &ctx->v_;
188 res->x = o->x + a->x * u + b->x * v;
189 res->y = o->y + a->y * u + b->y * v;
190 res->z = o->z + a->z * u + b->z * v;
191}
192
193#endif /* A_HAVE_INLINE */
194#if defined(LIBA_PLANE_C)
196#undef A_INTERN
197#define A_INTERN static A_INLINE
199#endif /* LIBA_PLANE_C */
200
202
203#endif /* a/plane.h */
algorithm library
double a_real
compiler built-in floating-point number type
Definition a.h:1012
three-dimensional line
instance structure for three-dimensional line defined by an origin, a direction vector,...
Definition line3.h:297
instance structure for three-dimensional plane
Definition plane.h:78
instance structure for three-dimensional point
Definition point3.h:350
instance structure for three-dimensional vector
Definition vector3.h:415