• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2016 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include <algos/vec.h>
18 #include <nanohub_math.h>
19 
20 
findOrthogonalVector(float inX,float inY,float inZ,float * outX,float * outY,float * outZ)21 void findOrthogonalVector( float inX, float inY, float inZ, float *outX, float *outY, float *outZ) {
22 
23     float x, y, z;
24 
25     // discard the one with the smallest absolute value
26     if (fabsf(inX) <= fabsf(inY) && fabsf(inX) <= fabsf(inZ)) {
27         x = 0.0f;
28         y = inZ;
29         z = -inY;
30     } else if (fabsf(inY) <= fabsf(inZ)) {
31         x = inZ;
32         y = 0.0f;
33         z = -inX;
34     } else {
35         x = inY;
36         y = -inX;
37         z = 0.0f;
38     }
39 
40     float magSquared = x * x + y * y + z * z;
41     float invMag = 1.0f / sqrtf(magSquared);
42 
43     *outX = x * invMag;
44     *outY = y * invMag;
45     *outZ = z * invMag;
46 }
47