简体   繁体   中英

Calculate end rotation circles

I have one circle, which grows and shrinks by manipulating the radius in a loop. While growing and shrinking, I draw a point on that circle. And within the same loop, increasing the angle for a next point.

The setup is like this:

let radius = 0;
let circleAngle = 0;
let radiusAngle = 0;

let speed = 0.02;
let radiusSpeed = 4;
let circleSpeed = 2;

And in the loop:

radius = Math.cos(radiusAngle) * 100;

// creating new point for line  
let pointOnCircle = {
    x: midX + Math.cos(circleAngle) * radius,
    y: midY + Math.sin(circleAngle) * radius
};

circleAngle += speed * circleSpeed;
radiusAngle += speed * radiusSpeed;

This produces some kind of flower / pattern to be drawn. After unknown rotations, the drawing line connects to the point from where it started, closing the path perfectly.

Now I would like to know how many rotations must occure, before the line is back to it's beginning.

A working example can be found here: http://codepen.io/anon/pen/RGKOjP

The console logs the current rotations of both the circle and the line.

Full cycle is over, when both radius and point returns to the starting point. So

speed * circleSpeed * K = 360 * N
speed * radiusSpeed * K = 360 * M

Here K is unknown number of turns, N and M are integer numbers.

Divide the first equation by the second

circleSpeed / radiusSpeed  = N / M

If speed values are integers, divide them by LCM to get minimal valid N and M values, if they are rational, multiply them to get integer proportion.

For your example minimal integers N=1,M=2, so we can get

K = 360 * 1 / (0.02 * 2) = 9000 loop turns

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM