I want to move an object around a circle therefore, am using equation of circle to every quadrant…
I wrote this:
if(keyDown(“up”) && this.guy.x <= 600 && this.guy.x <= 400){
The equation of a circle can be written as follow: (x - cx )² + (y - cy)² = r²
where (cx, cy) is the center of your cricle and r is the radius. All the pairs (x, y) that fit the equation will be a point of the circle.
You can indeed get the x value by rearranging the above equation BUT you will have to deal with solving a second degree equation that can have none, 1 or 2 solutions.
You can get that intuition visually:
Given a Y value, you can be in the case of the blue line (no solution), the red line (1 solution) or the orange line (2solutions)
Now, instead of working with that equation of a circle, we usually work with its parametric form. Given a center (cx, cy), a radius r and an angle alpha, you can get the (x, y) coordinates of the point with the following equations:
let cx, cy, r;
function setup() {
createCanvas(400, 400);
angleMode(DEGREES);
cx = 200;
cy = 200;
r = 100
angleSlider = createSlider(0, 360, 0);
angleSlider.position(50, 350);
angleSlider.size(300, 20);
}
function draw() {
background(20);
noFill();
stroke(200);
strokeWeight(2);
// Draw a circle at position (cx, cy) and radius r
ellipse(cx, cy, 2*r, 2*r);
// Place a point on the circle based on the angle
let x = cx + r * cos(angleSlider.value());
let y = cy + r * sin(angleSlider.value());
fill(230, 10, 10);
noStroke();
ellipse(x, y, 20, 20);
}
OK;
Nice, thanks for your help…
Have to adapt the code according to me coz, I have to change the x or y position and I should get the other coordinate…
Will it work that way???
In your code this.position is the centre of the circle 234 is the radius of the circle
so looks good so far but then this.angle++; increments the angle by 1 radian or ~57.3 degrees which is huge try this.angle += 0.01745; which is approximately 1 degree
Why would you need me to dm you? If you have a question, post it on the forum. The point is that everyone can benefit from wathever help you need. Plus I might not be able to answer your question but other people could.