Skip to content

Commit 2e31697

Browse files
committed
BUG: Fixes NaNs generated from qu2ax when quaternion is "<0,0,0>1"
Signed-off-by: Michael Jackson <mike.jackson@bluequartz.net>
1 parent 0f73dd2 commit 2e31697

File tree

2 files changed

+31
-9
lines changed

2 files changed

+31
-9
lines changed

CMakeLists.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ set(CMAKE_CXX_EXTENSIONS OFF)
1515
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
1616

1717
# set project's name
18-
project(EbsdLibProj VERSION 1.0.36)
18+
project(EbsdLibProj VERSION 1.0.37)
1919

2020
# ---------- Setup output Directories -------------------------
2121
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY
@@ -94,7 +94,7 @@ endif()
9494
set(EbsdLib_USE_GHC_FILESYSTEM OFF)
9595

9696
if(APPLE)
97-
exec_program(uname ARGS -v OUTPUT_VARIABLE DARWIN_VERSION)
97+
execute_process(COMMAND uname -v OUTPUT_VARIABLE DARWIN_VERSION)
9898
string(REGEX MATCH "[0-9]+" DARWIN_VERSION ${DARWIN_VERSION})
9999
if(DARWIN_VERSION VERSION_LESS 19)
100100
message(STATUS "The current macOS System is too old to compile and will fail. Please set the EbsdLib_USE_GHC_FILESYSTEM=ON variable to allow Ebsdlib to compile")

Source/EbsdLib/Core/OrientationTransformation.hpp

+29-7
Original file line numberDiff line numberDiff line change
@@ -1368,24 +1368,46 @@ OutputType qu2ax(const InputType& q, typename Quaternion<typename OutputType::va
13681368
{
13691369
qo[i] = sign * q[i];
13701370
}
1371-
OutputValueType eps = static_cast<OutputValueType>(1.0e-12L);
1371+
13721372
OutputValueType omega = static_cast<OutputValueType>(2.0 * acos(qo[w]));
1373+
// If omega equals zero then return the rotation axis as [001]
1374+
OutputValueType eps = static_cast<OutputValueType>(1.0e-12L);
13731375
if(omega < eps)
13741376
{
13751377
res[0] = 0.0;
13761378
res[1] = 0.0;
13771379
res[2] = static_cast<OutputValueType>(1.0 * epsijk);
13781380
res[3] = 0.0;
1381+
return res;
1382+
}
1383+
1384+
if(qo[w] != 0.0)
1385+
{
1386+
typename OutputType::value_type mag = sqrt(q[x] * q[x] + q[y] * q[y] + q[z] * q[z]);
1387+
if(mag == 0.0)
1388+
{
1389+
res[0] = 0.0;
1390+
res[1] = 0.0;
1391+
res[2] = static_cast<OutputValueType>(1.0 * epsijk);
1392+
res[3] = 0.0;
1393+
}
1394+
else
1395+
{
1396+
mag = static_cast<OutputValueType>(1.0 / mag);
1397+
res[0] = q[x] * mag;
1398+
res[1] = q[y] * mag;
1399+
res[2] = q[z] * mag;
1400+
res[3] = omega;
1401+
}
13791402
}
13801403
else
13811404
{
1382-
typename OutputType::value_type mag = 0.0;
1383-
mag = static_cast<OutputValueType>(1.0 / sqrt(q[x] * q[x] + q[y] * q[y] + q[z] * q[z]));
1384-
res[0] = q[x] * mag;
1385-
res[1] = q[y] * mag;
1386-
res[2] = q[z] * mag;
1387-
res[3] = omega;
1405+
res[0] = q[x];
1406+
res[1] = q[y];
1407+
res[2] = q[z];
1408+
res[3] = EbsdLib::Constants::k_PiD;
13881409
}
1410+
13891411
return res;
13901412
}
13911413

0 commit comments

Comments
 (0)