-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
plot_rotation_mccormick_envelope.cc
51 lines (46 loc) · 1.54 KB
/
plot_rotation_mccormick_envelope.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/* clang-format off to disable clang-format-includes */
#include "drake/solvers/test/rotation_constraint_visualization.h"
/* clang-format on */
#include "drake/common/proto/call_python.h"
#include "drake/solvers/rotation_constraint.h"
// Plot the McCormick Envelope on the unit sphere, to help developers to
// visualize the McCormick Envelope relaxation.
namespace drake {
namespace solvers {
namespace {
// This draws all the McCormick Envelope in the first orthant (+++).
void DrawAllMcCormickEnvelopes(int num_bins) {
for (int i = 0; i < num_bins; ++i) {
for (int j = 0; j < num_bins; ++j) {
for (int k = 0; k < num_bins; ++k) {
Eigen::Vector3d bmin(static_cast<double>(i) / num_bins,
static_cast<double>(j) / num_bins,
static_cast<double>(k) / num_bins);
Eigen::Vector3d bmax(static_cast<double>(i + 1) / num_bins,
static_cast<double>(j + 1) / num_bins,
static_cast<double>(k + 1) / num_bins);
if (bmin.norm() <= 1 && bmax.norm() >= 1) {
DrawBoxSphereIntersection(bmin, bmax);
DrawBox(bmin, bmax);
}
}
}
}
}
void DoMain() {
using common::CallPython;
for (int num_bins = 1; num_bins <= 3; ++num_bins) {
CallPython("figure", num_bins);
CallPython("clf");
CallPython("axis", "equal");
DrawSphere();
DrawAllMcCormickEnvelopes(num_bins);
}
}
} // namespace
} // namespace solvers
} // namespace drake
int main() {
drake::solvers::DoMain();
return 0;
}