2014-07-13 29 views
0

我試圖執行我的計劃,這將讓我有每個字母計算旋轉爲面向圓的中心座標....需要幫助修改一個簡單的公式,使其普遍

的我正在使用的字符數是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

好吧想通了:)

我甚至不需要轉動他的所作所爲是獲取當前度那封信,並添加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); 
}