Thread Tools Display Modes
09-07-12, 01:34 PM   #1
myrroddin
A Pyroguard Emberseer
 
myrroddin's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 1,246
math logic bomb

I am working with random numbers, with the intent to attach them to a frame that moves. Never mind the code issues of moving the frame, I am struggling with the math. The average of all the numbers is what moves the pointer frame. So far so good.

The trouble is the end number has to be between 1 and 21, inclusive. Here is a hard-coded example.
Lua Code:
  1. local pointer = 97846.7851 -- this would actually be random
  2. if pointer < 0 then
  3.     pointer = pointer * -1 -- can't have neg numbers because frames are numbered in the positive
  4. end
  5. pointer = mod(pointer, 21) -- this won't work, because 0 is a possibility
  6. pointer = round() -- local function that rounds better than floor or ceil
  7. -- attach pointer to frame
Is it possible to do something like the following? I've tried Googling for a hint, but haven't found anything. Also, I'm not sure if mod(pointer, 21) is correct either.
Lua Code:
  1. pointer = mod(pointer, 21) > 0
  Reply With Quote
09-07-12, 01:47 PM   #2
Haleth
This Space For Rent
 
Haleth's Avatar
Featured
Join Date: Sep 2008
Posts: 1,173
You can't have a mathematically correct average of a set of numbers if you're going to limit the average below the highest number of the set.

Why don't you limit your random numbers (e.g. random(21)) then divide the end result by the amount of numbers?

Last edited by Haleth : 09-07-12 at 01:51 PM.
  Reply With Quote
09-07-12, 02:22 PM   #3
myrroddin
A Pyroguard Emberseer
 
myrroddin's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 1,246
The random numbers aren't generated from math.random. They are the average of all the mana deltas within x amount of time. For example, say you gain or lose the following amount of mana:
  • 100
  • -500
  • 450
  • 800
Which sums up to 850. The average is 212.5. I need to convert 212.5 into a spread from 1 to 21 plot points. Because there is no way to determine ahead of time mana deltas, I have to add them as I get them, then average them.
  Reply With Quote
09-07-12, 02:38 PM   #4
Dridzt
A Pyroguard Emberseer
 
Dridzt's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2005
Posts: 1,362
Is it a sliding window that always contains 21 datapoints?
(ie starts plotting when you have at least 21 datapoints and from that point on displays the last 21)
  Reply With Quote
09-07-12, 02:56 PM   #5
myrroddin
A Pyroguard Emberseer
 
myrroddin's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 1,246
If I understand you correctly, then yes, sort of. Think of the PvP capture bar, where it swings between Horde and Alliance. The vertical slider is my plot point, and moves the slider based on the mana returns. Obviously, a mana delta value measured in hundreds, or thousands, isn't any good; the graph would have to be huge, which is why I am making it 21 segments. The main frame behind has a width of 210, so breaking it up into 21 chunks makes setting a width of each segment easy.

That is why I am trying to figure out the math to convert the average deltas into somewhere on a 21 segment frame. I have the average, deltas, frame segments, all that built. It is just the math that converts I am having a challenge with.

Does that make more sense? Oh, in fact, I AM using the PvP capture bar texture.
  Reply With Quote
09-07-12, 03:50 PM   #6
Dridzt
A Pyroguard Emberseer
 
Dridzt's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2005
Posts: 1,362
Actually the math would be simple if I could understand what the bar represents.
I'm not sure you have decided that yet yourself

I mean ok it's 21 segments, let's say 10 'negative' segments (losing mana) 1 'zero' segment (not losing or gaining), 10 'positive' segments (gaining mana)
|----------|-|----------|

What amount does the total width of the bar represent (splitting it in 21 segments aside, there must be something to divide to 21 parts)
What is a meaningful number for the user to be at the left end of the bar (highest rate of losing mana) to the right end of the bar (highest rate of gaining mana)?

Edit: What I posted above should get you an average MPS over 21 seconds if your deltas are 1/sec.
There's no way to place -215 MPS (or +450 MPS) on a bar if you can't know what's the range of the bar,
that's not a math problem it's a logic problem.
Tell me what the full range of the bar corresponds to and I can help with the rest.

Last edited by Dridzt : 09-07-12 at 03:55 PM.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » math logic bomb


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off