Skip to content

Commit

Permalink
Merge pull request #1194 from LLNL/feature/han12/handedness
Browse files Browse the repository at this point in the history
Right hand rule consistency
  • Loading branch information
bmhan12 committed Oct 27, 2023
2 parents dd02bf8 + c5aecce commit c35431a
Show file tree
Hide file tree
Showing 6 changed files with 121 additions and 39 deletions.
3 changes: 3 additions & 0 deletions src/axom/primal/docs/sphinx/primitive.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ Primal includes the following primitives:
- Tetrahedron
- Hexahedron
- BoundingBox, OrientedBoundingBox
- Polyhedron

.. note:: Primitives in Axom use a right-handed coordinate system.

Primal also provides the NumericArray class, which implements arithmetic
operations on numerical tuples and supports Primal's Point and Vector classes.
Expand Down
20 changes: 10 additions & 10 deletions src/axom/primal/geometry/Hexahedron.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2017-2022, Lawrence Livermore National Security, LLC and
// Copyright (c) 2017-2023, Lawrence Livermore National Security, LLC and
// other Axom Project Developers. See the top-level COPYRIGHT file for details.
//
// SPDX-License-Identifier: (BSD-3-Clause)
Expand Down Expand Up @@ -39,16 +39,16 @@ namespace primal
*
* \verbatim
*
* U +---------+ V +y
* |\ |\ +z
* | \ | \ < ^
* | T + --------+ W \ |
* Q +---|-----+ R | \|
* S +---------+ R +y
* |\ |\
* | \ | \ ^
* | W + --------+ V |
* P +---|-----+ Q | |
* \ | \ | -----> +x
* \ | \ |
* \ | \ |
* P +----------+ S
*
* \ | \ | \
* \ | \ | \
* T +----------+ U >
* +z
* \endverbatim
*
*/
Expand Down
42 changes: 23 additions & 19 deletions src/axom/primal/geometry/Polyhedron.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,14 +228,16 @@ class NeighborCollection
*
* <pre>
*
* 4--------5 +y
* /| /| +z
* / | / | ^ >
* 7--------6 | | /
* | 0-----|--1 |/
* 3--------2 +y
* /| /|
* / | / | ^
* 7--------6 | |
* | 0-----|--1 |
* | / | / -----> +x
* |/ |/
* 3--------2
* |/ |/ /
* 4--------5 /
* <
* +z
*
* </pre>
*
Expand Down Expand Up @@ -680,14 +682,14 @@ class Polyhedron
* \note The Hexahedron is assumed to have a specific vertex order:
* \verbatim
*
* 7--------6 +y
* /| /| +z
* 4--------7 +z
* /| /| +y
* / | / | ^ >
* 3--------2 | | /
* | 4-----|--5 |/
* 5--------6 | | /
* | 0-----|--3 |/
* | / | / -----> +x
* |/ |/
* 0--------1
* 1--------2
*
* \endverbatim
*
Expand Down Expand Up @@ -748,16 +750,18 @@ class Polyhedron
* vertex neighbors
*
* \note The Octahedron is assumed to have a specific vertex order:
* (view looking down from +z axis):
*
* \verbatim
*
* 0 +y
* /\ +z
* 4 --/ \-- 5 ^ >
* 4 +z
* /\ +y
* 0 --/ \-- 2 ^ >
* \/ \ / | /
* / \ |/
* 2 -------- 1 -----> +x
* 5 -------- 3 -----> +x
* \/
* 3
* 1
*
* \endverbatim
*
Expand Down Expand Up @@ -816,8 +820,8 @@ class Polyhedron
* \note The Tetrahedron is assumed to have a specific vertex order:
* \verbatim
*
* 3 +y
* / \\ +z
* 3 +z
* / \\ +y
* / \ \ ^ >
* / \ \ | /
* / \ \ |/
Expand Down
46 changes: 36 additions & 10 deletions src/axom/primal/tests/primal_hexahedron.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2017-2022, Lawrence Livermore National Security, LLC and
// Copyright (c) 2017-2023, Lawrence Livermore National Security, LLC and
// other Axom Project Developers. See the top-level COPYRIGHT file for details.
//
// SPDX-License-Identifier: (BSD-3-Clause)
Expand Down Expand Up @@ -48,17 +48,43 @@ class HexahedronTest : public ::testing::Test
{
EPS = 1e-8;

// Define coordinates for first hexahedron
/*
* Define coordinates for first hexahedron:
*
* 7 +---------+ 6 +z
* |\ |\ +y
* | \ | \ < ^
* | 4 + --------+ 5 \ |
* 3 +---|-----+ 2 | \|
* \ | \ | -----> +x
* \ | \ |
* \ | \ |
* 0 +----------+ 1
*
*/
qData0[0] = QPoint {0, 0, 0};
qData0[1] = QPoint {0, 0, 1};
qData0[2] = QPoint {1, 0, 1};
qData0[3] = QPoint {1, 0, 0};
qData0[4] = QPoint {0, 1, 0};
qData0[5] = QPoint {0, 1, 1};
qData0[1] = QPoint {1, 0, 0};
qData0[2] = QPoint {1, 1, 0};
qData0[3] = QPoint {0, 1, 0};
qData0[4] = QPoint {0, 0, 1};
qData0[5] = QPoint {1, 0, 1};
qData0[6] = QPoint {1, 1, 1};
qData0[7] = QPoint {1, 1, 0};

// Define coordinates for second hexahedron
qData0[7] = QPoint {0, 1, 1};

/*
* Define coordinates for second hexahedron:
*
* 3 +---------+ 2 +y
* |\ |\
* | \ | \ ^
* | 7 + --------+ 6 |
* 0 +---|-----+ 1 | |
* \ | \ | -----> +x
* \ | \ | \
* \ | \ | \
* 4 +----------+ 5 >
* +z
*/
qData1[0] = QPoint {-1, 0, 0};
qData1[1] = QPoint {0, 0, 0};
qData1[2] = QPoint {0, 1, 0};
Expand Down
37 changes: 37 additions & 0 deletions src/axom/primal/tests/primal_octahedron.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,21 @@ class OctahedronTest : public ::testing::Test
{
EPS = 1e-12;

/*
* Define coordinates for first octahedron
* (view looking down from +z axis):
*
* 4 +z
* /\ +y
* 0 --/ \-- 2 ^ >
* \/ \ / | /
* / \ |/
* 5 -------- 3 -----> +x
* \/
* 1
*
*/

// Define coordinates for first octahedron
qData0[0] = QPoint::make_point(1, 0, 0);
qData0[1] = QPoint::make_point(1, 1, 0);
Expand All @@ -40,6 +55,28 @@ class OctahedronTest : public ::testing::Test
qData0[4] = QPoint::make_point(0, 0, 1);
qData0[5] = QPoint::make_point(1, 0, 1);

/*
* Define coordinates for second octahedron (regular octahedron):
*
* 3 +z
* / \\ +y
* / \ \ ^ >
* / \ \ | /
* / \ \ |/
* 4- - - - -\- 2 -----> +x
* / \ /
* /_____________/
* 5 1
* \ /
* \ /
* \ /
* \ /
* \ /
* \ /
* \/
* 0
*/

// Define coordinates for second octahedron
qData1[0] = QPoint::make_point(0, 0, -1);
qData1[1] = QPoint::make_point(1, 0, 0);
Expand Down
12 changes: 12 additions & 0 deletions src/axom/primal/tests/primal_polyhedron.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ TEST(primal_polyhedron, polyhedron_octahedron)
octA.addNeighbors(octA[5], {0, 1, 3, 4});

EXPECT_NEAR(1.3333, octA.volume(), EPS);
EXPECT_NEAR(1.3333, octA.signedVolume(), EPS);

PolyhedronType octB;
octB.addVertex({1, 0, 0});
Expand All @@ -272,6 +273,7 @@ TEST(primal_polyhedron, polyhedron_octahedron)
octB.addNeighbors(octB[5], {0, 1, 3, 4});

EXPECT_NEAR(0.6666, octB.volume(), EPS);
EXPECT_NEAR(0.6666, octB.signedVolume(), EPS);
}

//------------------------------------------------------------------------------
Expand Down Expand Up @@ -707,12 +709,17 @@ TEST(primal_polyhedron, polyhedron_from_primitive)
poly = Polyhedron3D::from_primitive(hex, false);
EXPECT_NEAR(1.0, poly.volume(), EPS);

// Check signed volume
EXPECT_NEAR(1.0, poly.signedVolume(), EPS);
EXPECT_NEAR(hex.signedVolume(), poly.signedVolume(), EPS);

// Negative volume
axom::utilities::swap<Point3D>(hex[1], hex[3]);
axom::utilities::swap<Point3D>(hex[5], hex[7]);

poly = Polyhedron3D::from_primitive(hex, false);
EXPECT_NEAR(-1.0, poly.signedVolume(), EPS);
EXPECT_NEAR(-1.0, hex.signedVolume(), EPS);

// Check sign
poly = Polyhedron3D::from_primitive(hex, CHECK_SIGN);
Expand Down Expand Up @@ -749,11 +756,16 @@ TEST(primal_polyhedron, polyhedron_from_primitive)
poly = Polyhedron3D::from_primitive(tet, false);
EXPECT_NEAR(2.6666, poly.volume(), EPS);

// Check signed volume
EXPECT_NEAR(2.6666, poly.signedVolume(), EPS);
EXPECT_NEAR(tet.signedVolume(), poly.signedVolume(), EPS);

// Negative volume
axom::utilities::swap<Point3D>(tet[1], tet[2]);

poly = Polyhedron3D::from_primitive(tet, false);
EXPECT_NEAR(-2.6666, poly.signedVolume(), EPS);
EXPECT_NEAR(tet.signedVolume(), poly.signedVolume(), EPS);

// Check sign
poly = Polyhedron3D::from_primitive(tet, CHECK_SIGN);
Expand Down

0 comments on commit c35431a

Please sign in to comment.