We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I am trying to create a little speedometer for my project, which requires the pointer (a triangle) to rotate depending on a variable. I can rotate it if it is translated to the center, but when I try to move it on to the speedometer dial, it seems a little random. Is there an equation to use to put it back in the same place each time no matter its angle? I've since use a technique that draw a triangle directly at a different angle each time, but the results also seem random. Here's the current code:
PImage speedo; //this is the dial
x=-260;
y =-155;
void setup(){
speedo = loadImage("speedo.png");
speedo.resize(112,64);
}
void draw(){
angle=robotSpeed/maxSpeed;
speedoAngle=angle*PI*(-1);
image(speedo,width-150,height-80);
//pointer
y+=2;
stroke(26,172,130);
triangle(x,y,x+3,y+30,x-3,y+30);//30 is the value that would need to be modified to rotate correctly, if I understood
}
Thanks
Answers
Don't. Translate first and THEN rotate.