13#ifdef ASTRO_ENABLE_PLOTTING
15#ifndef ASTRO_PLOTTING_HH
16#define ASTRO_PLOTTING_HH
22#include <TApplication.h>
26#include <TPolyLine3D.h>
27#include <TPolyMarker3D.h>
28#include <TGeoManager.h>
29#include <TGeoVolume.h>
30#include <TGeoSphere.h>
31#include <TGeoMatrix.h>
51 TObjArray* DrawAxes(Vector3
const & origin, Rotation
const & rotation, Real
const length = 1.0,
52 Real
const line_width = 1.0)
54 TObjArray* arrows =
new TObjArray();
57 TPolyLine3D* xAxis =
new TPolyLine3D(2);
58 xAxis->SetPoint(0, origin.x(), origin.y(), origin.z());
60 xAxis->SetPoint(1, x_end.x(), x_end.y(), x_end.z());
61 xAxis->SetLineColor(kRed);
62 xAxis->SetLineWidth(line_width);
63 xAxis->Draw(
"same L");
67 TPolyLine3D* yAxis =
new TPolyLine3D(2);
68 yAxis->SetPoint(0, origin.x(), origin.y(), origin.z());
70 yAxis->SetPoint(1, y_end.x(), y_end.y(), y_end.z());
71 yAxis->SetLineColor(kGreen + 2);
72 yAxis->SetLineWidth(line_width);
73 yAxis->Draw(
"same L");
77 TPolyLine3D* zAxis =
new TPolyLine3D(2);
78 zAxis->SetPoint(0, origin.x(), origin.y(), origin.z());
80 zAxis->SetPoint(1, z_end.x(), z_end.y(), z_end.z());
81 zAxis->SetLineColor(kBlue);
82 zAxis->SetLineWidth(line_width);
83 zAxis->Draw(
"same L");
97 TObjArray* DrawAbsoluteAxes(Real
const length = 1.0, Real
const line_width = 1) {
98 return DrawAxes(ZEROS_VEC3, IDENTITY_MAT3, length, line_width);
110 TObjArray* DrawOrbitalPlaneAxes(Orbit
const & orbit, Real length = 1.0, Real line_width = 1.0) {
112 Rotation rotation{orbit.keplerian_to_reference()};
115 return DrawAxes(ZEROS_VEC3, rotation, length, line_width);
125 TPolyLine3D* DrawTrace(Eigen::Matrix<Real, 3, Eigen::Dynamic>
const & trace) {
126 TPolyLine3D* poly_line =
new TPolyLine3D(trace.cols());
127 for (
int k = 0; k < trace.cols(); ++k) {
128 poly_line->SetPoint(k, trace(0, k), trace(1, k), trace(2, k));
130 poly_line->SetLineColor(kRed);
131 poly_line->SetLineWidth(2);
142 TPolyLine3D* DrawTrace(Orbit
const & orbit, Integer num_points = 360) {
145 Real a{orbit.keplerian().a};
146 Real e{orbit.keplerian().e};
147 Real i{orbit.keplerian().i};
148 Real Omega{orbit.keplerian().Omega};
149 Real omega{orbit.keplerian().omega};
152 Real cos_Omega{std::cos(Omega)};
153 Real sin_Omega{std::sin(Omega)};
154 Real cos_i{std::cos(i)};
155 Real sin_i{std::sin(i)};
157 TPolyLine3D* poly_line =
new TPolyLine3D(num_points + 1);
158 for (
int k = 0; k <= num_points; ++k) {
160 Real nu{2.0 * TMath::Pi() * k / num_points};
163 Real r{a*(1.0 - e*e)/(1.0 + e * std::cos(nu))};
166 Real cos_w_nu{std::cos(omega + nu)};
167 Real sin_w_nu{std::sin(omega + nu)};
168 Real x{r*(cos_Omega*cos_w_nu - sin_Omega*sin_w_nu*cos_i)};
169 Real y{r*(sin_Omega*cos_w_nu + cos_Omega*sin_w_nu*cos_i)};
170 Real z{r*(sin_w_nu*sin_i)};
172 poly_line->SetPoint(k, x, y, z);
175 poly_line->SetLineColor(kRed);
176 poly_line->SetLineWidth(2);
202 TPolyMarker3D* DrawMarker(Vector3
const & position, Color_t color, Real
const size = 1.0) {
203 TPolyMarker3D* marker =
new TPolyMarker3D(1);
204 marker->SetPoint(0, position.x(), position.y(), position.z());
205 marker->SetMarkerColor(color);
206 marker->SetMarkerSize(size);
207 marker->SetMarkerStyle(20);
208 marker->Draw(
"same P");
221 TPolyMarker3D* DrawMarker(Body
const & body, Color_t
const color, Real
const size = 1.0) {
222 return DrawMarker(body.orbit().cartesian().r, color, size);
235 TGeoVolume* DrawSphere(Vector3
const & position, Real
const radius, Color_t
const color, Real
const line_width) {
236 static TGeoManager* geom =
nullptr;
240 geom =
new TGeoManager(
"SphereGeom",
"Sphere Geometry");
243 TGeoMaterial *mat =
new TGeoMaterial(
"Vacuum", 0, 0, 0);
244 TGeoMedium *med =
new TGeoMedium(
"VacuumMedium", 1, mat);
247 TGeoVolume *top = geom->MakeBox(
"TOP", med, 1000, 1000, 1000);
248 geom->SetTopVolume(top);
252 TGeoMedium* med = geom->GetMedium(
"VacuumMedium");
253 if (!med) {med =
new TGeoMedium(
"VacuumMedium", 1, geom->GetMaterial(
"Vacuum"));}
256 static int sphere_id = 0;
257 std::string sphere_name =
"Sphere_" + std::to_string(sphere_id++);
258 TGeoSphere* sphere =
new TGeoSphere(0.0, radius);
259 TGeoVolume* volume =
new TGeoVolume(sphere_name.c_str(), sphere, med);
260 volume->SetLineColor(color);
261 volume->SetLineWidth(line_width);
264 geom->GetTopVolume()->AddNode(volume, 1,
new TGeoTranslation(position.x(), position.y(), position.z()));
267 geom->CloseGeometry();
268 geom->GetTopVolume()->Draw(
"same");
282 TGeoVolume* DrawSphere(Body
const & body, Color_t
const color, Real
const line_width = 1.0) {
283 return DrawSphere(body.orbit().cartesian().r, body.radius(), color, line_width);
The namespace for the Astro library.
Definition Astro.hh:73
Eigen::Matrix< Real, 3, 3 > Rotation
Definition Astro.hh:111
double Real
Definition Astro.hh:84
Eigen::Vector< Real, 3 > Vector3
Definition Astro.hh:93