我正在尝试为我的程序执行计算,这将允许我将每个字母旋转到面向圆的中心坐标....
我正在使用的字符数是16,但我希望这个算法可以处理任意大小的圆圈周围的任意数量的字母,字母的位置已经设置在一个循环中,将它们置于正确的位置。
The formula I have goes something like this
degree = 360 / phrase.length() -> where phrase.length() is 16
rotate = 360 / (phrase.length() - degree
This is where I set the rotation
degrees = degree
Letter.setRotate((degrees + rotate) - (205));
degrees = degrees + degree
the next letter is then set using the Letter.setRotate((degrees + rotate) - (205)
this goes on and on until each letter is printed and rotated
使用上面的公式,字母打印出来面向中心,但是这样做的更好的方法是什么,这样我可以将它用于未知的短语长度?
下面是我到目前为止创建的循环,即使没有编程经验,您也可以理解其中的大部分内容......至少是方程式部分
// Place text in a circular pattern
int i = 0;
double degree = 360 / phrase.length(), rotate = 360 / (phrase.length() - degree);
Font font = new Font("Times Roman", textSize);
for (double degrees = 0; i < phrase.length(); i++, degrees += degree) {
double pointX = circle.getCenterX() + circle.getRadius() *
Math.cos(Math.toRadians(degrees));
double pointY = circle.getCenterY() + circle.getRadius() *
Math.sin(Math.toRadians(degrees));
Text letter = new Text(pointX, pointY, phrase.charAt(i) + "");
letter.setFont(font);
letter.setRotate((degrees + rotate) - (205));
getChildren().add(letter);
}
答案 0 :(得分:0)
好吧想通了:)
我甚至不需要旋转我所做的就是获得该字母的当前度数并添加90 ...显然我过于复杂了
这是工作循环
// Place text in a circular pattern
int i = 0;
double degree = 360 / phrase.length();
Font font = new Font("Times Roman", textSize);
for (double degrees = 0; i < phrase.length(); i++, degrees += degree) {
double pointX = circle.getCenterX() + circle.getRadius() *
Math.cos(Math.toRadians(degrees));
double pointY = circle.getCenterY() + circle.getRadius() *
Math.sin(Math.toRadians(degrees));
Text letter = new Text(pointX, pointY, phrase.charAt(i) + "");
letter.setFont(font);
letter.setRotate(degrees + 90);
getChildren().add(letter);
}