package cse1030.drawing;
public class Spiro {
/**
* The greatest common divisor of two positive integers computed using the
* Euclidean algorithm.
*
* @param p
* an integer greater than zero
* @param q
* an integer greater than zero
* @return the greatest common divisor of p
and q
*/
private static int gcd(int p, int q) {
while (p != q) {
if (p > q) {
p = p - q;
} else {
q = q - p;
}
}
return p;
}
/**
* Computes the number of times that the innermost circle must travel around
* the fixed circle to complete the hypotrochoid pattern. The innermost circle
* has radius p / q
and the fixed circle has radius
* 1
.
*
* @param p
* together with q
defines the radius of the innermost
* circle
* @param q
* together with p
defines the radius of the innermost
* circle
* @return the number of times that the innermost circle must travel around
* the fixed circle for a complete hypotrochoid
*/
public static int numberOfRevolutions(int p, int q) {
if (p <= 0) {
throw new IllegalArgumentException("p must be greater than zero");
}
if (q <= 0) {
throw new IllegalArgumentException("q must be greater than zero");
}
int g = Spiro.gcd(p, q);
return (p / g);
}
/**
* Draws a hypotrochoid using the command line arguments to define the
* parameters of the hypotrochoid.
*
* @param args
* requires 3 arguments (an int
, an int
,
* and a double
.
*
* The first two parameters, P
and Q
,
* define the radius, r
, of the inner circle (
* r = P / Q
). The second parameter, H
,
* defines the distance from the center of the inner circle to
* the tip of the pencil.
*/
public static void main(String[] args) {
final int P = Integer.parseInt(args[0]);
final int Q = Integer.parseInt(args[1]);
final double H = Double.parseDouble(args[2]);
final int N = Spiro.numberOfRevolutions(P, Q);
// here is how you draw an IPoint2D
IPoint2D point = new IPoint2D(0., 0.);
SimpleDrawing.drawPoint(point);
// YOUR CODE SHOULD GO AFTER THIS COMMENT
}
}