Oolite 1.91.0.7646-241128-10e222e
Loading...
Searching...
No Matches
OOHPVector.m File Reference
#include "OOMaths.h"
+ Include dependency graph for OOHPVector.m:

Go to the source code of this file.

Functions

HPVector OORandomUnitHPVector (void)
 
HPVector OOHPVectorRandomSpatial (OOHPScalar maxLength)
 
HPVector OOHPVectorRandomRadial (OOHPScalar maxLength)
 
HPVector OOHPRandomPositionInBoundingBox (BoundingBox bb)
 
HPVector OORandomPositionInCylinder (HPVector centre1, OOHPScalar exclusion1, HPVector centre2, OOHPScalar exclusion2, OOHPScalar radius)
 
HPVector OORandomPositionInShell (HPVector centre, OOHPScalar inner, OOHPScalar outer)
 
HPVector OOProjectHPVectorToPlane (HPVector point, HPVector plane, HPVector normal)
 

Variables

const HPVector kZeroHPVector = { 0.0, 0.0, 0.0 }
 
const HPVector kBasisXHPVector = { 1.0, 0.0, 0.0 }
 
const HPVector kBasisYHPVector = { 0.0, 1.0, 0.0 }
 
const HPVector kBasisZHPVector = { 0.0, 0.0, 1.0 }
 
const HPVector2D kZeroHPVector2D = { 0.0, 0.0 }
 
const HPVector2D kBasisXHPVector2D = { 1.0, 0.0 }
 
const HPVector2D kBasisYHPVector2D = { 0.0, 1.0 }
 

Function Documentation

◆ OOHPRandomPositionInBoundingBox()

HPVector OOHPRandomPositionInBoundingBox ( BoundingBox bb)

Definition at line 104 of file OOHPVector.m.

105{
106 HPVector result;
107 result.x = (OOHPScalar)(bb.min.x + randf() * (bb.max.x - bb.min.x));
108 result.y = (OOHPScalar)(bb.min.y + randf() * (bb.max.y - bb.min.y));
109 result.z = (OOHPScalar)(bb.min.z + randf() * (bb.max.z - bb.min.z));
110 return result;
111}
double OOHPScalar
Definition OOMaths.h:69
float randf(void)

References randf().

+ Here is the call graph for this function:

◆ OOHPVectorRandomRadial()

HPVector OOHPVectorRandomRadial ( OOHPScalar maxLength)

Definition at line 98 of file OOHPVector.m.

99{
100 return HPvector_multiply_scalar(OORandomUnitHPVector(), randf() * maxLength);
101}
HPVector OORandomUnitHPVector(void)
Definition OOHPVector.m:66

References OORandomUnitHPVector(), and randf().

Referenced by VectorStaticRandomDirectionAndLength().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ OOHPVectorRandomSpatial()

HPVector OOHPVectorRandomSpatial ( OOHPScalar maxLength)

Definition at line 82 of file OOHPVector.m.

83{
84 HPVector v;
85 OOHPScalar m;
86
87 do
88 {
89 v = make_HPvector(randf() - 0.5f, randf() - 0.5f, randf() - 0.5f);
90 m = HPmagnitude2(v);
91 }
92 while (m > 0.25); // We're confining to a sphere of radius 0.5 using the sqared magnitude; 0.5 squared is 0.25.
93
94 return HPvector_multiply_scalar(v, maxLength * 2.0); // 2.0 is to compensate for the 0.5-radius sphere.
95}

References randf().

Referenced by OORandomPositionInCylinder(), OORandomPositionInShell(), and VectorStaticRandom().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ OOProjectHPVectorToPlane()

HPVector OOProjectHPVectorToPlane ( HPVector point,
HPVector plane,
HPVector normal )

Definition at line 141 of file OOHPVector.m.

142{
143 return HPvector_subtract(point,HPvector_multiply_scalar(normal,HPdot_product(HPvector_subtract(point, plane), normal)));
144}

◆ OORandomPositionInCylinder()

HPVector OORandomPositionInCylinder ( HPVector centre1,
OOHPScalar exclusion1,
HPVector centre2,
OOHPScalar exclusion2,
OOHPScalar radius )

