Reputation: 45331
I'm trying to make an Euelr circle with a mehod that I wrote which uses class named Turtle.
This is what I wrote:
public class turtleAa {
public static void main(String[] args) {
int number = LineInput.readInt();
euelr(number);
}
public static void euelr(int n){
Turtle leonardo = new Turtle();
leonardo.tailDown();
for (int i=1; i<=n; i++){
leonardo.moveForward(50);
leonardo.turnRight(90);
leonardo.moveForward(50);
leonardo.turnLeft(135);
leonardo.moveForward(35);
leonardo.turnLeft(90);
leonardo.moveForward(35);
leonardo.turnLeft(90);
leonardo.moveForward(70.71067812);
leonardo.turnLeft(135);
leonardo.moveForward(50);
leonardo.turnLeft(135);
leonardo.moveForward(70.71067812);
leonardo.turnLeft(135);
leonardo.moveForward(50);
leonardo.turnLeft(?)
}
}}
I want to make a full circle of Euler drawnings Two main problems with this:
Can't understad how to control correctly the angles with i and n.
leonardo the turtle is drawing the lines.
Thank you.
Upvotes: 0
Views: 345
Reputation: 74800
What about this?
leonardo.turnLeft(360/n);
This works only for divisors of 360, of course, but there are quite some of them (1,2,3,4,5,6,8,9,10,12,15,18,20...). If your turnLeft
method accepts non-integer (i.e. double
or float
) values, use
leonardo.turnLeft(360.0/n);
Instead (and it will also work for 7, 11, ... - approximately.)
Upvotes: 2
Reputation: 12592
What you want is the Fleury algorithm to find an Euler Circuit in (undirected)-weighted graph. The Fleury algorithm starts at a random position with a DFS and looks for the next edge to travel if that edge doesn't bridge the graph, meaning cutiing the graph in two parts. I'm not sure what you want to do with a turtle and mathematic? Can you elaborate?
Upvotes: 0