ZDaemon Forum Index ZDaemon
Client/Server DOOM
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Question to Math pros about drawing Rhodonea

 
Post new topic   Reply to topic    ZDaemon Forum Index -> Wad Editing
View previous topic :: View next topic  
Author Message
Miami_vice
has entered the game!


Joined: 06 Sep 2008
Location: Lithuania, Vilnius

PostPosted: Tue Jan 26, 2016 12:36 pm    Post subject: Question to Math pros about drawing Rhodonea Reply with quote

Why when there's an even number of petals then it is spawned once, but when the number of petals is odd then it's spawning twice?

Video: https://www.youtube.com/watch?v=7xeQt05AtTM

Code: http://pastebin.com/HUMdw7qE

Material: https://en.wikipedia.org/wiki/Rose_%28mathematics%29

Besides what do you think about it?
Back to top
View user's profile Send private message
Sr69Mm-jC
Spamming!


Joined: 21 Jul 2011

PostPosted: Tue Jan 26, 2016 7:46 pm    Post subject: Re: Question to Math pros about drawing Rhodonea Reply with quote

From the very article that you provided yourself:

Wikipedia wrote:
If k is an integer, the curve will be rose-shaped with
2k petals if k is even, and
k petals if k is odd.

Where k is even, the entire graph of the rose will be traced out exactly once when the value of theta,θ changes from 0 to 2π. When k is odd, this will happen on the interval between 0 and π.

In the form k = n, for integer n, the shape will appear similar to a flower. If n is odd half of these will overlap, forming a flower with n petals. However if it is even the petals will not overlap, forming a flower with 2n petals.


Since I assume you intend to simply draw the roses with armor bonuses or whatever else, simply evaluate k%2 and add an if-else statement. Or just iterate from 0 to (2 - (k%2)) * pi instead. As to "why", well, because these exact formulas appear to behave like that, I guess? You could come up with other formulas that would behave differently.
Back to top
View user's profile Send private message
Miami_vice
has entered the game!


Joined: 06 Sep 2008
Location: Lithuania, Vilnius

PostPosted: Wed Jan 27, 2016 3:52 am    Post subject: Re: Question to Math pros about drawing Rhodonea Reply with quote

Sr69Mm-jC wrote:
From the very article that you provided yourself:

Wikipedia wrote:
If k is an integer, the curve will be rose-shaped with
2k petals if k is even, and
k petals if k is odd.

Where k is even, the entire graph of the rose will be traced out exactly once when the value of theta,θ changes from 0 to 2π. When k is odd, this will happen on the interval between 0 and π.

In the form k = n, for integer n, the shape will appear similar to a flower. If n is odd half of these will overlap, forming a flower with n petals. However if it is even the petals will not overlap, forming a flower with 2n petals.


Since I assume you intend to simply draw the roses with armor bonuses or whatever else, simply evaluate k%2 and add an if-else statement. Or just iterate from 0 to (2 - (k%2)) * pi instead. As to "why", well, because these exact formulas appear to behave like that, I guess? You could come up with other formulas that would behave differently.





Thank you Roman. I haven't read carefully about petals overlapping when k is odd. In that case on the interval between 0 and π the entire graph of the rose will be traced out exactly once. But since I'm iterating from 0 to 2π this is happening twice.
I have fixed it in two ways. The second way is better.

You are right by dividing petals number by 2 modulus in order to find out that odd numbers return 1 and even numbers return 0. And I have chosen your second offer to iterate from 0 to (2 - (k%2)) * pi. Not much to write.

The code looks like THIS. Here iteration condition is rose_abonuses-((k%2)*rose_abonuses)/2 so when k is even division by modulus 2 is zero and we subtract zero from armor bonuses number to get same intended number of armor bonuses to spawn. It is iterating through all intended number of bonuses making the angle = 1.0 * n / rose_abonuses; to receive values from 0.0 to 1.0 which is from 0 to 2π. 2k of petal is drawn.

When k is odd division by 2 modulus returns 1. This is multiplied by the number of all armor bonuses and divided by 2. We get half or by 1 less then half. We subtract half number of intended armor bonuses to get again half number of all intended armor bonuses. At the end of iteration angle becomes 0.5 which means π. With odd number of petals (or k in my case) it is drawn exactly once because angle is π. Like theory stated. But I'm disappointed losing half the number of chosen armor bonuses.

In the classic Math where radians take place, scientists measure angles and periods by π and 2π where 2π is full angle or period. Respectively it would be 180 or 360. However in Doom angles are measured from 0.0 to 1.0 where 1.0 if full angle or 2π. 0.5 would π.

In order not to lose all primarily chosen armor bonuses I have to iterate right that number of times. The only change should happen directly in angle expression. When there is even number of petals the angle at the end of iteration must be 2π or 1.0. And vice versa, when there is odd number of petals the angle at the end of iteration must remain π or 0.5.

To achieve this I'm iterating through all armor bonuses for (int n = 0; n < rose_abonuses; n++), but the angle is either 2π or π (1.0 or 0.5) depending on k%2:

angle = 1.0 * n / (rose_abonuses+(k%2)*rose_abonuses);

When k is even then k%2 is 0 and we don't add same number of armor bonuses. The division ends at almost 1.0 or 2π. As a result 2k of petals is drawn out of all armor bonuses.

When k is odd then k%2 is 1 and we add same number of armor bonuses to get twice the number of armor bonuses. When n reaches armor bonuses number it is divided by twice that number and result is almost 0.5 or π. As a result odd number of petals is drawn once (because of π) and it is made of all intended armor bonuses.
The code is HERE.

Later we will discuss not full draw when k is not integer.

Yours sincerely, [SDA]Mvice
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    ZDaemon Forum Index -> Wad Editing All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group