Showing axis using PolyLine3D

Hi,
I’m trying to create a PolyLine3D and I can’t figure out how to show the Axis (not from the Canvas but from the code) and how to set their color, plus I wanted to be able to set the grid I prefer. I’ll put the code at the end. Moreover as you can see I inserted my data one by one picking them from an array, I guess there is a better way using data in column from a .txt and a %lg%lg call just like in the TGraph constructor but I can’t seem to find it.
At last my goal is to project the 3D graph on two of the screens defined by the axis so that If I have a tilted circle I would see a tilted line on a screen and an ellipse on the other two with (possibly) only two screens showing, being the ones behind the 3D PolyLine. It seemed a natural feature of 3D images but I don’t know if there is a way to do it with PolyLine3D or TGraph2D, let me know!
One last curiosity, I’ve used MultiGraph to plot multiple TGraph in the same canvas, what can I do to have the same result with multiple TGraph2D since MultiGraph does not accept them?
Thanks in advance and sorry if those are trivial questions, I just started using the platform.

#include <iostream>
using namespace std;

void RLC2()
{
	double x, y, z;

	TCanvas *c1 = new TCanvas("c1","battimenti 50k",10,20,750,350);
	c1->SetGrid();

// -----------------------------------FIRST POLYLINE-------------------------------------

	TPolyLine3D *pl1 = new TPolyLine3D(13);
	pl1->Draw("LINE");
	pl1->SetLineColor(kRed+1);
	pl1->SetLineWidth(4);
	double X1[14] = {-2.015277, 1.849814, 5.068774, 6.543466, 5.744914, 2.979166, -0.7699732, -4.197940, -6.142563, -5.960888, -3.737958, -0.2877636, 3.164386, 5.450814};
	double Y1[14] = {4.767911, 4.475423, 2.651570, -0.1318587, -2.814449, -4.498798, -4.617337, -3.158470, -0.6443475, 2.083028, 4.013176, 4.526962, 3.464281, 1.259047
};
	double Z1[14] = {-2.075191, -1.532102, -0.4778128, 0.7188547, 1.644302, 1.994123, 1.645590, 0.7217537, -0.4475338, -1.456083, -1.956974, -1.801714, -1.054081, 0.0179260300
};
	for (int i=0; i<14; i++)
		{
		x=X1[i]; y=Y1[i]; z=Z1[i];
		pl1->SetPoint(i,x,y,z);
		}

// -----------------------------------SECOND POLYLINE-------------------------------------

	TPolyLine3D *pl2 = new TPolyLine3D(17);
	pl2->Draw("LINE");
	pl2->SetLineColor(kMagenta+1);
	pl2->SetLineWidth(4);
	double X2[18] = {0.9726839, -1.660949, -4.066839, -5.863286, -6.766183, -6.601581, -5.390096, -3.322105, -0.7187566, 2.010551, 4.433869, 6.178174, 6.967708, 6.662008, 5.298127, 3.102217, 0.4221839, -2.315812};
	double Y2[18] = {-3.187782, -3.141719, -2.606684, -1.65354, -0.3969614, 0.9359624, 2.099456, 2.948565, 3.342197, 3.208517, 2.579093, 1.530916, 0.2295574, -1.13461, -2.278769, -3.07633, -3.392004, -3.172321};
	double Z2[18] = {3.059374, 2.590367, 1.700995, 0.5259059, -0.7516125, -1.918642, -2.801564, -3.273787, -3.238032, -2.695588, -1.74019, -0.5126015, 0.7935861, 1.964166, 2.826159, 3.252647, 3.16342, 2.565564};
	for (int i=0; i<18; i++)
		{
		x=X2[i]; y=Y2[i]; z=Z2[i];
		pl2->SetPoint(i,x,y,z);
		}

// -----------------------------------THIRD POLYLINE-------------------------------------

	TPolyLine3D *pl3 = new TPolyLine3D(43);
	pl3->Draw("LINE");
	pl3->SetLineColor(kBlue+1);
	pl3->SetLineWidth(4);
	double X3[44] = {-0.2855087, 0.0465945, 0.3780537, 0.6966285, 0.994588, 1.269677, 1.519964, 1.739971, 1.924867, 2.072076, 2.179342, 2.237323, 2.245699, 2.204789, 2.114918, 1.976407, 1.794731, 1.568281, 1.298024, 0.9842802, 0.6447675, 0.2904377, -0.06582456, -0.4156442, -0.747425, -1.056013, -1.341731, -1.602968, -1.828128, -2.01721, -2.164095, -2.269105, -2.322899, -2.329985, -2.285533, -2.185999, -2.037826, -1.839079, -1.603612, -1.328846, -1.021225, -0.6726938, -0.2996819, 0.07075333};
	double Y3[44] = {0.119071, 0.1216479, 0.1174604, 0.1116623, 0.1061863, 0.09555639, 0.08975827, 0.07848415, 0.06882062, 0.0520705, 0.03950791, 0.01985873, 0.002786496, -0.01589633, -0.03425703, -0.04907445, -0.07162268, -0.08579585, -0.1060893, -0.1183297, -0.1267048, -0.1283154, -0.1250942, -0.1247721, -0.1144643, -0.1102768, -0.1009354, -0.09288244, -0.0828968, -0.06679092, -0.05487256, -0.03522339, -0.02330503, -0.001723151, 0.01985873, 0.03983003, 0.05690227, 0.07107545, 0.08492651, 0.166, 0.1210037, 0.1322778, 0.1345326, 0.1297009};
	double Z3[44] = {-7.053191, -6.99521, -6.772626, -6.392848, -5.869407, -5.21583, -4.447259, -3.581409, -2.635674, -1.629381, -0.5821789, 0.4814536, 1.539935, 2.569107, 3.548032, 4.454162, 5.268814, 5.972335, 6.547653, 6.97415, 7.241517, 7.34492, 7.276629, 7.035999, 6.632051, 6.07767, 5.389932, 4.583334, 3.676881, 2.68958, 1.641402, 0.556185, -0.5444911, -1.640011, -2.702674, -3.7109, -4.640529, -5.474168, -6.192813, -6.781967, -7.226491, -7.507379, -7.614967, -7.5441};
	for (int i=0; i<44; i++)
		{
		x=X3[i]; y=Y3[i]; z=Z3[i];
		pl3->SetPoint(i,x,y,z);
		}

	TLegend *l = new TLegend(.1,.7,.4,.9);
	l->AddEntry(pl1,"5kHz","L");
	l->AddEntry(pl2,"30kHz","L");
	l->AddEntry(pl3,"50kHz","L");
	l->SetMargin(0.1);
	l->Draw();
}

