Win a copy of The Way of the Web Tester: A Beginner's Guide to Automating Tests this week in the Testing forum!

# Polygon Rotation

Ben Duffield
Greenhorn
Posts: 4
Hi there!
This class opens a DialogBox, which determines the Polygon's vertices. Now even-numbered vertices need to be rotated clockwise and odd-numbered vertices need to be rotated anti-clockwise!
For that I have created a second for-loop to take care of the odd-numbered vertices. I am however not sure what code exactly to write to make the odd-numbered vertices move anti-clockwise! The code for the for-loop that is supposed to make odd-numbered vertices move anti-clockwise is missing! I appreciate any help with this!
Below is the whole code.

Julie de Wet
Greenhorn
Posts: 17
Have you tried using -1 * angle ? i.e. negative angles.

Jim Yingst
Wanderer
Sheriff
Posts: 18671
I think
is being interpreted aswhen what you want is
It's a good idea to always use braces for if/for/while statements. At least until you're sure you understand what happens if you omit them. Note also that most IDEs (Eclipse, IntelliJ, NetBeans, JBuilder, etc) can format code for you - the indentation they use will make it obvious how the code is really being interpreted. For a beginner it's probably best to avoid IDEs initially to make sure you know how to write code yourself. But once you've mastered the essentials, and IDE can certainly help avoid these mistakes in the future. It's kind of like learning long division - you need to know how it works to really understand math, but after you've learned it you'll probably just use a calculator for anything complicated.

Ben Duffield
Greenhorn
Posts: 4
The brackets don't make any difference here, but I know it's best to always include them. -1 * angle does not produce the desired effect. The Polygon just moves clockwise.
I have changed the algorithm of that section to the code below so as to only use one for-loop and keep it simple. But even the code below doesn't make the odd-vertices move anti-clockwise!

Julie de Wet
Greenhorn
Posts: 17
try and replace

with

[ April 18, 2004: Message edited by: Julie de Wet ]

Jim Yingst
Wanderer
Sheriff
Posts: 18671
The brackets don't make any difference here
Ummm, there's a huge difference between
and
Note that in the former, the indentation is wrong, wrong, wrong. I haven't tried to analyze what your code really does, or what you're trying to do, but I guarantee that if you thought the indentation was correct in your original code, then you need to use braces.

Ben Duffield
Greenhorn
Posts: 4
[code]
public static PlanarPoint negVertex (PlanarPoint c, double alpha, double r) {
double a = c.getX()-1*(r*Math.cos(alpha));
double b = c.getY()-1*(r*Math.sin(alpha));
PlanarPoint w = new PlanarPoint(a, b);
return w;
}
[code]
The code above solved the error! This is the code that was originally posted by me, but for some reason it threw an exception error. Now after creating the file again, it works.
I made an error saying that the brackets don't make any difference, but what I wanted to say was that I didn't notice any difference then after compiling, as the polygon was only still moving clockwise!
Anyway thanks for all the help!