liba 0.1.15
An algorithm library based on C/C++
Loading...
Searching...
No Matches
line3.h
Go to the documentation of this file.
1
5
6#ifndef LIBA_LINE3_H
7#define LIBA_LINE3_H
8
9#include "a.h"
10#include "point3.h"
11
17
19#define a_line3_c(x) a_cast_s(a_line3, x)
20#define a_line3_(_, x) a_cast_s(a_line3 _, x)
21
22typedef struct a_line3 a_line3;
23
24#if defined(__cplusplus)
25namespace a
26{
27typedef struct a_line3 line3;
28} /* namespace a */
29extern "C" {
30#endif /* __cplusplus */
31#if !defined A_HAVE_INLINE || defined(LIBA_LINE3_C)
33#undef A_INTERN
34#define A_INTERN A_PUBLIC extern
36#endif /* A_HAVE_INLINE */
37
43A_INTERN a_real a_line3_max(a_line3 const *ctx);
49A_INTERN a_point3 const *a_line3_org(a_line3 const *ctx);
55A_INTERN a_vector3 const *a_line3_dir(a_line3 const *ctx);
61A_INTERN void a_line3_tgt(a_line3 const *ctx, a_point3 *res);
69A_INTERN void a_line3_set_org(a_line3 *ctx, a_real x, a_real y, a_real z);
75A_INTERN void a_line3_set_max(a_line3 *ctx, a_real max);
76
87A_EXTERN int a_line3_set_dir(a_line3 *ctx, a_real x, a_real y, a_real z);
98A_EXTERN int a_line3_set_tgt(a_line3 *ctx, a_real x, a_real y, a_real z);
108A_EXTERN int a_line3_setv(a_line3 *ctx, a_point3 const *p, a_vector3 const *v);
118A_EXTERN int a_line3_set(a_line3 *ctx, a_point3 const *p, a_point3 const *q);
129A_INTERN void a_line3_eval(a_line3 const *ctx, a_real w, a_point3 *res);
140A_EXTERN a_real a_line3_parm(a_line3 const *ctx, a_point3 const *rhs);
155A_EXTERN a_real a_line3_proj(a_line3 const *ctx, a_point3 const *rhs, a_point3 *res);
164A_EXTERN a_real a_line3_limparm(a_line3 const *ctx, a_real min, a_real max, a_point3 const *rhs);
174A_EXTERN a_real a_line3_limproj(a_line3 const *ctx, a_real min, a_real max, a_point3 const *rhs, a_point3 *res);
175
182A_EXTERN a_real a_line3_dist(a_line3 const *ctx, a_point3 const *rhs);
189A_EXTERN a_real a_line3_dist2(a_line3 const *ctx, a_point3 const *rhs);
190
201A_EXTERN a_real a_line3_limdist(a_line3 const *ctx, a_real min, a_real max, a_point3 const *rhs, a_real *w, a_point3 *p);
212A_EXTERN a_real a_line3_limdist2(a_line3 const *ctx, a_real min, a_real max, a_point3 const *rhs, a_real *w, a_point3 *p);
213
228A_EXTERN a_real a_line3_segdist(a_line3 const *ctx, a_real min1, a_real max1,
229 a_line3 const *rhs, a_real min2, a_real max2,
230 a_real *w1, a_point3 *p1, a_real *w2, a_point3 *p2);
245A_EXTERN a_real a_line3_segdist2(a_line3 const *ctx, a_real min1, a_real max1,
246 a_line3 const *rhs, a_real min2, a_real max2,
247 a_real *w1, a_point3 *p1, a_real *w2, a_point3 *p2);
248
260A_EXTERN int a_line3_int0(a_line3 const *ctx, a_real min, a_real max, a_point3 const *rhs, a_real *w);
276A_EXTERN int a_line3_int1(a_line3 const *ctx, a_real min1, a_real max1,
277 a_line3 const *rhs, a_real min2, a_real max2,
278 a_real *w1, a_real *w2);
279
288A_EXTERN void a_line3_rot_(a_line3 const *ctx, a_line3 const *rhs, a_real sin, a_real cos, a_line3 *res);
296A_EXTERN void a_line3_rot(a_line3 const *ctx, a_line3 const *rhs, a_real angle, a_line3 *res);
297
298#if !defined A_HAVE_INLINE || defined(LIBA_LINE3_C)
300#undef A_INTERN
301#define A_INTERN static A_INLINE
303#endif /* A_HAVE_INLINE */
304#if defined(__cplusplus)
305} /* extern "C" */
306#endif /* __cplusplus */
307
312{
316#if defined(__cplusplus)
318 A_INLINE void set_max(a_real max_) { max = max_; }
320 A_INLINE void set_org(a_real x, a_real y, a_real z)
321 {
322 a_line3_set_org(this, x, y, z);
323 }
324
325 A_INLINE a_vector3 const &dir() const { return dir_; }
327 A_INLINE int set_dir(a_real x, a_real y, a_real z)
328 {
329 return a_line3_set_dir(this, x, y, z);
330 }
331
332 A_INLINE void tgt(a_point3 &res) const { a_line3_tgt(this, &res); }
334 A_INLINE int set_tgt(a_real x, a_real y, a_real z)
335 {
336 return a_line3_set_tgt(this, x, y, z);
337 }
338
339 A_INLINE int set(a_point3 const &p, a_vector3 const &v)
340 {
341 return a_line3_setv(this, &p, &v);
342 }
343
344 A_INLINE int set(a_point3 const &p, a_point3 const &q)
345 {
346 return a_line3_set(this, &p, &q);
347 }
348
349 A_INLINE void eval(a_real w, a_point3 &res) const
350 {
351 a_line3_eval(this, w, &res);
352 }
353
354 A_INLINE a_real parm(a_point3 const &rhs) const
355 {
356 return a_line3_parm(this, &rhs);
357 }
358
359 A_INLINE a_real proj(a_point3 const &rhs, a_point3 &res) const
360 {
361 return a_line3_proj(this, &rhs, &res);
362 }
363
364 A_INLINE a_real limparm(a_real min_, a_real max_, a_point3 const &rhs) const
365 {
366 return a_line3_limparm(this, min_, max_, &rhs);
367 }
368
369 A_INLINE a_real limproj(a_real min_, a_real max_, a_point3 const &rhs, a_point3 &res) const
370 {
371 return a_line3_limproj(this, min_, max_, &rhs, &res);
372 }
373
374 A_INLINE a_real dist(a_point3 const &rhs) const
375 {
376 return a_line3_dist(this, &rhs);
377 }
378
379 A_INLINE a_real dist2(a_point3 const &rhs) const
380 {
381 return a_line3_dist2(this, &rhs);
382 }
383
384 A_INLINE a_real limdist(a_real min_, a_real max_, a_point3 const &rhs, a_real &w, a_point3 &p)
385 {
386 return a_line3_limdist(this, min_, max_, &rhs, &w, &p);
387 }
388
389 A_INLINE a_real limdist2(a_real min_, a_real max_, a_point3 const &rhs, a_real &w, a_point3 &p)
390 {
391 return a_line3_limdist2(this, min_, max_, &rhs, &w, &p);
392 }
393
394 A_INLINE a_real segdist(a_real min1, a_real max1, a_line3 const &rhs, a_real min2, a_real max2,
395 a_real &w1, a_point3 &p1, a_real &w2, a_point3 &p2) const
396 {
397 return a_line3_segdist(this, min1, max1, &rhs, min2, max2, &w1, &p1, &w2, &p2);
398 }
399
400 A_INLINE a_real segdist2(a_real min1, a_real max1, a_line3 const &rhs, a_real min2, a_real max2,
401 a_real &w1, a_point3 &p1, a_real &w2, a_point3 &p2) const
402 {
403 return a_line3_segdist2(this, min1, max1, &rhs, min2, max2, &w1, &p1, &w2, &p2);
404 }
405
406 A_INLINE int int0(a_real min_, a_real max_, a_point3 const &rhs, a_real &w) const
407 {
408 return a_line3_int0(this, min_, max_, &rhs, &w);
409 }
410
411 A_INLINE int int1(a_real min1, a_real max1, a_line3 const &rhs, a_real min2, a_real max2,
412 a_real &w1, a_real &w2) const
413 {
414 return a_line3_int1(this, min1, max1, &rhs, min2, max2, &w1, &w2);
415 }
416
417 A_INLINE void rot(a_line3 const &rhs, a_real sin, a_real cos, a_line3 &res) const
418 {
419 a_line3_rot_(this, &rhs, sin, cos, &res);
420 }
421
422 A_INLINE void rot(a_line3 const &rhs, a_real angle, a_line3 &res) const
423 {
424 a_line3_rot(this, &rhs, angle, &res);
425 }
426#endif /* __cplusplus */
427};
428
429#if defined(LIBA_LINE3_C)
431#undef A_INTERN
432#define A_INTERN A_INLINE
434#endif /* LIBA_LINE3_C */
435#if defined(A_HAVE_INLINE) || defined(LIBA_LINE3_C)
436
437A_INTERN a_real a_line3_max(a_line3 const *ctx)
438{
439 return ctx->max;
440}
441A_INTERN a_point3 const *a_line3_org(a_line3 const *ctx)
442{
443 return &ctx->org;
444}
445A_INTERN a_vector3 const *a_line3_dir(a_line3 const *ctx)
446{
447 return &ctx->dir_;
448}
449A_INTERN void a_line3_tgt(a_line3 const *ctx, a_point3 *res)
450{
451 a_line3_eval(ctx, ctx->max, res);
452}
453A_INTERN void a_line3_set_org(a_line3 *ctx, a_real x, a_real y, a_real z)
454{
455 ctx->org.x = x;
456 ctx->org.y = y;
457 ctx->org.z = z;
458}
459A_INTERN void a_line3_set_max(a_line3 *ctx, a_real max)
460{
461 ctx->max = max;
462}
463
464A_INTERN void a_line3_eval(a_line3 const *ctx, a_real w, a_point3 *res)
465{
466 a_point3 const *const o = &ctx->org;
467 a_vector3 const *const d = &ctx->dir_;
468 res->x = o->x + d->x * w;
469 res->y = o->y + d->y * w;
470 res->z = o->z + d->z * w;
471}
472
473#endif /* A_HAVE_INLINE */
474#if defined(LIBA_LINE3_C)
476#undef A_INTERN
477#define A_INTERN static A_INLINE
479#endif /* LIBA_LINE3_C */
480
482
483#endif /* a/line3.h */
algorithm library
a_real a_line3_limdist(a_line3 const *ctx, a_real min, a_real max, a_point3 const *rhs, a_real *w, a_point3 *p)
compute the distance from a point to the closest point on a line segment.
int a_line3_set(a_line3 *ctx, a_point3 const *p, a_point3 const *q)
initialize the line segment from two points (start point p, end point q).
a_real a_line3_max(a_line3 const *ctx)
get the maximum length of the line segment.
a_real a_line3_segdist2(a_line3 const *ctx, a_real min1, a_real max1, a_line3 const *rhs, a_real min2, a_real max2, a_real *w1, a_point3 *p1, a_real *w2, a_point3 *p2)
compute the squared distance between two line segments.
a_real a_line3_parm(a_line3 const *ctx, a_point3 const *rhs)
compute the scalar projection parameter of a point onto the infinite line.
a_real a_line3_dist(a_line3 const *ctx, a_point3 const *rhs)
compute the distance from a point to the infinite line.
a_real a_line3_proj(a_line3 const *ctx, a_point3 const *rhs, a_point3 *res)
project a point onto the infinite line.
int a_line3_int0(a_line3 const *ctx, a_real min, a_real max, a_point3 const *rhs, a_real *w)
compute the intersection between a point and a line segment.
int a_line3_setv(a_line3 *ctx, a_point3 const *p, a_vector3 const *v)
initialize the line segment from a start point and a direction vector.
void a_line3_set_org(a_line3 *ctx, a_real x, a_real y, a_real z)
set the origin coordinates of the line.
void a_line3_eval(a_line3 const *ctx, a_real w, a_point3 *res)
evaluate a point on the line at a given parameter.
a_real a_line3_limproj(a_line3 const *ctx, a_real min, a_real max, a_point3 const *rhs, a_point3 *res)
project a point onto a line segment.
a_real a_line3_limdist2(a_line3 const *ctx, a_real min, a_real max, a_point3 const *rhs, a_real *w, a_point3 *p)
compute the squared distance from a point to the closest point on a line segment.
a_vector3 const * a_line3_dir(a_line3 const *ctx)
get the address of the direction vector of the line.
void a_line3_tgt(a_line3 const *ctx, a_point3 *res)
compute the target endpoint of the line segment.
int a_line3_set_tgt(a_line3 *ctx, a_real x, a_real y, a_real z)
Set the line direction and length based on a target point relative to the current origin.
a_real a_line3_dist2(a_line3 const *ctx, a_point3 const *rhs)
compute the squared distance from a point to the infinite line.
a_real a_line3_limparm(a_line3 const *ctx, a_real min, a_real max, a_point3 const *rhs)
compute the scalar projection parameter of a point onto the line segment.
a_point3 const * a_line3_org(a_line3 const *ctx)
get the address of the origin point of the line.
a_real a_line3_segdist(a_line3 const *ctx, a_real min1, a_real max1, a_line3 const *rhs, a_real min2, a_real max2, a_real *w1, a_point3 *p1, a_real *w2, a_point3 *p2)
compute the distance between two line segments.
int a_line3_int1(a_line3 const *ctx, a_real min1, a_real max1, a_line3 const *rhs, a_real min2, a_real max2, a_real *w1, a_real *w2)
compute the intersection between two line segments.
void a_line3_rot(a_line3 const *ctx, a_line3 const *rhs, a_real angle, a_line3 *res)
rotate a 3D line segment around an arbitrary axis defined by another line.
void a_line3_set_max(a_line3 *ctx, a_real max)
set the maximum length of the line segment.
int a_line3_set_dir(a_line3 *ctx, a_real x, a_real y, a_real z)
set the direction vector and length of the line using raw components.
void a_line3_rot_(a_line3 const *ctx, a_line3 const *rhs, a_real sin, a_real cos, a_line3 *res)
rotate a 3D line segment around an arbitrary axis defined by another line.
double a_real
compiler built-in floating-point number type
Definition a.h:1012
three-dimensional point
instance structure for three-dimensional line defined by an origin, a direction vector,...
Definition line3.h:312
a_vector3 dir_
Definition line3.h:314
a_point3 org
Definition line3.h:313
a_real parm(a_point3 const &rhs) const
compute the scalar projection parameter of a point onto the infinite line.
Definition line3.h:354
int int1(a_real min1, a_real max1, a_line3 const &rhs, a_real min2, a_real max2, a_real &w1, a_real &w2) const
compute the intersection between two line segments.
Definition line3.h:411
a_real segdist2(a_real min1, a_real max1, a_line3 const &rhs, a_real min2, a_real max2, a_real &w1, a_point3 &p1, a_real &w2, a_point3 &p2) const
compute the squared distance between two line segments.
Definition line3.h:400
a_real limdist2(a_real min_, a_real max_, a_point3 const &rhs, a_real &w, a_point3 &p)
compute the squared distance from a point to the closest point on a line segment.
Definition line3.h:389
a_vector3 const & dir() const
get the address of the direction vector of the line.
Definition line3.h:325
a_real limproj(a_real min_, a_real max_, a_point3 const &rhs, a_point3 &res) const
project a point onto a line segment.
Definition line3.h:369
a_real dist(a_point3 const &rhs) const
compute the distance from a point to the infinite line.
Definition line3.h:374
a_real limdist(a_real min_, a_real max_, a_point3 const &rhs, a_real &w, a_point3 &p)
compute the distance from a point to the closest point on a line segment.
Definition line3.h:384
a_real segdist(a_real min1, a_real max1, a_line3 const &rhs, a_real min2, a_real max2, a_real &w1, a_point3 &p1, a_real &w2, a_point3 &p2) const
compute the distance between two line segments.
Definition line3.h:394
int int0(a_real min_, a_real max_, a_point3 const &rhs, a_real &w) const
compute the intersection between a point and a line segment.
Definition line3.h:406
a_real limparm(a_real min_, a_real max_, a_point3 const &rhs) const
compute the scalar projection parameter of a point onto the line segment.
Definition line3.h:364
int set_dir(a_real x, a_real y, a_real z)
set the direction vector and length of the line using raw components.
Definition line3.h:327
int set(a_point3 const &p, a_vector3 const &v)
initialize the line segment from a start point and a direction vector.
Definition line3.h:339
void rot(a_line3 const &rhs, a_real angle, a_line3 &res) const
rotate a 3D line segment around an arbitrary axis defined by another line.
Definition line3.h:422
void eval(a_real w, a_point3 &res) const
evaluate a point on the line at a given parameter.
Definition line3.h:349
void set_org(a_real x, a_real y, a_real z)
set the origin coordinates of the line.
Definition line3.h:320
a_real dist2(a_point3 const &rhs) const
compute the squared distance from a point to the infinite line.
Definition line3.h:379
void tgt(a_point3 &res) const
compute the target endpoint of the line segment.
Definition line3.h:332
a_real max
Definition line3.h:315
int set_tgt(a_real x, a_real y, a_real z)
Set the line direction and length based on a target point relative to the current origin.
Definition line3.h:334
a_real proj(a_point3 const &rhs, a_point3 &res) const
project a point onto the infinite line.
Definition line3.h:359
int set(a_point3 const &p, a_point3 const &q)
initialize the line segment from two points (start point p, end point q).
Definition line3.h:344
void rot(a_line3 const &rhs, a_real sin, a_real cos, a_line3 &res) const
rotate a 3D line segment around an arbitrary axis defined by another line.
Definition line3.h:417
void set_max(a_real max_)
set the maximum length of the line segment.
Definition line3.h:318
instance structure for three-dimensional point
Definition point3.h:350
instance structure for three-dimensional vector
Definition vector3.h:415