Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
L
libcifpp
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
open
libcifpp
Commits
89285b4a
Unverified
Commit
89285b4a
authored
Mar 14, 2022
by
Maarten L. Hekkelman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
construct quaternion from angle/axis
parent
f5016403
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
56 additions
and
0 deletions
+56
-0
include/cif++/Point.hpp
+2
-0
src/Point.cpp
+13
-0
test/unit-test.cpp
+41
-0
No files found.
include/cif++/Point.hpp
View file @
89285b4a
...
@@ -378,7 +378,9 @@ Point Nudge(Point p, float offset);
...
@@ -378,7 +378,9 @@ Point Nudge(Point p, float offset);
Quaternion
Normalize
(
Quaternion
q
);
Quaternion
Normalize
(
Quaternion
q
);
Quaternion
ConstructFromAngleAxis
(
float
angle
,
Point
axis
);
std
::
tuple
<
double
,
Point
>
QuaternionToAngleAxis
(
Quaternion
q
);
std
::
tuple
<
double
,
Point
>
QuaternionToAngleAxis
(
Quaternion
q
);
Point
Centroid
(
const
std
::
vector
<
Point
>
&
Points
);
Point
Centroid
(
const
std
::
vector
<
Point
>
&
Points
);
Point
CenterPoints
(
std
::
vector
<
Point
>
&
Points
);
Point
CenterPoints
(
std
::
vector
<
Point
>
&
Points
);
...
...
src/Point.cpp
View file @
89285b4a
...
@@ -295,6 +295,19 @@ Quaternion Normalize(Quaternion q)
...
@@ -295,6 +295,19 @@ Quaternion Normalize(Quaternion q)
// --------------------------------------------------------------------
// --------------------------------------------------------------------
Quaternion
ConstructFromAngleAxis
(
float
angle
,
Point
axis
)
{
auto
q
=
std
::
cos
((
angle
*
mmcif
::
kPI
/
180
)
/
2
);
auto
s
=
std
::
sqrt
(
1
-
q
*
q
);
axis
.
normalize
();
return
Normalize
(
Quaternion
{
q
,
static_cast
<
float
>
(
s
*
axis
.
mX
),
static_cast
<
float
>
(
s
*
axis
.
mY
),
static_cast
<
float
>
(
s
*
axis
.
mZ
)});
}
std
::
tuple
<
double
,
Point
>
QuaternionToAngleAxis
(
Quaternion
q
)
std
::
tuple
<
double
,
Point
>
QuaternionToAngleAxis
(
Quaternion
q
)
{
{
if
(
q
.
R_component_1
()
>
1
)
if
(
q
.
R_component_1
()
>
1
)
...
...
test/unit-test.cpp
View file @
89285b4a
...
@@ -1745,6 +1745,47 @@ BOOST_AUTO_TEST_CASE(t1)
...
@@ -1745,6 +1745,47 @@ BOOST_AUTO_TEST_CASE(t1)
// std::cout << "rmsd: " << RMSd(p1, p2) << std::endl;
// std::cout << "rmsd: " << RMSd(p1, p2) << std::endl;
}
}
BOOST_AUTO_TEST_CASE
(
t2
)
{
Point
p
[]
=
{
{
1
,
1
,
0
},
{
2
,
1
,
0
},
{
1
,
2
,
0
}
};
Point
xp
=
mmcif
::
CrossProduct
(
p
[
1
]
-
p
[
0
],
p
[
2
]
-
p
[
0
]);
Quaternion
q
=
ConstructFromAngleAxis
(
45
,
xp
);
//mmcif::Normalize(Quaternion{45 * mmcif::kPI / 180, xp.mX, xp.mY, xp.mZ});
auto
&&
[
angle
,
axis
]
=
mmcif
::
QuaternionToAngleAxis
(
q
);
BOOST_TEST
(
angle
==
45
,
tt
::
tolerance
(
0.01
));
}
BOOST_AUTO_TEST_CASE
(
t3
)
{
Point
p
[]
=
{
{
1
,
1
,
0
},
{
2
,
1
,
0
},
{
1
,
2
,
0
}
};
Point
xp
=
mmcif
::
CrossProduct
(
p
[
1
]
-
p
[
0
],
p
[
2
]
-
p
[
0
]);
Quaternion
q
=
ConstructFromAngleAxis
(
45
,
xp
);
//mmcif::Normalize(Quaternion{45 * mmcif::kPI / 180, xp.mX, xp.mY, xp.mZ});
Point
v
=
p
[
1
];
v
-=
p
[
0
];
v
.
rotate
(
q
);
v
+=
p
[
0
];
std
::
cout
<<
v
<<
std
::
endl
;
double
a
=
mmcif
::
Angle
(
v
,
p
[
0
],
p
[
1
]);
BOOST_TEST
(
a
==
45
,
tt
::
tolerance
(
0.01
));
}
BOOST_AUTO_TEST_CASE
(
parser_test_1
)
BOOST_AUTO_TEST_CASE
(
parser_test_1
)
{
{
auto
data1
=
R"(
auto
data1
=
R"(
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment