Path length instead of degrees.
-
Hi, i am using QGraphicsScene, and there i wanna rotate one object, nearly another one. The static object is a circle, the moving object should move around the path.
This is good, i can already simply rotate it. The problem is, i don't want to rotate it, i want to move it around that circle, but by the path length, so if the circle has 4000 length of any kind of units, so if i move it by 1000 units, it should do the angle of 90.
(4000 / 1000 = 4 ---- 360 / 4 = 90)I dont want the angles, i want the path size, how could i achieve it? I have no idea how to do it, i just started with QGraphicsScene.
-
Hi
but what is "the path" ? -
a shot in the dark here, because I'm not entierly sure what you want to do, but this (it's untested)
should give you a point(x,y) depending on the radius and the length of the partial circumference.its untested, and I think you'll need to adjust it to the correct point of origin
QPoint lengthToPoint(const int radius, const int semiCyrcleLength) { //arc angle double angle = (semiCyrcleLength *360)/(2* 3.1415 * radius); //angle to x & y QPoint p(cos(angle),sin(angle)); return p; }
-
@Loc888 said in Path length instead of degrees.:
if the circle has 4000 length of any kind of units, so if i move it by 1000 units, it should do the angle of 90.
(4000 / 1000 = 4 ---- 360 / 4 = 90)...
So if the circle has 120 cm of length, if i move another item on this circle by 60cm, it should do a 180 degree move.
double findDegrees(double fullCircleLength, double pathLength) { double ratio = fullCircleLength / pathLength; double angle = 360 / ratio; return angle; } int main() { qDebug() << findDegrees(4000, 1000); // Output: 90 qDebug() << findDegrees(120, 60); // Output: 180 return 0; }
Is this what you want?
@mrjj
Image? All i want, is instead of using 360 degrees, use a distance value.Look, your words were not clear.
@mrjj asked you for an image so that he can understand what you want, so that he can help you. If you don't want to give him the image, then he cannot help you.
@aha_1980 If you don't know how to do it, that's it, i will not talk about anything else, i know what i wanna achieve.
@aha_1980 was also trying to help you. There is no need to be rude.
-
@JKSH I am not trying to be rude, i just wanted to say, i am not interested in doing this, by another way.
I am not sure if i am explaining it bad, but if you can't understand it, or maybe you are not sure, then i will make a simple image of it, maybe it will help. -
@Loc888 said in Path length instead of degrees.:
@JKSH I am not trying to be rude, i just wanted to say, i am not interested in doing this, by another way.
OK.
I am not sure if i am explaining it bad, but if you can't understand it, or maybe you are not sure, then i will make a simple image of it, maybe it will help.
Yes, please do.
Both @J-Hilk and myself have tried to understand your question, and we both gave you some code. If the code is not what you want, that means we can't understand what you want. A simple image will be very helpful.
-
Image1: https://tinypic.pl/v6f0sy6qi612
Image2: https://tinypic.pl/hwvlldlzqaah
Image3: https://tinypic.pl/zs4be25yzsjr <-- This one is the most important. -
@Loc888 said in Path length instead of degrees.:
Image1: https://tinypic.pl/v6f0sy6qi612
Image2: https://tinypic.pl/hwvlldlzqaah
Image3: https://tinypic.pl/zs4be25yzsjr <-- This one is the most important.Great, thank you.
You can use the
findDegrees()
function that I wrote before, right?double findDegrees(double fullCircleLength, double pathLength) { double ratio = fullCircleLength / pathLength; double angle = 360 / ratio; return angle; }
The function calls below will give you the same results:
this->ball_P->setRotation( findDegrees(50000, 25000) );
this->ball_P->setRotation(180);