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);
125A_INTERN void a_line3_eval(a_line3 const *ctx, a_real w, a_point3 *res);
132A_EXTERN a_real a_line3_parm(a_line3 const *ctx, a_point3 const *rhs);
140A_EXTERN a_real a_line3_proj(a_line3 const *ctx, a_point3 const *rhs, a_point3 *res);
149A_EXTERN a_real a_line3_limparm(a_line3 const *ctx, a_real min, a_real max, a_point3 const *rhs);
159A_EXTERN a_real a_line3_limproj(a_line3 const *ctx, a_real min, a_real max, a_point3 const *rhs, a_point3 *res);
160
167A_EXTERN a_real a_line3_dist(a_line3 const *ctx, a_point3 const *rhs);
174A_EXTERN a_real a_line3_dist2(a_line3 const *ctx, a_point3 const *rhs);
175
186A_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);
197A_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);
198
213A_EXTERN a_real a_line3_segdist(a_line3 const *ctx, a_real min1, a_real max1,
214 a_line3 const *rhs, a_real min2, a_real max2,
215 a_real *w1, a_point3 *p1, a_real *w2, a_point3 *p2);
230A_EXTERN a_real a_line3_segdist2(a_line3 const *ctx, a_real min1, a_real max1,
231 a_line3 const *rhs, a_real min2, a_real max2,
232 a_real *w1, a_point3 *p1, a_real *w2, a_point3 *p2);
233
245A_EXTERN int a_line3_int0(a_line3 const *ctx, a_real min, a_real max, a_point3 const *rhs, a_real *w);
261A_EXTERN int a_line3_int1(a_line3 const *ctx, a_real min1, a_real max1,
262 a_line3 const *rhs, a_real min2, a_real max2,
263 a_real *w1, a_real *w2);
264
273A_EXTERN void a_line3_rot_(a_line3 const *ctx, a_line3 const *rhs, a_real sin, a_real cos, a_line3 *res);
281A_EXTERN void a_line3_rot(a_line3 const *ctx, a_line3 const *rhs, a_real angle, a_line3 *res);
282
283#if !defined A_HAVE_INLINE || defined(LIBA_LINE3_C)
285#undef A_INTERN
286#define A_INTERN static A_INLINE
288#endif /* A_HAVE_INLINE */
289#if defined(__cplusplus)
290} /* extern "C" */
291#endif /* __cplusplus */
292
297{
301#if defined(__cplusplus)
303 A_INLINE void set_max(a_real max_) { max = max_; }
305 A_INLINE void set_org(a_real x, a_real y, a_real z)
306 {
307 a_line3_set_org(this, x, y, z);
308 }
309
310 A_INLINE a_vector3 const &dir() const { return dir_; }
312 A_INLINE int set_dir(a_real x, a_real y, a_real z)
313 {
314 return a_line3_set_dir(this, x, y, z);
315 }
316
317 A_INLINE void tgt(a_point3 &res) const { a_line3_tgt(this, &res); }
319 A_INLINE int set_tgt(a_real x, a_real y, a_real z)
320 {
321 return a_line3_set_tgt(this, x, y, z);
322 }
323
324 A_INLINE int set(a_point3 const &p, a_vector3 const &v)
325 {
326 return a_line3_setv(this, &p, &v);
327 }
328
329 A_INLINE int set(a_point3 const &p, a_point3 const &q)
330 {
331 return a_line3_set(this, &p, &q);
332 }
333
334 A_INLINE void eval(a_real w, a_point3 &res) const
335 {
336 a_line3_eval(this, w, &res);
337 }
338
339 A_INLINE a_real parm(a_point3 const &rhs) const
340 {
341 return a_line3_parm(this, &rhs);
342 }
343
344 A_INLINE a_real proj(a_point3 const &rhs, a_point3 &res) const
345 {
346 return a_line3_proj(this, &rhs, &res);
347 }
348
349 A_INLINE a_real limparm(a_real min_, a_real max_, a_point3 const &rhs) const
350 {
351 return a_line3_limparm(this, min_, max_, &rhs);
352 }
353
354 A_INLINE a_real limproj(a_real min_, a_real max_, a_point3 const &rhs, a_point3 &res) const
355 {
356 return a_line3_limproj(this, min_, max_, &rhs, &res);
357 }
358
359 A_INLINE a_real dist(a_point3 const &rhs) const
360 {
361 return a_line3_dist(this, &rhs);
362 }
363
364 A_INLINE a_real dist2(a_point3 const &rhs) const
365 {
366 return a_line3_dist2(this, &rhs);
367 }
368
369 A_INLINE a_real limdist(a_real min_, a_real max_, a_point3 const &rhs, a_real &w, a_point3 &p)
370 {
371 return a_line3_limdist(this, min_, max_, &rhs, &w, &p);
372 }
373
374 A_INLINE a_real limdist2(a_real min_, a_real max_, a_point3 const &rhs, a_real &w, a_point3 &p)
375 {
376 return a_line3_limdist2(this, min_, max_, &rhs, &w, &p);
377 }
378
379 A_INLINE a_real segdist(a_real min1, a_real max1, a_line3 const &rhs, a_real min2, a_real max2,
380 a_real &w1, a_point3 &p1, a_real &w2, a_point3 &p2) const
381 {
382 return a_line3_segdist(this, min1, max1, &rhs, min2, max2, &w1, &p1, &w2, &p2);
383 }
384
385 A_INLINE a_real segdist2(a_real min1, a_real max1, a_line3 const &rhs, a_real min2, a_real max2,
386 a_real &w1, a_point3 &p1, a_real &w2, a_point3 &p2) const
387 {
388 return a_line3_segdist2(this, min1, max1, &rhs, min2, max2, &w1, &p1, &w2, &p2);
389 }
390
391 A_INLINE int int0(a_real min_, a_real max_, a_point3 const &rhs, a_real &w) const
392 {
393 return a_line3_int0(this, min_, max_, &rhs, &w);
394 }
395
396 A_INLINE int int1(a_real min1, a_real max1, a_line3 const &rhs, a_real min2, a_real max2,
397 a_real &w1, a_real &w2) const
398 {
399 return a_line3_int1(this, min1, max1, &rhs, min2, max2, &w1, &w2);
400 }
401
402 A_INLINE void rot(a_line3 const &rhs, a_real sin, a_real cos, a_line3 &res) const
403 {
404 a_line3_rot_(this, &rhs, sin, cos, &res);
405 }
406
407 A_INLINE void rot(a_line3 const &rhs, a_real angle, a_line3 &res) const
408 {
409 a_line3_rot(this, &rhs, angle, &res);
410 }
411#endif /* __cplusplus */
412};
413
414#if defined(LIBA_LINE3_C)
416#undef A_INTERN
417#define A_INTERN A_INLINE
419#endif /* LIBA_LINE3_C */
420#if defined(A_HAVE_INLINE) || defined(LIBA_LINE3_C)
421
422A_INTERN a_real a_line3_max(a_line3 const *ctx)
423{
424 return ctx->max;
425}
426A_INTERN a_point3 const *a_line3_org(a_line3 const *ctx)
427{
428 return &ctx->org;
429}
430A_INTERN a_vector3 const *a_line3_dir(a_line3 const *ctx)
431{
432 return &ctx->dir_;
433}
434A_INTERN void a_line3_tgt(a_line3 const *ctx, a_point3 *res)
435{
436 a_line3_eval(ctx, ctx->max, res);
437}
438A_INTERN void a_line3_set_org(a_line3 *ctx, a_real x, a_real y, a_real z)
439{
440 ctx->org.x = x;
441 ctx->org.y = y;
442 ctx->org.z = z;
443}
444A_INTERN void a_line3_set_max(a_line3 *ctx, a_real max)
445{
446 ctx->max = max;
447}
448
449A_INTERN void a_line3_eval(a_line3 const *ctx, a_real w, a_point3 *res)
450{
451 a_point3 const *const o = &ctx->org;
452 a_vector3 const *const d = &ctx->dir_;
453 res->x = o->x + d->x * w;
454 res->y = o->y + d->y * w;
455 res->z = o->z + d->z * w;
456}
457
458#endif /* A_HAVE_INLINE */
459#if defined(LIBA_LINE3_C)
461#undef A_INTERN
462#define A_INTERN static A_INLINE
464#endif /* LIBA_LINE3_C */
465
467
468#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:297
a_vector3 dir_
Definition line3.h:299
a_point3 org
Definition line3.h:298
a_real parm(a_point3 const &rhs) const
compute the scalar projection parameter of a point onto the infinite line.
Definition line3.h:339
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:396
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:385
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:374
a_vector3 const & dir() const
get the address of the direction vector of the line.
Definition line3.h:310
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:354
a_real dist(a_point3 const &rhs) const
compute the distance from a point to the infinite line.
Definition line3.h:359
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:369
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:379
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:391
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:349
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:312
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:324
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:407
void eval(a_real w, a_point3 &res) const
evaluate a point on the line at a given parameter.
Definition line3.h:334
void set_org(a_real x, a_real y, a_real z)
set the origin coordinates of the line.
Definition line3.h:305
a_real dist2(a_point3 const &rhs) const
compute the squared distance from a point to the infinite line.
Definition line3.h:364
void tgt(a_point3 &res) const
compute the target endpoint of the line segment.
Definition line3.h:317
a_real max
Definition line3.h:300
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:319
a_real proj(a_point3 const &rhs, a_point3 &res) const
project a point onto the infinite line.
Definition line3.h:344
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:329
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:402
void set_max(a_real max_)
set the maximum length of the line segment.
Definition line3.h:303
instance structure for three-dimensional point
Definition point3.h:350
instance structure for three-dimensional vector
Definition vector3.h:415