Definition at line 113 of file OOHPVector.m.

114{
115 OOHPScalar exc12 = exclusion1*exclusion1;
116 OOHPScalar exc22 = exclusion2*exclusion2;
117 if (HPdistance(centre1,centre2) < (exclusion1+exclusion2)*1.2)
118 {
119 OOLog(@"position.cylinder.error",@"Trying to generate cylinder position in range %f long with exclusions %f and %f",HPdistance(centre1,centre2),exclusion1,exclusion2);
120 }
121 HPVector result;
122 do
123 {
124 result = HPvector_add(OOHPVectorInterpolate(centre1,centre2,randf()),OOHPVectorRandomSpatial(radius));
125 }
126 while(HPdistance2(result,centre1)<exc12 || HPdistance2(result,centre2)<exc22);
127 return result;
128}
HPVector OOHPVectorRandomSpatial(OOHPScalar maxLength)
Definition OOHPVector.m:82
#define OOLog(class, format,...)
Definition OOLogging.h:88

References OOHPVectorRandomSpatial(), OOLog, and randf().

+ Here is the call graph for this function:

◆ OORandomPositionInShell()

HPVector OORandomPositionInShell ( HPVector centre,
OOHPScalar inner,
OOHPScalar outer )

Definition at line 130 of file OOHPVector.m.

131{
132 HPVector result;
133 OOHPScalar inner2 = inner*inner;
134 do
135 {
136 result = HPvector_add(centre,OOHPVectorRandomSpatial(outer));
137 } while(HPdistance2(result,centre)<inner2);
138 return result;
139}

References OOHPVectorRandomSpatial().

+ Here is the call graph for this function:

◆ OORandomUnitHPVector()

HPVector OORandomUnitHPVector ( void )

Definition at line 66 of file OOHPVector.m.

67{
68 HPVector v;
69 OOHPScalar m;
70
71 do
72 {
73 v = make_HPvector(randf() - 0.5f, randf() - 0.5f, randf() - 0.5f);
74 m = HPmagnitude2(v);
75 }
76 while (m > 0.25 || m == 0.0); // We're confining to a sphere of radius 0.5 using the sqared magnitude; 0.5 squared is 0.25.
77
78 return HPvector_normal(v);
79}

References randf().

Referenced by OOHPVectorRandomRadial(), and VectorStaticRandomDirection().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Variable Documentation

◆ kBasisXHPVector

const HPVector kBasisXHPVector = { 1.0, 0.0, 0.0 }

Definition at line 29 of file OOHPVector.m.

29{ 1.0, 0.0, 0.0 };

◆ kBasisXHPVector2D

const HPVector2D kBasisXHPVector2D = { 1.0, 0.0 }

Definition at line 34 of file OOHPVector.m.

34{ 1.0, 0.0 };

◆ kBasisYHPVector

const HPVector kBasisYHPVector = { 0.0, 1.0, 0.0 }

Definition at line 30 of file OOHPVector.m.

30{ 0.0, 1.0, 0.0 };

◆ kBasisYHPVector2D

const HPVector2D kBasisYHPVector2D = { 0.0, 1.0 }

Definition at line 35 of file OOHPVector.m.

35{ 0.0, 1.0 };

◆ kBasisZHPVector

const HPVector kBasisZHPVector = { 0.0, 0.0, 1.0 }

Definition at line 31 of file OOHPVector.m.

31{ 0.0, 0.0, 1.0 };

Referenced by quaternion_rotation_betweenHP().

◆ kZeroHPVector

const HPVector kZeroHPVector = { 0.0, 0.0, 0.0 }

Definition at line 28 of file OOHPVector.m.

28{ 0.0, 0.0, 0.0 };

Referenced by JSObjectGetVector(), JSValueToVector(), SystemLocationFromCode(), and VectorConstruct().

◆ kZeroHPVector2D

const HPVector2D kZeroHPVector2D = { 0.0, 0.0 }

Definition at line 33 of file OOHPVector.m.

33{ 0.0, 0.0 };