With given x and y coordinates for the centre of the circle, as well as the radius, i managed to make it using this formula: (x−h)^2+(y−k)^2=r^2
And the code does work for some values, for example x = 15, y = 15 and radius = 6, it does create a correct circle, but if i make the radius bigger, once it gets close to the value of x or y, the last 2 "parts" of the circle do not work and the first part draws a weird shape.
void cerc(int x, int y, int raza)
{
// first part
for (int i = y; i < 50; i++) {
for (int j = x; j < 50; j++) {
if ((pow(j - x, 2)) + (pow(i - y, 2)) <= pow(raza, 2) && matriceHarta[i][j] == 0) {
matriceHarta[i][j] = -1;
}
}
}
// second part
for (int i = y - raza; i <= y; i++) {
for (int j = x - raza; j <= x; j++) {
if ((pow(j - x, 2)) + (pow(i - y, 2)) <= pow(raza, 2) && matriceHarta[i][j] == 0) {
matriceHarta[i][j] = -1;
}
}
}
// third part
for (int i = y; i <= raza + y; i++) {
for (int j = x; j >= raza; j--) {
if ((pow(j - x, 2)) + (pow(i - y, 2)) <= pow(raza, 2) && matriceHarta[i][j] == 0) {
matriceHarta[i][j] = -1;
}
}
}
// fourth part
for (int i = raza; i <= y; i++) {
for (int j = x; j <= x + raza; j++) {
if ((pow(j - x, 2)) + (pow(i - y, 2)) <= pow(raza, 2) && matriceHarta[i][j] == 0) {
matriceHarta[i][j] = -1;
}
}
}
}
*cerc means 'circle', raza means 'radius' and matriceHarta means 'matrixMap'
This is the shape it creates when i use x = 15, y = 15, radius = 10;
,this is the shape it creates when i input x = 15. y = 15 and radius = 6