|
Rose chart with axis origin not in the middle |
Posted by Medic89 on Jun-08-2023 23:46 |
|
Hi Peter,
just as a fun project I'm trying to simulate a flight display for a flightsimulator homecockpit with chartview. I used a rosechart to simulate an artificial horizon, but when an aircraft climbs, the horizon (which in a rose chart is the horizontal axis that runs through the origin point) has to move downwards. Is that possible with a rosechart?
|
Re: Rose chart with axis origin not in the middle |
Posted by Peter Kwan on Jun-09-2023 04:27 |
|
Hi Medic89,
The shape you want is called "circle segment". The only chart type in ChartDirector that can have a circle segment shape is angular meter.
The attached chart is drawn by using the following code:
AngularMeter *m = new AngularMeter(320, 320, 0x000000);
m->getDrawArea()->circle(160, 160, 148, 148, 0x228822, 0x228822);
m->setMeter(160, 160, 148, -110, 110);
m->addScaleBackground(148, 0x88ccff);
m->setCap(0, Chart::Transparent, Chart::Transparent);
m->setLineWidth(0);
m->addText(160, 15, "<*img=@Diamond,width=11,edgeColor=FFFF00*>", "", 10, 0x000000, Chart::Center);
By adjusting the angles (-110, 110) in the above code, you can move the line up/down and also rotate the line (in case you plane can roll too).
Best Regards
Peter Kwan
|
Re: Rose chart with axis origin not in the middle |
Posted by Medic89 on Jun-10-2023 21:39 |
|
wow, that is cool, thank you peter!
Now I'm trying to draw a white line between the two parts of the gauge (basically the bottom axis of the angularmeter), but I can only draw a total frame, not just on the bottom. my second problem is, that I have to place some ticks on the white line, that shift along the line, when the aircraft is turning. I tried to use m->getDrawArea()->line(), but with this function, I always have to get the position of the bottom line of the angularmeter, is there a simple way to achieve this?
|
Re: Rose chart with axis origin not in the middle |
Posted by Peter Kwan on Jun-13-2023 03:44 |
|
Hi Medic89.
Since you have all the parameters of the meter (the center, radius and the angles), you can compute the line easily using textbook maths:
// -110, 110 are the angles in degrees, in C++ we need to use radians
double startAngle = -110.0 / 180 * 3.1416;
double endAngle = 110.0 / 180 * 3.1416;
// (160, 160) is the center, and 148 is the radius. Compute the end points of the line.
int x1 = 160 + (int)(148 * sin(startAngle));
int y1 = 160 - (int)(148 * cos(startAngle));
int x2 = 160 + (int)(148 * sin(endAngle));
int y2 = 160 - (int)(148 * cos(endAngle));
// Draw the line
DrawArea *d = m->makeChart();
d->line(x1, y1, x2, y2, 0xffffff);
With the end points of the line known, you would be able to draw the ticks easily.
Best Regards
Peter Kwan |
|