| 08-23-2007, 07:31 PM | #1 |
How do I make a proper working circle? I'm doing SquareRoot(X squared + Y squared) >= R squared as an if condition. I start off setting Y = R and doing a loop that subtracts Y by 25 then I find X. When the loop is finished, the square root of X squared + y squared comes out to be a 50 less than R squared. And by the time Y hits 0, X squared + y squared is equal to R squared. I have a few problems. A) There is a huge gap from the first point to the next. B) The closer Y is to 0, the closer the points are. C) I have to use 4 loops to make the whole circle. I cannot post the code here due to the fact that the computer I am running WC3 on does not have internet. It probably sounds really easy to a lot of readers, but I'm probably doing something wrong with my code and I would like to see other people's code to see what they are doing versus mine. |
| 08-23-2007, 07:48 PM | #2 |
Another JASS math problem :) Use roughly this: JASS:
newX = centerX+(Cos(angle*bj_DEGTORAD)*radius)
newY = centerY+(Sin(angle*bj_DEGTORAD)*radius)
|
| 08-23-2007, 09:41 PM | #3 |
The number of posts you both have made are anagrams of each other. Just had to post it >< Sorry for offtopic. |
| 08-24-2007, 11:47 PM | #4 |
They're not anagrams, they're palindromes. And as to what CommanderZ is getting at, you need to get the Center X/Y values, the project new values at an angle increment such that the whole circle is filled up. Here's an example function: JASS:function CreateEffectsInCircle takes string modelPath, real CX, real CY, real Radius, integer howMany returns nothing local real X local real Y local integer I = 0 local real AngleIncrement = 360.00/howMany*0.01745 //In radians, not degrees loop set I = I+1 exitwhen I > howMany set X = CX+Radius*Cos(AngleIncrement*I) //These can be inlined, but for the sake of demonstration they're not set Y = CY+Radius*Sin(AngleIncrement*I) call CreateEffect(modelPath, X, Y) endloop endfunction |
| 08-25-2007, 09:11 AM | #5 |
They are anagrams, palindromes are words/numbers/phrases that read the same from both directions. On topic: I have a question on this though. Pyro, I see you're using a constant instead of DEGTORAD. Do you know how much faster this is? or is it just the power of habit. Furthermore, mind you that pyro's loop doesn't start at 0, but at 1. The 0.0 rad effect is created last in the loop. This doesn't matter if you're using a loop, but that was just pyro's example. If you're using a timer, it's worth considering. In a more general sense: With most of the math stuff involved in circles you're better off using cos en sin because calculating a root takes a lot of effort. If you want to compare the distance of 2 points to something, it's better to compare their distance's squared instead of taking the root first, etc. |
| 08-25-2007, 10:04 AM | #6 |
I thought you were remarking that CommanderZ's post count was 232 and that ChaosWolfs' was at 121 (at the time of posting), so I assumed you were talking about palindromes. Yes, my loop does start at 1 because I like to have a counter of the number of times the loop has run. You could just as easily start at 0 and then exitwhen I > howMany-1. As for using the number instead of the variable, I don't think there's a noticeable speed tradeoff... but if you were doing this many times/second you'd obviously want to do it as efficiently as possible. Another reason is that bj_DEGTORAD is actually bj_PI/180.00 so it has to perform an extra calculation each time. You could do this by getting the circle's formula and projecting points by inputting x/y values also... but it would be hell to do. |
| 08-25-2007, 11:10 AM | #7 |
Ah, I see.. no they were 123 and 231. How peculiar. What advantage could calculating pi over 180 every time have? If you want to use a formula for the circle, you'd have to make 2 formulas (1 negative) and either use sqrt or inverse cos every calculation. Hardly ideal and in every respect inferior to angle addition. |
| 08-25-2007, 11:17 AM | #8 | |
Quote:
|
| 08-25-2007, 01:01 PM | #9 | |
Quote:
I don't think that you are right here. The value of bj_DEGTORAD is calculated once at the start of the game and saved (but only the value is saved not the way it's calculated) as constant bj_DEGTORAD. So inside the game bj_DEGTORAD=0.17453 in the same way as bj_PI=3.14159 |
| 08-25-2007, 01:05 PM | #10 | |
Quote:
I thought so too... Source? |
| 08-25-2007, 01:40 PM | #11 |
Prove me wrong, then. I can't say I disbelieve you. |
| 08-25-2007, 02:00 PM | #12 |
Pytho is correct. It's a global variable initialized to that value. It's the same as reading any other global. |
| 08-25-2007, 02:58 PM | #13 |
Sorry for the offtopic... BLU!!! you're back LOL!! Now on topic: Definitely the bj_DEGTORAD and its complement are set once, if you could save a formula as a variable, probably JASS wouldn't have real type, it would be a handle, and inefficient. As a conclusion, it is nice to use directly those BJs instead bj_PI * I-forgot-that-value. |
| 08-25-2007, 03:01 PM | #14 | |
Quote:
1/180...? :D |
| 08-25-2007, 03:34 PM | #15 | |
Quote:
|
