void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600); 

  float jarBolaX = 800;
  float jarBolaY = 400;

  float radius = 100;
  float tJaga = hitungArahJaga(400, 0, jarBolaX, jarBolaY);

  float x1 = -cos(radians(90 + tJaga)) * radius;
  float y1 = sin(radians(90 + tJaga)) * radius;

  float x = jarBolaX - x1;
  float y = jarBolaY - y1;

  Serial.print("x1 :"); Serial.print(x1);
  Serial.print(" y1 :"); Serial.print(y1);
  Serial.print(" tJaga :"); Serial.print(tJaga);
  Serial.print(" x :"); Serial.print(x);
  Serial.print(" y :"); Serial.print(y);
}

void loop() {
  // put your main code here, to run repeatedly:
  delay(10); // this speeds up the simulation


}

float centerXLap = 400;

float hitungArahJaga(float x, float y, float x1, float y1){
  float tRobot = 0;

  float deltaX = x1 - x;
  float deltaY = y1 - y;

  float rJarakRobot = 10 * sqrt((deltaX / 10 * deltaX / 10) + (deltaY / 10 * deltaY / 10));

  if(deltaX >= 0){
    tRobot = ((acos(deltaX / rJarakRobot)) * (180/PI));
  } else{
    tRobot = -((acos(deltaX / rJarakRobot)) * (180/PI));
  }

  tRobot = 90 - tRobot;

  if(tRobot > 180){
    tRobot = tRobot - 360;
  }
  if(tRobot < - 180){
    tRobot = tRobot + 360;
  }

  return tRobot;
}