liba 0.1.15
An algorithm library based on C/C++
Loading...
Searching...
No Matches
point3.h
Go to the documentation of this file.
1
5
6#ifndef LIBA_POINT3_H
7#define LIBA_POINT3_H
8
9#include "a.h"
10#include "vector3.h"
11
17
18/* clang-format off */
20#define A_POINT3_C(x, y, z) {a_real_c(x), a_real_c(y), a_real_c(z)}
21/* clang-format on */
22
24#define a_point3_c(x) a_cast_s(a_point3, x)
25#define a_point3_(_, x) a_cast_s(a_point3 _, x)
26
27typedef struct a_point3 a_point3;
28
29#if defined(__cplusplus)
30namespace a
31{
32typedef struct a_point3 point3;
33} /* namespace a */
34extern "C" {
35#endif /* __cplusplus */
36#if !defined A_HAVE_INLINE || defined(LIBA_POINT3_C)
38#undef A_INTERN
39#define A_INTERN A_PUBLIC extern
41#endif /* A_HAVE_INLINE */
42
46A_INTERN void a_vector3_set(a_vector3 *ctx, a_point3 const *p, a_point3 const *q);
47
51A_INTERN void a_point3_val(a_point3 const *ctx, a_real *x, a_real *y, a_real *z);
55A_INTERN void a_point3_set_val(a_point3 *ctx, a_real x, a_real y, a_real z);
59A_INTERN void a_point3_cyl(a_point3 const *ctx, a_real *rho, a_real *theta, a_real *z);
63A_INTERN void a_point3_set_cyl(a_point3 *ctx, a_real rho, a_real theta, a_real z);
67A_INTERN void a_point3_sph(a_point3 const *ctx, a_real *rho, a_real *theta, a_real *alpha);
71A_INTERN void a_point3_set_sph(a_point3 *ctx, a_real rho, a_real theta, a_real alpha);
72
76A_INTERN void a_point3_add(a_point3 const *lhs, a_vector3 const *rhs, a_point3 *res);
80A_INTERN void a_point3_sub(a_point3 const *lhs, a_vector3 const *rhs, a_point3 *res);
84A_INTERN void a_point3_mul(a_point3 const *lhs, a_real rhs, a_point3 *res);
88A_INTERN void a_point3_div(a_point3 const *lhs, a_real rhs, a_point3 *res);
92A_INTERN void a_point3_pos(a_point3 const *ctx, a_vector3 *res);
96A_INTERN void a_point3_neg(a_point3 const *ctx, a_vector3 *res);
97
111A_EXTERN a_real a_point3_dist(a_point3 const *lhs, a_point3 const *rhs);
125A_EXTERN a_real a_point3_dist2(a_point3 const *lhs, a_point3 const *rhs);
126
137A_EXTERN a_real a_point3_mindist(a_point3 const *ctx, a_point3 const *i_p, a_size i_n,
138 a_point3 *o_p /*=A_NULL*/, a_size *o_i /*=A_NULL*/);
139
150A_EXTERN a_real a_point3_maxdist(a_point3 const *ctx, a_point3 const *i_p, a_size i_n,
151 a_point3 *o_p /*=A_NULL*/, a_size *o_i /*=A_NULL*/);
152
162A_EXTERN int a_point3_cmpxy(a_point3 const *lhs, a_point3 const *rhs);
163
173A_EXTERN int a_point3_cmpyx(a_point3 const *lhs, a_point3 const *rhs);
174
175#if !defined A_HAVE_INLINE || defined(LIBA_POINT3_C)
177#undef A_INTERN
178#define A_INTERN static A_INLINE
180#endif /* A_HAVE_INLINE */
181#if defined(__cplusplus)
182} /* extern "C" */
183A_INLINE void a_vector3::set(a_point3 const &p, a_point3 const &q)
184{
185 a_vector3_set(this, &p, &q);
186}
187#endif /* __cplusplus */
188
193{
194 a_real x, y, z;
195#if defined(__cplusplus)
197 A_INLINE void val(a_real &x_, a_real &y_, a_real &z_) const
198 {
199 a_point3_val(this, &x_, &y_, &z_);
200 }
201
202 A_INLINE void set_val(a_real x_, a_real y_, a_real z_)
203 {
204 a_point3_set_val(this, x_, y_, z_);
205 }
206
207 A_INLINE void cyl(a_real &rho, a_real &theta, a_real &z_) const
208 {
209 a_point3_cyl(this, &rho, &theta, &z_);
210 }
211
212 A_INLINE void set_cyl(a_real rho, a_real theta, a_real z_)
213 {
214 a_point3_set_cyl(this, rho, theta, z_);
215 }
216
217 A_INLINE void sph(a_real &rho, a_real &theta, a_real &alpha) const
218 {
219 a_point3_sph(this, &rho, &theta, &alpha);
220 }
221
222 A_INLINE void set_sph(a_real rho, a_real theta, a_real alpha)
223 {
224 a_point3_set_sph(this, rho, theta, alpha);
225 }
226
227 A_INLINE void add(a_vector3 const &rhs, a_point3 &res) const
228 {
229 a_point3_add(this, &rhs, &res);
230 }
231
232 A_INLINE void sub(a_vector3 const &rhs, a_point3 &res) const
233 {
234 a_point3_sub(this, &rhs, &res);
235 }
236
237 A_INLINE void mul(a_real rhs, a_point3 &res) const
238 {
239 a_point3_mul(this, rhs, &res);
240 }
241
242 A_INLINE void div(a_real rhs, a_point3 &res) const
243 {
244 a_point3_div(this, rhs, &res);
245 }
246
247 A_INLINE void pos(a_vector3 &res) const
248 {
249 a_point3_pos(this, &res);
250 }
251
252 A_INLINE void neg(a_vector3 &res) const
253 {
254 a_point3_neg(this, &res);
255 }
256
257 A_INLINE a_real dist(a_point3 const &rhs) const { return a_point3_dist(this, &rhs); }
259 A_INLINE a_real dist2(a_point3 const &rhs) const { return a_point3_dist2(this, &rhs); }
261 A_INLINE a_real mindist(a_point3 const *i_p, a_size i_n, a_point3 *o_p = A_NULL, a_size *o_i = A_NULL) const
262 {
263 return a_point3_mindist(this, i_p, i_n, o_p, o_i);
264 }
265
266 A_INLINE a_real maxdist(a_point3 const *i_p, a_size i_n, a_point3 *o_p = A_NULL, a_size *o_i = A_NULL) const
267 {
268 return a_point3_maxdist(this, i_p, i_n, o_p, o_i);
269 }
270
271 friend A_INLINE void operator+=(a_point3 &lhs, a_vector3 const &rhs) { a_point3_add(&lhs, &rhs, &lhs); }
273 friend A_INLINE a_point3 operator+(a_point3 const &lhs, a_vector3 const &rhs)
274 {
275 a_point3 res;
276 a_point3_add(&lhs, &rhs, &res);
277 return res;
278 }
279
280 friend A_INLINE void operator-=(a_point3 &lhs, a_vector3 const &rhs) { a_point3_sub(&lhs, &rhs, &lhs); }
282 friend A_INLINE a_point3 operator-(a_point3 const &lhs, a_vector3 const &rhs)
283 {
284 a_point3 res;
285 a_point3_sub(&lhs, &rhs, &res);
286 return res;
287 }
288
289 friend A_INLINE a_vector3 operator-(a_point3 const &lhs, a_point3 const &rhs)
290 {
291 a_vector3 res;
292 a_vector3_set(&res, &rhs, &lhs);
293 return res;
294 }
295
296 friend A_INLINE void operator*=(a_point3 &lhs, a_real rhs) { a_point3_mul(&lhs, rhs, &lhs); }
298 friend A_INLINE a_point3 operator*(a_real lhs, a_point3 const &rhs)
299 {
300 a_point3 res;
301 a_point3_mul(&rhs, lhs, &res);
302 return res;
303 }
304
305 friend A_INLINE a_point3 operator*(a_point3 const &lhs, a_real rhs)
306 {
307 a_point3 res;
308 a_point3_mul(&lhs, rhs, &res);
309 return res;
310 }
311
312 friend A_INLINE void operator/=(a_point3 &lhs, a_real rhs) { a_point3_div(&lhs, rhs, &lhs); }
314 friend A_INLINE a_point3 operator/(a_point3 const &lhs, a_real rhs)
315 {
316 a_point3 res;
317 a_point3_div(&lhs, rhs, &res);
318 return res;
319 }
320
321 friend A_INLINE a_vector3 operator+(a_point3 const &rhs)
322 {
323 a_vector3 res;
324 a_point3_pos(&rhs, &res);
325 return res;
326 }
327
328 friend A_INLINE a_vector3 operator-(a_point3 const &rhs)
329 {
330 a_vector3 res;
331 a_point3_neg(&rhs, &res);
332 return res;
333 }
334#endif /* __cplusplus */
335};
336
337#if defined(LIBA_POINT3_C)
339#undef A_INTERN
340#define A_INTERN A_INLINE
342#endif /* LIBA_POINT3_C */
343#if defined(A_HAVE_INLINE) || defined(LIBA_POINT3_C)
344
345A_INTERN void a_vector3_set(a_vector3 *ctx, a_point3 const *p, a_point3 const *q)
346{
347 ctx->x = q->x - p->x;
348 ctx->y = q->y - p->y;
349 ctx->z = q->z - p->z;
350}
351A_INTERN void a_point3_val(a_point3 const *ctx, a_real *x, a_real *y, a_real *z)
352{
353 *x = ctx->x;
354 *y = ctx->y;
355 *z = ctx->z;
356}
357A_INTERN void a_point3_set_val(a_point3 *ctx, a_real x, a_real y, a_real z)
358{
359 ctx->x = x;
360 ctx->y = y;
361 ctx->z = z;
362}
363A_INTERN void a_point3_cyl(a_point3 const *ctx, a_real *rho, a_real *theta, a_real *z)
364{
365 a_real_cart2pol(ctx->x, ctx->y, rho, theta);
366 *z = ctx->z;
367}
368A_INTERN void a_point3_set_cyl(a_point3 *ctx, a_real rho, a_real theta, a_real z)
369{
370 a_real_pol2cart(rho, theta, &ctx->x, &ctx->y);
371 ctx->z = z;
372}
373A_INTERN void a_point3_sph(a_point3 const *ctx, a_real *rho, a_real *theta, a_real *alpha)
374{
375 a_real_cart2sph(ctx->x, ctx->y, ctx->z, rho, theta, alpha);
376}
377A_INTERN void a_point3_set_sph(a_point3 *ctx, a_real rho, a_real theta, a_real alpha)
378{
379 a_real_sph2cart(rho, theta, alpha, &ctx->x, &ctx->y, &ctx->z);
380}
381A_INTERN void a_point3_add(a_point3 const *lhs, a_vector3 const *rhs, a_point3 *res)
382{
383 res->x = lhs->x + rhs->x;
384 res->y = lhs->y + rhs->y;
385 res->z = lhs->z + rhs->z;
386}
387A_INTERN void a_point3_sub(a_point3 const *lhs, a_vector3 const *rhs, a_point3 *res)
388{
389 res->x = lhs->x - rhs->x;
390 res->y = lhs->y - rhs->y;
391 res->z = lhs->z - rhs->z;
392}
393A_INTERN void a_point3_mul(a_point3 const *lhs, a_real rhs, a_point3 *res)
394{
395 res->x = lhs->x * rhs;
396 res->y = lhs->y * rhs;
397 res->z = lhs->z * rhs;
398}
399A_INTERN void a_point3_div(a_point3 const *lhs, a_real rhs, a_point3 *res)
400{
401 res->x = lhs->x / rhs;
402 res->y = lhs->y / rhs;
403 res->z = lhs->z / rhs;
404}
405A_INTERN void a_point3_pos(a_point3 const *ctx, a_vector3 *res)
406{
407 res->x = +ctx->x;
408 res->y = +ctx->y;
409 res->z = +ctx->z;
410}
411A_INTERN void a_point3_neg(a_point3 const *ctx, a_vector3 *res)
412{
413 res->x = -ctx->x;
414 res->y = -ctx->y;
415 res->z = -ctx->z;
416}
417
418#endif /* A_HAVE_INLINE */
419#if defined(LIBA_POINT3_C)
421#undef A_INTERN
422#define A_INTERN static A_INLINE
424#endif /* LIBA_POINT3_C */
425
427
428#endif /* a/point3.h */
algorithm library
void a_point3_val(a_point3 const *ctx, a_real *x, a_real *y, a_real *z)
get the cartesian coordinates of a 3D point.
void a_point3_pos(a_point3 const *ctx, a_vector3 *res)
convert it into a vector from the origin to the point.
a_real a_point3_dist(a_point3 const *lhs, a_point3 const *rhs)
compute the distance between two 3D points.
void set(a_point3 const &p, a_point3 const &q)
set a 3D vector as the difference from point p to point q.
Definition point3.h:183
void a_point3_set_cyl(a_point3 *ctx, a_real rho, a_real theta, a_real z)
set the cylindrical coordinates of a 3D point.
int a_point3_cmpyx(a_point3 const *lhs, a_point3 const *rhs)
compare two 3D points primarily by Y, then by X, and finally by Z.
void a_vector3_set(a_vector3 *ctx, a_point3 const *p, a_point3 const *q)
set a 3D vector as the difference from point p to point q.
void a_point3_add(a_point3 const *lhs, a_vector3 const *rhs, a_point3 *res)
add a 3D vector to a 3D point.
a_real a_point3_mindist(a_point3 const *ctx, a_point3 const *i_p, a_size i_n, a_point3 *o_p, a_size *o_i)
compute the minimum distance from a reference point to a point set.
a_real a_point3_dist2(a_point3 const *lhs, a_point3 const *rhs)
compute the squared distance between two 3D points.
int a_point3_cmpxy(a_point3 const *lhs, a_point3 const *rhs)
compare two 3D points primarily by X, then by Y, and finally by Z.
a_real a_point3_maxdist(a_point3 const *ctx, a_point3 const *i_p, a_size i_n, a_point3 *o_p, a_size *o_i)
compute the maximum distance from a reference point to a point set.
void a_point3_set_sph(a_point3 *ctx, a_real rho, a_real theta, a_real alpha)
set the spherical coordinates of a 3D point.
void a_point3_set_val(a_point3 *ctx, a_real x, a_real y, a_real z)
set the cartesian coordinates of a 3D point.
void a_point3_sph(a_point3 const *ctx, a_real *rho, a_real *theta, a_real *alpha)
get the spherical coordinates of a 3D point.
void a_point3_mul(a_point3 const *lhs, a_real rhs, a_point3 *res)
multiplie a 3D point by a scalar.
void a_point3_cyl(a_point3 const *ctx, a_real *rho, a_real *theta, a_real *z)
get the cylindrical coordinates of a 3D point.
void a_point3_div(a_point3 const *lhs, a_real rhs, a_point3 *res)
divide a 3D point by a scalar.
void a_point3_neg(a_point3 const *ctx, a_vector3 *res)
convert it into a vector from the point to the origin.
void a_point3_sub(a_point3 const *lhs, a_vector3 const *rhs, a_point3 *res)
subtract a 3D vector from a 3D point.
double a_real
compiler built-in floating-point number type
Definition a.h:1012
size_t a_size
unsigned integer type returned by the sizeof operator
Definition a.h:823
instance structure for three-dimensional point
Definition point3.h:193
a_real mindist(a_point3 const *i_p, a_size i_n, a_point3 *o_p=NULL, a_size *o_i=NULL) const
compute the minimum distance from a reference point to a point set.
Definition point3.h:261
a_real maxdist(a_point3 const *i_p, a_size i_n, a_point3 *o_p=NULL, a_size *o_i=NULL) const
compute the maximum distance from a reference point to a point set.
Definition point3.h:266
friend void operator/=(a_point3 &lhs, a_real rhs)
divide a 3D point by a scalar.
Definition point3.h:312
a_real dist2(a_point3 const &rhs) const
compute the squared distance between two 3D points.
Definition point3.h:259
friend a_point3 operator*(a_point3 const &lhs, a_real rhs)
multiplie a 3D point by a scalar.
Definition point3.h:305
friend a_point3 operator/(a_point3 const &lhs, a_real rhs)
divide a 3D point by a scalar.
Definition point3.h:314
friend void operator+=(a_point3 &lhs, a_vector3 const &rhs)
add a 3D vector to a 3D point.
Definition point3.h:271
void sph(a_real &rho, a_real &theta, a_real &alpha) const
get the spherical coordinates of a 3D point.
Definition point3.h:217
friend a_vector3 operator+(a_point3 const &rhs)
convert it into a vector from the origin to the point.
Definition point3.h:321
friend a_point3 operator-(a_point3 const &lhs, a_vector3 const &rhs)
subtract a 3D vector from a 3D point.
Definition point3.h:282
void cyl(a_real &rho, a_real &theta, a_real &z_) const
get the cylindrical coordinates of a 3D point.
Definition point3.h:207
void neg(a_vector3 &res) const
convert it into a vector from the point to the origin.
Definition point3.h:252
void val(a_real &x_, a_real &y_, a_real &z_) const
get the cartesian coordinates of a 3D point.
Definition point3.h:197
void sub(a_vector3 const &rhs, a_point3 &res) const
subtract a 3D vector from a 3D point.
Definition point3.h:232
friend void operator*=(a_point3 &lhs, a_real rhs)
multiplie a 3D point by a scalar.
Definition point3.h:296
void set_val(a_real x_, a_real y_, a_real z_)
set the cartesian coordinates of a 3D point.
Definition point3.h:202
void add(a_vector3 const &rhs, a_point3 &res) const
add a 3D vector to a 3D point.
Definition point3.h:227
void set_sph(a_real rho, a_real theta, a_real alpha)
set the spherical coordinates of a 3D point.
Definition point3.h:222
void pos(a_vector3 &res) const
convert it into a vector from the origin to the point.
Definition point3.h:247
void div(a_real rhs, a_point3 &res) const
divide a 3D point by a scalar.
Definition point3.h:242
void mul(a_real rhs, a_point3 &res) const
multiplie a 3D point by a scalar.
Definition point3.h:237
friend a_point3 operator+(a_point3 const &lhs, a_vector3 const &rhs)
add a 3D vector to a 3D point.
Definition point3.h:273
void set_cyl(a_real rho, a_real theta, a_real z_)
set the cylindrical coordinates of a 3D point.
Definition point3.h:212
a_real dist(a_point3 const &rhs) const
compute the distance between two 3D points.
Definition point3.h:257
friend a_point3 operator*(a_real lhs, a_point3 const &rhs)
multiplie a 3D point by a scalar.
Definition point3.h:298
friend void operator-=(a_point3 &lhs, a_vector3 const &rhs)
subtract a 3D vector from a 3D point.
Definition point3.h:280
friend a_vector3 operator-(a_point3 const &rhs)
convert it into a vector from the point to the origin.
Definition point3.h:328
friend a_vector3 operator-(a_point3 const &lhs, a_point3 const &rhs)
set a 3D vector as the difference from point p to point q.
Definition point3.h:289
instance structure for three-dimensional vector
Definition vector3.h:387
three-dimensional vector