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
12e3d71b
Unverified
Commit
12e3d71b
authored
Mar 21, 2023
by
Maarten L. Hekkelman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix construct_from_angle_axis
parent
9addc8f8
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
60 additions
and
33 deletions
+60
-33
CMakeLists.txt
+2
-2
src/point.cpp
+17
-28
test/unit-3d-test.cpp
+41
-3
No files found.
CMakeLists.txt
View file @
12e3d71b
...
...
@@ -436,10 +436,10 @@ if(ENABLE_TESTING)
add_custom_command
(
OUTPUT
${
CMAKE_CURRENT_BINARY_DIR
}
/Run
${
CIFPP_TEST
}
.touch
COMMAND $<TARGET_FILE:
${
CIFPP_TEST
}
> --
${
PROJEC
T_SOURCE_DIR
}
/test
)
COMMAND $<TARGET_FILE:
${
CIFPP_TEST
}
> --
${
CMAKE_CURREN
T_SOURCE_DIR
}
/test
)
add_test
(
NAME
${
CIFPP_TEST
}
COMMAND $<TARGET_FILE:
${
CIFPP_TEST
}
> --
${
PROJEC
T_SOURCE_DIR
}
/test
)
COMMAND $<TARGET_FILE:
${
CIFPP_TEST
}
> --
${
CMAKE_CURREN
T_SOURCE_DIR
}
/test
)
endforeach
()
endif
()
...
...
src/point.cpp
View file @
12e3d71b
...
...
@@ -299,13 +299,25 @@ quaternion_type<T> normalize(quaternion_type<T> q)
quaternion
construct_from_angle_axis
(
float
angle
,
point
axis
)
{
auto
q
=
std
::
cos
((
angle
*
kPI
/
180
)
/
2
);
auto
s
=
std
::
sqrt
(
1
-
q
*
q
);
// auto q = std::cos((angle * kPI / 180) / 2);
// auto s = std::sqrt(1 - q * q);
// axis.normalize();
// return normalize(quaternion{
// static_cast<float>(q),
// static_cast<float>(s * axis.m_x),
// static_cast<float>(s * axis.m_y),
// static_cast<float>(s * axis.m_z) });
angle
=
(
angle
*
kPI
/
180
)
/
2
;
auto
s
=
std
::
sin
(
angle
);
auto
c
=
std
::
cos
(
angle
);
axis
.
normalize
();
return
normalize
(
quaternion
{
static_cast
<
float
>
(
q
),
static_cast
<
float
>
(
c
),
static_cast
<
float
>
(
s
*
axis
.
m_x
),
static_cast
<
float
>
(
s
*
axis
.
m_y
),
static_cast
<
float
>
(
s
*
axis
.
m_z
)
});
...
...
@@ -364,33 +376,10 @@ quaternion construct_for_dihedral_angle(point p1, point p2, point p3, point p4,
p3
-=
p3
;
quaternion
q
;
auto
axis
=
p2
;
auto
axis
=
-
p2
;
float
dh
=
dihedral_angle
(
p1
,
p2
,
p3
,
p4
);
for
(
int
iteration
=
0
;
iteration
<
100
;
++
iteration
)
{
float
delta
=
std
::
fmod
(
angle
-
dh
,
360.0
f
);
if
(
delta
<
-
180
)
delta
+=
360
;
if
(
delta
>
180
)
delta
-=
360
;
if
(
std
::
abs
(
delta
)
<
esd
)
break
;
// if (iteration > 0)
// std::cout << cif::coloured(("iteration " + std::to_string(iteration)).c_str(), cif::scBLUE, cif::scBLACK) << " delta: " << delta << std::endl;
auto
q2
=
construct_from_angle_axis
(
delta
,
axis
);
q
=
iteration
==
0
?
q2
:
q
*
q2
;
p4
.
rotate
(
q2
);
dh
=
dihedral_angle
(
p1
,
p2
,
p3
,
p4
);
}
return
q
;
return
construct_from_angle_axis
(
angle
-
dh
,
axis
);
}
point
centroid
(
const
std
::
vector
<
point
>
&
pts
)
...
...
test/unit-3d-test.cpp
View file @
12e3d71b
...
...
@@ -168,6 +168,46 @@ BOOST_AUTO_TEST_CASE(t3)
BOOST_TEST
(
a
==
45
,
tt
::
tolerance
(
0.01
));
}
BOOST_AUTO_TEST_CASE
(
dh_q_0
)
{
cif
::
point
axis
(
1
,
0
,
0
);
cif
::
point
p
(
1
,
1
,
0
);
cif
::
point
t
[
3
]
=
{
{
0
,
1
,
0
},
{
0
,
0
,
0
},
{
1
,
0
,
0
}
};
auto
a
=
cif
::
dihedral_angle
(
t
[
0
],
t
[
1
],
t
[
2
],
p
);
BOOST_TEST
(
a
==
0
,
tt
::
tolerance
(
0.01
f
));
auto
q
=
cif
::
construct_from_angle_axis
(
90
,
axis
);
p
.
rotate
(
q
);
BOOST_TEST
(
p
.
m_x
==
1
,
tt
::
tolerance
(
0.01
f
));
BOOST_TEST
(
p
.
m_y
==
0
,
tt
::
tolerance
(
0.01
f
));
BOOST_TEST
(
p
.
m_z
==
1
,
tt
::
tolerance
(
0.01
f
));
a
=
cif
::
dihedral_angle
(
t
[
0
],
t
[
1
],
t
[
2
],
p
);
BOOST_TEST
(
a
==
90
,
tt
::
tolerance
(
0.01
f
));
q
=
cif
::
construct_from_angle_axis
(
-
90
,
axis
);
p
.
rotate
(
q
);
BOOST_TEST
(
p
.
m_x
==
1
,
tt
::
tolerance
(
0.01
f
));
BOOST_TEST
(
p
.
m_y
==
1
,
tt
::
tolerance
(
0.01
f
));
BOOST_TEST
(
p
.
m_z
==
0
,
tt
::
tolerance
(
0.01
f
));
a
=
cif
::
dihedral_angle
(
t
[
0
],
t
[
1
],
t
[
2
],
p
);
BOOST_TEST
(
a
==
0
,
tt
::
tolerance
(
0.01
f
));
}
BOOST_AUTO_TEST_CASE
(
dh_q_1
)
{
struct
...
...
@@ -204,9 +244,7 @@ BOOST_AUTO_TEST_CASE(dh_q_1)
{
auto
q
=
cif
::
construct_for_dihedral_angle
(
pts
[
0
],
pts
[
1
],
pts
[
2
],
pts
[
3
],
angle
,
1
);
pts
[
3
]
-=
pts
[
2
];
pts
[
3
].
rotate
(
q
);
pts
[
3
]
+=
pts
[
2
];
pts
[
3
].
rotate
(
q
,
pts
[
2
]);
auto
dh
=
cif
::
dihedral_angle
(
pts
[
0
],
pts
[
1
],
pts
[
2
],
pts
[
3
]);
BOOST_TEST
(
dh
==
angle
,
tt
::
tolerance
(
0.1
f
));
...
...
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