ROOT Version: root 6.08/06
Platform, compiler: C++ std 2016

Try this one:

void RLC2()
{
   double x, y, z;

   TCanvas *c1 = new TCanvas("c1","battimenti 50k",10,20,750,350);
   TH3F* h3 = new TH3F("h3", "h3", 10, -10., 10, 10, -10., 10, 10, -10, 10.);
   h3->Draw();

// -----------------------------------FIRST POLYLINE-------------------------------------

   TPolyLine3D *pl1 = new TPolyLine3D(13);
   pl1->Draw("LINE");
   pl1->SetLineColor(kRed+1);
   pl1->SetLineWidth(4);
   double X1[14] = {-2.015277, 1.849814, 5.068774, 6.543466, 5.744914, 2.979166, -0.7699732, -4.197940, -6.142563, -5.960888, -3.737958, -0.2877636, 3.164386, 5.450814};
   double Y1[14] = {4.767911, 4.475423, 2.651570, -0.1318587, -2.814449, -4.498798, -4.617337, -3.158470, -0.6443475, 2.083028, 4.013176, 4.526962, 3.464281, 1.259047
};
   double Z1[14] = {-2.075191, -1.532102, -0.4778128, 0.7188547, 1.644302, 1.994123, 1.645590, 0.7217537, -0.4475338, -1.456083, -1.956974, -1.801714, -1.054081, 0.0179260300
};
   for (int i=0; i<14; i++)
      {
      x=X1[i]; y=Y1[i]; z=Z1[i];
      pl1->SetPoint(i,x,y,z);
      }

// -----------------------------------SECOND POLYLINE-------------------------------------

   TPolyLine3D *pl2 = new TPolyLine3D(17);
   pl2->Draw("LINE");
   pl2->SetLineColor(kMagenta+1);
   pl2->SetLineWidth(4);
   double X2[18] = {0.9726839, -1.660949, -4.066839, -5.863286, -6.766183, -6.601581, -5.390096, -3.322105, -0.7187566, 2.010551, 4.433869, 6.178174, 6.967708, 6.662008, 5.298127, 3.102217, 0.4221839, -2.315812};
   double Y2[18] = {-3.187782, -3.141719, -2.606684, -1.65354, -0.3969614, 0.9359624, 2.099456, 2.948565, 3.342197, 3.208517, 2.579093, 1.530916, 0.2295574, -1.13461, -2.278769, -3.07633, -3.392004, -3.172321};
   double Z2[18] = {3.059374, 2.590367, 1.700995, 0.5259059, -0.7516125, -1.918642, -2.801564, -3.273787, -3.238032, -2.695588, -1.74019, -0.5126015, 0.7935861, 1.964166, 2.826159, 3.252647, 3.16342, 2.565564};
   for (int i=0; i<18; i++)
      {
      x=X2[i]; y=Y2[i]; z=Z2[i];
      pl2->SetPoint(i,x,y,z);
      }

// -----------------------------------THIRD POLYLINE-------------------------------------

   TPolyLine3D *pl3 = new TPolyLine3D(43);
   pl3->Draw("LINE");
   pl3->SetLineColor(kBlue+1);
   pl3->SetLineWidth(4);
   double X3[44] = {-0.2855087, 0.0465945, 0.3780537, 0.6966285, 0.994588, 1.269677, 1.519964, 1.739971, 1.924867, 2.072076, 2.179342, 2.237323, 2.245699, 2.204789, 2.114918, 1.976407, 1.794731, 1.568281, 1.298024, 0.9842802, 0.6447675, 0.2904377, -0.06582456, -0.4156442, -0.747425, -1.056013, -1.341731, -1.602968, -1.828128, -2.01721, -2.164095, -2.269105, -2.322899, -2.329985, -2.285533, -2.185999, -2.037826, -1.839079, -1.603612, -1.328846, -1.021225, -0.6726938, -0.2996819, 0.07075333};
   double Y3[44] = {0.119071, 0.1216479, 0.1174604, 0.1116623, 0.1061863, 0.09555639, 0.08975827, 0.07848415, 0.06882062, 0.0520705, 0.03950791, 0.01985873, 0.002786496, -0.01589633, -0.03425703, -0.04907445, -0.07162268, -0.08579585, -0.1060893, -0.1183297, -0.1267048, -0.1283154, -0.1250942, -0.1247721, -0.1144643, -0.1102768, -0.1009354, -0.09288244, -0.0828968, -0.06679092, -0.05487256, -0.03522339, -0.02330503, -0.001723151, 0.01985873, 0.03983003, 0.05690227, 0.07107545, 0.08492651, 0.166, 0.1210037, 0.1322778, 0.1345326, 0.1297009};
   double Z3[44] = {-7.053191, -6.99521, -6.772626, -6.392848, -5.869407, -5.21583, -4.447259, -3.581409, -2.635674, -1.629381, -0.5821789, 0.4814536, 1.539935, 2.569107, 3.548032, 4.454162, 5.268814, 5.972335, 6.547653, 6.97415, 7.241517, 7.34492, 7.276629, 7.035999, 6.632051, 6.07767, 5.389932, 4.583334, 3.676881, 2.68958, 1.641402, 0.556185, -0.5444911, -1.640011, -2.702674, -3.7109, -4.640529, -5.474168, -6.192813, -6.781967, -7.226491, -7.507379, -7.614967, -7.5441};
   for (int i=0; i<44; i++)
      {
      x=X3[i]; y=Y3[i]; z=Z3[i];
      pl3->SetPoint(i,x,y,z);
      }

   TLegend *l = new TLegend(.1,.7,.4,.9);
   l->AddEntry(pl1,"5kHz","L");
   l->AddEntry(pl2,"30kHz","L");
   l->AddEntry(pl3,"50kHz","L");
   l->SetMargin(0.1);
   l->Draw();
}

It works, thanks, I’ll try to finish it from here. In the meantime I have drawn the grid and the projection of the 3D polyline with other polylines. Still don’t know if there is a way to project the 3Dgraph/polyline.
Anyway thanks again!

Ah yes sorry I did not replied to this one because Polyline3D is just a set of x,y, z coordinates and projections to one of the plans xy xz or yz can simply be done by ignoring the un-mentionned axis seems to me.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.