I have a QGraphicsScene, and I have determined where my center point is, but I now need to figure out how to place my items in the scene based on that information.
I have 2 pieces of data I need to work with: range and bearing.
Range obviously is how far away from the center point (or my location), and bearing is the direction from center point, with 0 being north, 180 being south and so on.
So for example, if I need to place an item at range: 20, bearing: 90, the item will be 20 (units) directly to the right of center point. Currently, placing the item with this data it is based off 0,0 being top left of the scene.
This all needs to be able to scale with the zoom state of the QGraphicsScene as well.
I'm totally lost at this conversion.
Unsure of how to get proper offsets with converting from coordinate system to coordinate system I managed to find a solution. Hopefully it's not considered too much of a hack job.
First I needed to offset from the top left (0,0), and knowing that my scene was 360, 360 that was easy.
Not being a math guy I was unsure about getting the angles, but after some research I saw that the info I had was exactly what I needed to derive a vector.
Here is the method I wrote to help me generate items in my QGraphicsScene.
QPointF Mainwindow::pointLocation(double bearing, double range){
int offset = 90; //used to offset Cartesian system
double centerX = 180;//push my center location out to halfway point
double centerY = 180;
double newX = centerX + qCos(qDegreesToRadians(bearing - offset)) * range;
double newY = centerY + qSin(qDegreesToRadians(bearing - offset)) * range;
QPointF newPoint = QPointF(newX, newY);
return newPoint;
}