ai_vector.h
Go to the documentation of this file.
1// Copyright 2021 Autodesk, Inc. All rights reserved.
2//
3// Use of this software is subject to the terms of the Autodesk license
4// agreement provided at the time of installation or download, or which
5// otherwise accompanies this software in either electronic or hard copy form.
6
12#pragma once
13#include "ai_comparison.h"
14#include "ai_constants.h"
15#include "ai_math.h"
16#include "ai_api.h"
17#include <cmath>
18
30{
31 float x, y, z;
32
33 AtVector() = default;
34 AI_DEVICE constexpr AtVector(float x, float y, float z) : x(x), y(y), z(z) { }
35
36 AI_DEVICE constexpr AtVector operator+(const AtVector& p) const
37 {
38 return AtVector(x + p.x,
39 y + p.y,
40 z + p.z);
41 }
42
43 AI_DEVICE AtVector& operator+=(const AtVector& p)
44 {
45 x += p.x;
46 y += p.y;
47 z += p.z;
48 return *this;
49 }
50
51 AI_DEVICE constexpr AtVector operator+(float f) const
52 {
53 return AtVector(x + f,
54 y + f,
55 z + f);
56 }
57
58 AI_DEVICE AtVector& operator+=(float f)
59 {
60 x += f;
61 y += f;
62 z += f;
63 return *this;
64 }
65
66 AI_DEVICE constexpr AtVector operator-(const AtVector& p) const
67 {
68 return AtVector(x - p.x,
69 y - p.y,
70 z - p.z);
71 }
72
73 AI_DEVICE AtVector& operator-=(const AtVector& p)
74 {
75 x -= p.x;
76 y -= p.y;
77 z -= p.z;
78 return *this;
79 }
80
81 AI_DEVICE constexpr AtVector operator-(float f) const
82 {
83 return AtVector(x - f,
84 y - f,
85 z - f);
86 }
87
88 AI_DEVICE AtVector& operator-=(float f)
89 {
90 x -= f;
91 y -= f;
92 z -= f;
93 return *this;
94 }
95
96 AI_DEVICE constexpr AtVector operator-() const
97 {
98 return AtVector(-x, -y, -z);
99 }
100
101 AI_DEVICE constexpr AtVector operator*(const AtVector& p) const
102 {
103 return AtVector(x * p.x,
104 y * p.y,
105 z * p.z);
106 }
107
108 AI_DEVICE AtVector operator*=(const AtVector& p)
109 {
110 x *= p.x;
111 y *= p.y;
112 z *= p.z;
113 return *this;
114 }
115
116 AI_DEVICE constexpr AtVector operator*(float f) const
117 {
118 return AtVector(x * f,
119 y * f,
120 z * f);
121 }
122
123 AI_DEVICE AtVector operator*=(float f)
124 {
125 x *= f;
126 y *= f;
127 z *= f;
128 return *this;
129 }
130
131 AI_DEVICE constexpr AtVector operator/(const AtVector& p) const
132 {
133 return AtVector(x / p.x,
134 y / p.y,
135 z / p.z);
136 }
137
138 AI_DEVICE AtVector operator/=(const AtVector& p)
139 {
140 x /= p.x;
141 y /= p.y;
142 z /= p.z;
143 return *this;
144 }
145
146 AI_DEVICE AtVector operator/(float f) const
147 {
148 return AtVector(x / f,
149 y / f,
150 z / f);
151 }
152
153 AI_DEVICE AtVector operator/=(float f)
154 {
155 x /= f;
156 y /= f;
157 z /= f;
158 return *this;
159 }
160
161 AI_DEVICE constexpr bool operator==(const AtVector& p) const
162 {
163 return (x == p.x && y == p.y && z == p.z);
164 }
165
166 AI_DEVICE constexpr bool operator!=(const AtVector& p) const
167 {
168 return !(*this == p);
169 }
170
171 AI_DEVICE AtVector& operator=(float f)
172 {
173 x = f;
174 y = f;
175 z = f;
176 return *this;
177 }
178
179 AI_DEVICE float& operator[](unsigned int i)
180 {
181 return *(&x + i); // no bounds checking!
182 }
183
184 AI_DEVICE constexpr const float& operator[](unsigned int i) const
185 {
186 return *(&x + i); // no bounds checking!
187 }
188
189 AI_DEVICE friend constexpr AtVector operator*(float f, const AtVector& p);
190 AI_DEVICE friend constexpr AtVector operator+(float f, const AtVector& p);
191 AI_DEVICE friend constexpr AtVector operator-(float f, const AtVector& p);
192};
193
194AI_DEVICE inline constexpr AtVector operator*(float f, const AtVector& p)
195{
196 return p * f;
197}
198
199AI_DEVICE inline constexpr AtVector operator+(float f, const AtVector& p)
200{
201 return p + f;
202}
203
204AI_DEVICE inline constexpr AtVector operator-(float f, const AtVector& p)
205{
206 return AtVector(f - p.x,
207 f - p.y,
208 f - p.z);
209}
210
211AI_DEVICE inline AtBooleanMask<3> operator<(const AtVector& lhs, float f)
212{
213 return AtBooleanMask<3>::lt(&lhs[0], f);
214}
215
216AI_DEVICE inline AtBooleanMask<3> operator<=(const AtVector& lhs, float f)
217{
218 return AtBooleanMask<3>::le(&lhs[0], f);
219}
220
221AI_DEVICE inline AtBooleanMask<3> operator>(const AtVector& lhs, float f)
222{
223 return AtBooleanMask<3>::gt(&lhs[0], f);
224}
225
226AI_DEVICE inline AtBooleanMask<3> operator>=(const AtVector& lhs, float f)
227{
228 return AtBooleanMask<3>::ge(&lhs[0], f);
229}
230
231AI_DEVICE inline AtBooleanMask<3> operator<(const AtVector& lhs, const AtVector& rhs)
232{
233 return AtBooleanMask<3>::lt(&lhs[0], &rhs[0]);
234}
235
236AI_DEVICE inline AtBooleanMask<3> operator<=(const AtVector& lhs, const AtVector& rhs)
237{
238 return AtBooleanMask<3>::le(&lhs[0], &rhs[0]);
239}
240
241AI_DEVICE inline AtBooleanMask<3> operator>(const AtVector& lhs, const AtVector& rhs)
242{
243 return AtBooleanMask<3>::gt(&lhs[0], &rhs[0]);
244}
245
246AI_DEVICE inline AtBooleanMask<3> operator>=(const AtVector& lhs, const AtVector& rhs)
247{
248 return AtBooleanMask<3>::ge(&lhs[0], &rhs[0]);
249}
250
255{
256 float x, y;
257
258 AtVector2() = default;
259 AI_DEVICE constexpr AtVector2(float x, float y) : x(x), y(y) { }
260
261 AI_DEVICE constexpr AtVector2(const AtVector& v) : x(v.x), y(v.y) { }
262
263 AI_DEVICE constexpr AtVector2 operator+(const AtVector2& p) const
264 {
265 return AtVector2(x + p.x,
266 y + p.y);
267 }
268
269 AI_DEVICE AtVector2& operator+=(const AtVector2& p)
270 {
271 x += p.x;
272 y += p.y;
273 return *this;
274 }
275
276 AI_DEVICE constexpr AtVector2 operator+(float f) const
277 {
278 return AtVector2(x + f,
279 y + f);
280 }
281
282 AI_DEVICE AtVector2& operator+=(float f)
283 {
284 x += f;
285 y += f;
286 return *this;
287 }
288
289 AI_DEVICE constexpr AtVector2 operator-(const AtVector2& p) const
290 {
291 return AtVector2(x - p.x,
292 y - p.y);
293 }
294
295 AI_DEVICE AtVector2& operator-=(const AtVector2& p)
296 {
297 x -= p.x;
298 y -= p.y;
299 return *this;
300 }
301
302 AI_DEVICE constexpr AtVector2 operator-(float f) const
303 {
304 return AtVector2(x - f,
305 y - f);
306 }
307
308 AI_DEVICE AtVector2& operator-=(float f)
309 {
310 x -= f;
311 y -= f;
312 return *this;
313 }
314
315 AI_DEVICE constexpr AtVector2 operator-() const
316 {
317 return AtVector2(-x, -y);
318 }
319
320 AI_DEVICE constexpr AtVector2 operator*(const AtVector2& p) const
321 {
322 return AtVector2(x * p.x,
323 y * p.y);
324 }
325
326 AI_DEVICE AtVector2 operator*=(const AtVector2& p)
327 {
328 x *= p.x;
329 y *= p.y;
330 return *this;
331 }
332
333 AI_DEVICE constexpr AtVector2 operator*(float f) const
334 {
335 return AtVector2(x * f,
336 y * f);
337 }
338
339 AI_DEVICE AtVector2 operator*=(float f)
340 {
341 x *= f;
342 y *= f;
343 return *this;
344 }
345
346 AI_DEVICE constexpr AtVector2 operator/(const AtVector2& p) const
347 {
348 return AtVector2(x / p.x,
349 y / p.y);
350 }
351
352 AI_DEVICE AtVector2 operator/=(const AtVector2& p)
353 {
354 x /= p.x;
355 y /= p.y;
356 return *this;
357 }
358
359 AI_DEVICE AtVector2 operator/(float f) const
360 {
361 return AtVector2(x / f,
362 y / f);
363 }
364
365 AI_DEVICE AtVector2 operator/=(float f)
366 {
367 x /= f;
368 y /= f;
369 return *this;
370 }
371
372 AI_DEVICE constexpr bool operator==(const AtVector2& p) const
373 {
374 return (x == p.x && y == p.y);
375 }
376
377 AI_DEVICE constexpr bool operator!=(const AtVector2& p) const
378 {
379 return !(*this == p);
380 }
381
382 AI_DEVICE AtVector2& operator=(float f)
383 {
384 x = f;
385 y = f;
386 return *this;
387 }
388
389 AI_DEVICE float& operator[](unsigned int i)
390 {
391 return *(&x + i); // no bounds checking!
392 }
393
394 AI_DEVICE constexpr const float& operator[](unsigned int i) const
395 {
396 return *(&x + i); // no bounds checking!
397 }
398
399 AI_DEVICE friend constexpr AtVector2 operator*(float f, const AtVector2& p);
400 AI_DEVICE friend constexpr AtVector2 operator+(float f, const AtVector2& p);
401 AI_DEVICE friend constexpr AtVector2 operator-(float f, const AtVector2& p);
402};
403
404AI_DEVICE inline constexpr AtVector2 operator*(float f, const AtVector2& p)
405{
406 return p * f;
407}
408
409AI_DEVICE inline constexpr AtVector2 operator+(float f, const AtVector2& p)
410{
411 return p + f;
412}
413
414AI_DEVICE inline constexpr AtVector2 operator-(float f, const AtVector2& p)
415{
416 return AtVector2(f - p.x,
417 f - p.y);
418}
419
420AI_DEVICE inline AtBooleanMask<2> operator<(const AtVector2& lhs, float f)
421{
422 return AtBooleanMask<2>::lt(&lhs[0], f);
423}
424
425AI_DEVICE inline AtBooleanMask<2> operator<=(const AtVector2& lhs, float f)
426{
427 return AtBooleanMask<2>::le(&lhs[0], f);
428}
429
430AI_DEVICE inline AtBooleanMask<2> operator>(const AtVector2& lhs, float f)
431{
432 return AtBooleanMask<2>::gt(&lhs[0], f);
433}
434
435AI_DEVICE inline AtBooleanMask<2> operator>=(const AtVector2& lhs, float f)
436{
437 return AtBooleanMask<2>::ge(&lhs[0], f);
438}
439
440AI_DEVICE inline AtBooleanMask<2> operator<(const AtVector2& lhs, const AtVector2& rhs)
441{
442 return AtBooleanMask<2>::lt(&lhs[0], &rhs[0]);
443}
444
445AI_DEVICE inline AtBooleanMask<2> operator<=(const AtVector2& lhs, const AtVector2& rhs)
446{
447 return AtBooleanMask<2>::le(&lhs[0], &rhs[0]);
448}
449
450AI_DEVICE inline AtBooleanMask<2> operator>(const AtVector2& lhs, const AtVector2& rhs)
451{
452 return AtBooleanMask<2>::gt(&lhs[0], &rhs[0]);
453}
454
455AI_DEVICE inline AtBooleanMask<2> operator>=(const AtVector2& lhs, const AtVector2& rhs)
456{
457 return AtBooleanMask<2>::ge(&lhs[0], &rhs[0]);
458}
459
460
465{
466 float x, y, z, w;
467
468 AtHPoint() = default;
469 AI_DEVICE constexpr AtHPoint(float x, float y, float z, float w) : x(x), y(y), z(z), w(w) { }
470 AI_DEVICE constexpr AtHPoint(const AtVector& v, float w) : x(v.x), y(v.y), z(v.z), w(w) { }
471
472 AI_DEVICE constexpr AtHPoint operator+(const AtHPoint& p) const
473 {
474 return AtHPoint(x + p.x,
475 y + p.y,
476 z + p.z,
477 w + p.w);
478 }
479
480 AI_DEVICE constexpr AtHPoint operator-(const AtHPoint& p) const
481 {
482 return AtHPoint(x - p.x,
483 y - p.y,
484 z - p.z,
485 w - p.w);
486 }
487
488 AI_DEVICE constexpr AtHPoint operator*(float k) const
489 {
490 return AtHPoint(x * k,
491 y * k,
492 z * k,
493 w * k);
494 }
495
496 AI_DEVICE constexpr AtHPoint operator-() const
497 {
498 return AtHPoint(-x, -y, -z, -w);
499 }
500
504 AI_DEVICE inline AtVector project() const
505 {
506 return w != 0 ?
507 AtVector(x, y, z) / w :
508 AtVector(0, 0, 0);
509 }
510};
511
516 AtVector val, dx, dy;
517
518 AtVectorDv() = default;
519 AI_DEVICE constexpr AtVectorDv(AtVector val, AtVector dx, AtVector dy) : val(val), dx(dx), dy(dy) { }
520 AI_DEVICE constexpr explicit AtVectorDv(AtVector val) : val(val), dx(0, 0, 0), dy(0, 0, 0) { }
521
522 AI_DEVICE constexpr AtVectorDv operator-() const
523 {
524 return AtVectorDv(-val, -dx, -dy);
525 }
526};
527
531#define AI_X 0
532#define AI_Y 1
533#define AI_Z 2
534/*\}*/
535
536
537
545AI_DEVICE inline constexpr float AiV2Dot(const AtVector2& v1, const AtVector2& v2)
546{
547 return v1.x * v2.x + v1.y * v2.y;
548}
549
553AI_DEVICE inline float AiV2Length(const AtVector2& v1)
554{
555 return sqrtf(v1.x * v1.x + v1.y * v1.y);
556}
557
561inline float AiV2Dist(const AtVector2& p1, const AtVector2& p2)
562{
563 return sqrtf(AiSqr(p1.x-p2.x) + AiSqr(p1.y - p2.y));
564}
565
570inline constexpr AtVector2 AiV2Lerp(float t, const AtVector2& lo, const AtVector2& hi)
571{
572 return AiLerp(t, lo, hi);
573}
574
578inline constexpr AtVector2 AiV2Clamp(const AtVector2& in, float lo, float hi)
579{
580 return AtVector2(AiClamp(in.x, lo, hi),
581 AiClamp(in.y, lo, hi));
582}
583
587AI_DEVICE inline AtVector2 ABS(const AtVector2& a)
588{
589 return AtVector2( std::abs(a.x), std::abs(a.y) );
590}
591
595AI_DEVICE inline float AiMaxElement(const AtVector2& a)
596{
597 return AiMax(a.x, a.y);
598}
599
603inline float AiMinElement(const AtVector2& a)
604{
605 return AiMin(a.x, a.y);
606}
607/*\}*/
608
609
610
618AI_DEVICE inline float AiV3Length(const AtVector& a)
619{
620 return sqrtf(a.x*a.x + a.y*a.y + a.z*a.z);
621}
622
626AI_DEVICE inline constexpr float AiV3Dot(const AtVector& a, const AtVector& b)
627{
628 return a.x*b.x + a.y*b.y + a.z*b.z;
629}
630
634AI_DEVICE inline float AiV3Dist(const AtVector& a, const AtVector& b)
635{
636 return sqrtf(AiSqr(a.x-b.x) + AiSqr(a.y-b.y) + AiSqr(a.z-b.z));
637}
638
642AI_DEVICE inline constexpr float AiV3Dist2(const AtVector& a, const AtVector& b)
643{
644 return AiSqr(a.x-b.x) + AiSqr(a.y-b.y) + AiSqr(a.z-b.z);
645}
646
650AI_DEVICE inline constexpr float AiV3DistPlane(const AtVector& x, const AtVector& p, const AtVector& n)
651{
652 return AiV3Dot(x, n) - AiV3Dot(p, n);
653}
654
658AI_DEVICE inline constexpr AtVector AiV3Cross(const AtVector& a, const AtVector& b)
659{
660 return AtVector(a.y * b.z - a.z * b.y,
661 a.z * b.x - a.x * b.z,
662 a.x * b.y - a.y * b.x);
663}
664
668AI_DEVICE inline AtVector AiV3Normalize(const AtVector& a)
669{
670 float len = AiV3Length(a);
671 return len == 0 ? a : a / len;
672}
673
678AI_DEVICE inline constexpr AtVector AiV3Lerp(float t, const AtVector& lo, const AtVector& hi)
679{
680 return AiLerp(t, lo, hi);
681}
682
686AI_DEVICE inline constexpr AtVector AiV3Clamp(const AtVector& in, float lo, float hi)
687{
688 return AtVector(AiClamp(in.x, lo, hi),
689 AiClamp(in.y, lo, hi),
690 AiClamp(in.z, lo, hi));
691}
692
696AI_DEVICE inline constexpr AtVector AiV3Min(const AtVector& a, const AtVector& b)
697{
698 return AtVector(AiMin(a.x, b.x),
699 AiMin(a.y, b.y),
700 AiMin(a.z, b.z));
701}
702
706AI_DEVICE inline constexpr AtVector AiV3Max(const AtVector& a, const AtVector& b)
707{
708 return AtVector(AiMax(a.x, b.x),
709 AiMax(a.y, b.y),
710 AiMax(a.z, b.z));
711}
712
716AI_DEVICE inline AtVector ABS(const AtVector& a)
717{
718 return AtVector( std::abs(a.x), std::abs(a.y), std::abs(a.z) );
719}
720
724AI_DEVICE inline float AiMaxElement(const AtVector& a)
725{
726 return AiMax(a.x, a.y, a.z);
727}
728
732AI_DEVICE inline float AiMinElement(const AtVector& a)
733{
734 return AiMin(a.x, a.y, a.z);
735}
736
740AI_DEVICE inline AtVector AiBerpXYZ(float a, float b, const AtVector& p0, const AtVector& p1, const AtVector& p2)
741{
742 float c = 1 - (a + b);
743 return c*p0 + a*p1 + b*p2;
744}
745
749AI_API AI_DEVICE AI_PURE bool AiV3IsFinite(const AtVector& a);
750
754AI_DEVICE inline bool AiV3IsSmall(const AtVector& a, float epsilon = AI_EPSILON)
755{
756 return std::abs(a.x) < epsilon && std::abs(a.y) < epsilon && std::abs(a.z) < epsilon;
757}
758
762AI_DEVICE inline void AiV3RotateToFrame(AtVector& a, const AtVector& u, const AtVector& v, const AtVector& w)
763{
764 a = u * a.x + v * a.y + w * a.z;
765}
766
770AI_DEVICE inline void AiBerpUV(float a, float b, float u0, float v0, float u1, float v1, float u2, float v2, float* u, float* v)
771{
772 float c = 1.0f - (a + b);
773 *u = c * u0 + a * u1 + b * u2;
774 *v = c * v0 + a * v1 + b * v2;
775}
776
777/*\}*/
778
786AI_DEVICE inline AtHPoint AiV4CreatePoint(const AtVector& v)
787{
788 return AtHPoint(v, 1);
789}
790
794AI_DEVICE inline AtHPoint AiV4CreateVector(const AtVector& v)
795{
796 return AtHPoint(v, 0);
797}
798
799AI_DEVICE inline void AiV4CreatePoint(AtHPoint& pout, const AtVector& v)
800{
801 pout = AtHPoint(v, 1);
802}
803
807inline void AiV4CreateVector(AtHPoint& vout, const AtVector& v)
808{
809 vout = AtHPoint(v, 0);
810}
811
815inline void AiV4Add(AtHPoint& vout, const AtHPoint& v1, const AtHPoint& v2)
816{
817 vout = v1 + v2;
818}
819
823inline void AiV4Sub(AtHPoint& vout, const AtHPoint& v1, const AtHPoint& v2)
824{
825 vout = v1 - v2;
826}
827
831inline void AiV4Scale(AtHPoint& vout, const AtHPoint& vin, float k)
832{
833 vout = vin * k;
834}
835
839inline void AiV4Neg(AtHPoint& vout, const AtHPoint& vin)
840{
841 vout = -vin;
842}
843
847inline void AiV4Project(AtVector& vout, const AtHPoint& vin)
848{
849 vout = vin.project();
850}
851
852
856AI_API AI_DEVICE void AiV3BuildLocalFrame(AtVector& u, AtVector& v, const AtVector& N);
857
861AI_API AI_DEVICE void AiV3BuildLocalFramePolar(AtVector& u, AtVector& v, const AtVector& N);
862
863/*\}*/
864
868#ifdef AI_CPU_COMPILER
869static constexpr const AtVector AI_P3_ZERO( 0.0f, 0.0f, 0.0f);
870static constexpr const AtVector AI_V3_ZERO( 0.0f, 0.0f, 0.0f);
871static constexpr const AtVector AI_V3_HALF( 0.5f, 0.5f, 0.5f);
872static constexpr const AtVector AI_V3_ONE ( 1.0f, 1.0f, 1.0f);
873static constexpr const AtVector AI_V3_X ( 1.0f, 0.0f, 0.0f);
874static constexpr const AtVector AI_V3_Y ( 0.0f, 1.0f, 0.0f);
875static constexpr const AtVector AI_V3_Z ( 0.0f, 0.0f, 1.0f);
876static constexpr const AtVector AI_V3_NEGX(-1.0f, 0.0f, 0.0f);
877static constexpr const AtVector AI_V3_NEGY( 0.0f, -1.0f, 0.0f);
878static constexpr const AtVector AI_V3_NEGZ( 0.0f, 0.0f, -1.0f);
879static constexpr const AtVector2 AI_P2_ZERO( 0.0f, 0.0f);
880static constexpr const AtVector2 AI_P2_ONE ( 1.0f, 1.0f);
881#else
882static __device__ const AtVector AI_P3_ZERO( 0.0f, 0.0f, 0.0f);
883static __device__ const AtVector AI_V3_ZERO( 0.0f, 0.0f, 0.0f);
884static __device__ const AtVector AI_V3_HALF( 0.5f, 0.5f, 0.5f);
885static __device__ const AtVector AI_V3_ONE ( 1.0f, 1.0f, 1.0f);
886static __device__ const AtVector AI_V3_X ( 1.0f, 0.0f, 0.0f);
887static __device__ const AtVector AI_V3_Y ( 0.0f, 1.0f, 0.0f);
888static __device__ const AtVector AI_V3_Z ( 0.0f, 0.0f, 1.0f);
889static __device__ const AtVector AI_V3_NEGX(-1.0f, 0.0f, 0.0f);
890static __device__ const AtVector AI_V3_NEGY( 0.0f, -1.0f, 0.0f);
891static __device__ const AtVector AI_V3_NEGZ( 0.0f, 0.0f, -1.0f);
892static __device__ const AtVector2 AI_P2_ZERO( 0.0f, 0.0f);
893static __device__ const AtVector2 AI_P2_ONE ( 1.0f, 1.0f);
894#endif
895/*\}*/
896
897/*\}*/
DLL export prefix for API functions (necessary for multi-platform development)
Comparison.
Various useful constants.
Math operations.
#define AI_EPSILON
System epsilon value
Definition: ai_constants.h:41
AI_DEVICE constexpr T1 AiLerp(T2 t, T1 a, T1 b)
Linear interpolation between 'a' and 'b' using 't' (0<=t<=1)
Definition: ai_math.h:119
AI_DEVICE constexpr T AiClamp(T v, T lo, T hi)
Clamp the input to the specified range.
Definition: ai_math.h:101
AI_DEVICE constexpr T AiMin(T a, T b)
Minimum of 'a' and 'b'.
Definition: ai_math.h:30
AI_DEVICE constexpr T AiSqr(T a)
Square of 'a'.
Definition: ai_math.h:92
AI_DEVICE constexpr T AiMax(T a, T b)
Maximum of 'a' and 'b'.
Definition: ai_math.h:43
AI_DEVICE constexpr AtVector AiV3Min(const AtVector &a, const AtVector &b)
Minimum of two vectors, component-wise.
Definition: ai_vector.h:696
AI_DEVICE constexpr float AiV3Dot(const AtVector &a, const AtVector &b)
Dot product: <a, b>
Definition: ai_vector.h:626
AI_DEVICE constexpr float AiV3DistPlane(const AtVector &x, const AtVector &p, const AtVector &n)
Signed distance between point x and a plane defined by point p and normalized vector n.
Definition: ai_vector.h:650
AI_DEVICE AtVector2 ABS(const AtVector2 &a)
Absolute value of each component.
Definition: ai_vector.h:587
AI_DEVICE constexpr float AiV3Dist2(const AtVector &a, const AtVector &b)
Squared distance between two points: ||a-b||^2.
Definition: ai_vector.h:642
AI_DEVICE AtHPoint AiV4CreatePoint(const AtVector &v)
Create a 4D point: pout = (v.x, v.y, v.z, 1)
Definition: ai_vector.h:786
AI_DEVICE float AiMaxElement(const AtVector2 &a)
Element-wise max.
Definition: ai_vector.h:595
AI_DEVICE constexpr AtVector AiV3Max(const AtVector &a, const AtVector &b)
Maximum of two vectors, component-wise.
Definition: ai_vector.h:706
AI_DEVICE constexpr float AiV2Dot(const AtVector2 &v1, const AtVector2 &v2)
Dot product: <v1, v2>
Definition: ai_vector.h:545
AI_DEVICE float AiV2Length(const AtVector2 &v1)
Vector Length: ||v1||.
Definition: ai_vector.h:553
AI_DEVICE AtVector AiBerpXYZ(float a, float b, const AtVector &p0, const AtVector &p1, const AtVector &p2)
Barycentric interpolation of a point inside a triangle.
Definition: ai_vector.h:740
AI_DEVICE AtVector project() const
Project a homogeneous vector back into 3d: vout = vin.w != 0 ? vin * (1 / vin.w) : (0,...
Definition: ai_vector.h:504
AI_DEVICE constexpr AtVector AiV3Clamp(const AtVector &in, float lo, float hi)
Clamp each vector coordinate to the range [lo,hi].
Definition: ai_vector.h:686
constexpr AtVector2 AiV2Lerp(float t, const AtVector2 &lo, const AtVector2 &hi)
2D vector linear interpolation (t=0 -> result=lo, t=1 -> result=hi)
Definition: ai_vector.h:570
float AiV2Dist(const AtVector2 &p1, const AtVector2 &p2)
Distance between two points: ||p1-p2||.
Definition: ai_vector.h:561
void AiV4Project(AtVector &vout, const AtHPoint &vin)
Project a homogeneous vector back into 3d: vout = vin.w != 0 ? vin * (1 / vin.w) : (0,...
Definition: ai_vector.h:847
AI_API AI_DEVICE AI_PURE bool AiV3IsFinite(const AtVector &a)
Check whether a vector has all valid components (not NaN and not infinite)
Definition: ai_vector.cpp:10
void AiV4Scale(AtHPoint &vout, const AtHPoint &vin, float k)
Scale a vector by a constant: vout = vin * k.
Definition: ai_vector.h:831
void AiV4Add(AtHPoint &vout, const AtHPoint &v1, const AtHPoint &v2)
Add two vectors: vout = v1 + v2.
Definition: ai_vector.h:815
constexpr AtVector2 AiV2Clamp(const AtVector2 &in, float lo, float hi)
Clamp each vector coordinate to the range [lo,hi].
Definition: ai_vector.h:578
AI_DEVICE AtHPoint AiV4CreateVector(const AtVector &v)
Create a 4D vector: vout = (v.x, v.y, v.z, 0)
Definition: ai_vector.h:794
AI_DEVICE float AiV3Length(const AtVector &a)
Vector Length: ||a||.
Definition: ai_vector.h:618
void AiV4Sub(AtHPoint &vout, const AtHPoint &v1, const AtHPoint &v2)
Substract two vectors: vout = v1 - v2.
Definition: ai_vector.h:823
void AiV4Neg(AtHPoint &vout, const AtHPoint &vin)
Negate a vector: vout = -vin.
Definition: ai_vector.h:839
AI_DEVICE void AiV3RotateToFrame(AtVector &a, const AtVector &u, const AtVector &v, const AtVector &w)
Rotate vector a so that it aligns with frame {u,v,w}.
Definition: ai_vector.h:762
AI_DEVICE AtVector AiV3Normalize(const AtVector &a)
Normalize a vector: a / ||a||.
Definition: ai_vector.h:668
AI_API AI_DEVICE void AiV3BuildLocalFramePolar(AtVector &u, AtVector &v, const AtVector &N)
Build an orthonormal basis aligned with vector N (polar method).
Definition: ai_vector.cpp:43
AI_DEVICE constexpr AtVector AiV3Cross(const AtVector &a, const AtVector &b)
Cross product: a x b.
Definition: ai_vector.h:658
AI_DEVICE void AiBerpUV(float a, float b, float u0, float v0, float u1, float v1, float u2, float v2, float *u, float *v)
Barycentric interpolation of UV coordinates inside a 3D triangle.
Definition: ai_vector.h:770
float AiMinElement(const AtVector2 &a)
Element-wise min.
Definition: ai_vector.h:603
AI_DEVICE float AiV3Dist(const AtVector &a, const AtVector &b)
Distance between two points: ||a-b||.
Definition: ai_vector.h:634
AI_DEVICE bool AiV3IsSmall(const AtVector &a, float epsilon=AI_EPSILON)
Check for a zero vector, within a small tolerance: ||a|| < epsilon.
Definition: ai_vector.h:754
AI_DEVICE constexpr AtVector AiV3Lerp(float t, const AtVector &lo, const AtVector &hi)
3D vector linear interpolation (t=0 -> result=lo, t=1 -> result=hi)
Definition: ai_vector.h:678
AI_API AI_DEVICE void AiV3BuildLocalFrame(AtVector &u, AtVector &v, const AtVector &N)
Build an orthonormal basis aligned with vector N (Frisvad's method).
Definition: ai_vector.cpp:26
Definition: ai_comparison.h:17
Homogeneous point.
Definition: ai_vector.h:465
2D point
Definition: ai_vector.h:255
Vector with differentials.
Definition: ai_vector.h:515
3D point (single precision)
Definition: ai_vector.h:30

© 2022 Autodesk, Inc. · All rights reserved · www.arnoldrenderer.com