# Draw a circle around a point?

Hi guys,

I have a question about drawing a circle around a point, i.e. I have two coordinates x,y and this point is in my pad. Now I would like to draw a circle around this point with a certain angular distance. This might be easy, but I need the points of the circle, since I want to transform them into another coordinate system, so that they would be in some way distorted.

Maybe I can create them through a rotation, but isn’t there another way, easier?

Thanks a lot,
Stephan

Example:

``````{
c1 = new TCanvas("c1");
Double_t xmin = -150;
Double_t xmax =  150;
Double_t ymin = -150;
Double_t ymax = ((xmax-xmin)*h/w)-150;
c1->SetFixedAspectRatio();
c1->Range(xmin,ymin,xmax,ymax);
TEllipse el1(0.,0.,50.,50.);
el1.Draw();
}``````

Oh I’m sorry… I should reword my description. The point is drawn in an histogram. So I would like to draw the circle also in the histogram and I should be able to access each point of the circle to transform it into another coordinate system.

Thank you!

can you post a running little macro showing where you are encountering difficulties ? That would be easier than trying to make one based on your description of the problem.

I don’t think that a macro is necessary, since I don’t know how to do it .
I just have an idea what I want to do:
A point on a sphere is given and I want to create some points around it in a fixed angular distance, but I also need the coordinates of the circle, since I want to make a projection of the sphere in 2 dimensions.

My idea was to use a rotation matrix, but I don’t think that this is the most elegant way .

``The point is drawn in an histogram. So I would like to draw the circle also in the histogram and I should be able to access each point of the circle to transform it into another coordinate system.``

To draw a circle you can use the macro I sent you. You can drawn the circle on top of the histogram in the histogram coordinates. I do not know if it is what you mean by “drawing in the histogram” … is the circle part of the histogram data ? … In that case you should fill some bins according to a circle… is that what you mean by “in” the histogram ?

I tested your macro and it works in the way you described it, but unfortunately it isn’t what I need.

Here is short macro, that hopefully explains my problem better:

TH3D *earth = new TH3D(“earth”, “earth”, 100, -1., 1., 100, -1., 1.,100, -1., 1.);

double phi=0., cos_theta=0., theta=0.;

for(int i=0; i<100; i++){
phi=gRandom->Uniform(0., 2*PI);
cos_theta=gRandom->Uniform(0., 1.);
theta=acos(cos_theta);
earth->Fill(cos(phi)*sin(theta), sin(phi)*sin(theta), cos_theta);
}

TCanvas *c1 = new TCanvas(“c1”, “c1”,1);
earth->Draw();

Each point should be surrounded by a circle in constant angular distant, doesn’t matter if I change my point of view.

do:
earth->SetMarkerStyle(4);

Yes, but… do these circles have an angular distance I can choose and can I access the circle (points of the circle) to make a projection?

no … they are simple markers. It is not foreseen to drawn real circles from TH3::Draw(). You can draw 3d boxes:

earth->Draw(“box”);

So my suggestion from the beginning is the only solution?

Use a rotation matrix to generate a circle around these points to obtain what I want…

Any way, if you want to access the individual “circles” … (is it not sphere in fact as you are in 3D …?) … using a TH3 is surely no a good idea. You will need some data model allowing you to access/change each circle parameters .
Here is a simple example to draw simple 3d lines:

``````{
c1 = new TCanvas("c1","PolyLine3D & PolyMarker3D Window",200,10,500,500);

// Creating a view
TView3D *view = TView::CreateView(1);
view->SetRange(5,5,5,25,25,25);

// Create a first PolyLine3D
TPolyLine3D *pl3d1 = new TPolyLine3D(5);
pl3d1->SetPoint(0, 10, 10, 10);
pl3d1->SetPoint(1, 15, 15, 10);
pl3d1->SetPoint(2, 20, 15, 15);
pl3d1->SetPoint(3, 20, 20, 20);
pl3d1->SetPoint(4, 10, 10, 20);

// Create a first PolyMarker3D
TPolyMarker3D *pm3d1 = new TPolyMarker3D(12);
pm3d1->SetPoint(0, 10, 10, 10);
pm3d1->SetPoint(1, 11, 15, 11);
pm3d1->SetPoint(2, 12, 15, 9);
pm3d1->SetPoint(3, 13, 17, 20);
pm3d1->SetPoint(4, 14, 16, 15);
pm3d1->SetPoint(5, 15, 20, 15);
pm3d1->SetPoint(6, 16, 18, 10);
pm3d1->SetPoint(7, 17, 15, 10);
pm3d1->SetPoint(8, 18, 22, 15);
pm3d1->SetPoint(9, 19, 28, 25);
pm3d1->SetPoint(10, 20, 12, 15);
pm3d1->SetPoint(11, 21, 12, 15);
pm3d1->SetMarkerSize(2);
pm3d1->SetMarkerColor(4);
pm3d1->SetMarkerStyle(2);

// Draw
pl3d1->Draw();
pm3d1->Draw();
}``````

Or you need something more complex and use OpenGL ?