Thread Tools Display Modes
02-11-14, 12:11 PM   #1
Duugu
Premium Member
 
Duugu's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2006
Posts: 851
I need an idea, approach or algorithm to solve a development issue

I'm stuck on a developing issue and desperately looking for some help or ideas.

The setup:
  • I have an array of x degree-values (each of them has a value between 0 and 360).
  • My goal is to 'normalize' each of the values using its two neighbors. To get more 'smoothe' degree values.

Don't know if this is clear to everyone. I can't explain it better. :/ So here's an

Example:

Let's say an array is
Lua Code:
  1. degrees = {
  2. [1] = 39,
  3. [2] = 25,
  4. [3] = 18,
  5. [4] = 6,
  6. [5] = 353,
  7. [6] = 320,
  8. [7] = 333,
  9. [8] = 342,
  10. [9] = 338,
  11. [10] = 318,
  12. [11] = 350,
  13. [12] = 359,
  14. [13] = 340,
  15. [14] = 329,
  16. [15] = 320,
  17. [16] = 313
  18. }

I'm starting my 'normalization' with the second value ([2]). (The first one is my reference and is not modified.)
Lua Code:
  1. [1] = 38,
  2. [2] = 25,
  3. [3] = 18,

I'm calculating a new 'normalized' value for [2] using the value of [1] and [3]:
38 - 18 / 2 = 10
38 - 10 = 28
So the normalized value of [2] is 28

Now I'm doing the same with the remaining values.

That means, the next step would be to normalize value [3]
Lua Code:
  1. [2] = 25,
  2. [3] = 18,
  3. [4] = 6,
which is
25 - 6 / 2 = 9.5
25 – 9.5 = 15.5
Normalized value of [3] = 15.5

(To be accurate: the value of [2] would be 28 and not 25 as it was normalized it in the previous step. But to keep the example as simple as possible I'm using the original value.)

Works nice so far. But now it's starting to get dirty. The next value is
Lua Code:
  1. [3] = 18,
  2. [4] = 6,
  3. [5] = 353,

So I'll have to consider the 0 threshold with this one.
18 + (360 - 353) / 2 = 12.5
18 - 12.5 = 5.5

And the next value makes it really worse:
Lua Code:
  1. [4] = 6,
  2. [5] = 353,
  3. [6] = 320,
Which translates into
6 + (360 - 320) / 2 = 23
360 + (6 – 23) = 343


The Problem

The degree values could be in any order/sequence. The array could be reversed for example. The values could be decreasing, then increasing and decreasing again. They could pass the 0 threshold never, once or multiple times. :/

I just can't imagine a way or an algorithm to do what I want. I really would appreciate any idea, hint, or approach that helps me solve this development issue.

How would you do it?

btw: Thanks a lot for reading all the way down to this.

Last edited by Duugu : 02-11-14 at 12:21 PM.
  Reply With Quote
02-11-14, 01:01 PM   #2
Malsomnus
A Cobalt Mageweaver
AddOn Author - Click to view addons
Join Date: Apr 2013
Posts: 203
I don't understand why you use this algorithm.
Averaging the two neighboring numbers - fine.
Substracting the result from the current number - wtf?
__________________
SanityCheck - If you've ever said the words "Sorry, I forgot" then you need this add-on.

Remember, every time you post a comment on an add-on, a kitten gets its wings!
  Reply With Quote
02-11-14, 01:18 PM   #3
Duugu
Premium Member
 
Duugu's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2006
Posts: 851
Hm. My goal is to get more "smoothe" degree values.

Lets say an ideal set of values would be:
10 , 20 , 30 , 40 , 50 , 40 , 30 , 20 , 10

A real world set of values I have to deal with is:
10 , 20 , 40 , 50 , 40 , 30 , 20 , 10

Now I'm trying to 'smoothe' or 'flatten' the second one. To get something like
10 , 25 , 40 , 50 , 40 , 30 , 20 , 10

Last edited by Duugu : 02-11-14 at 01:21 PM.
  Reply With Quote
02-11-14, 01:26 PM   #4
elcius
A Cliff Giant
AddOn Author - Click to view addons
Join Date: Sep 2011
Posts: 75
Lua Code:
  1. local a = {38,25,18,6,353,320,333,342,338}
  2. for i = 2,#a-1 do
  3.     a[i] = ((a[i-1]+a[i+1])/2+(abs(a[i-1]-a[i+1])>180 and 180 or 0))%360
  4. end
?
  Reply With Quote
02-11-14, 01:28 PM   #5
Resike
A Pyroguard Emberseer
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 1,290
Like this?

Lua Code:
  1. for i = 2, #degrees - 1 do
  2.     degrees[i] = (degrees[i - 1] + degrees[i + 1]) / 2
  3. end
  Reply With Quote
02-11-14, 01:45 PM   #6
Malsomnus
A Cobalt Mageweaver
AddOn Author - Click to view addons
Join Date: Apr 2013
Posts: 203
What I'd do is a weighted average of each number with its 2 closest neighbours. Preferably put the whole thing into a brand new array so that you actually work with the original numbers
__________________
SanityCheck - If you've ever said the words "Sorry, I forgot" then you need this add-on.

Remember, every time you post a comment on an add-on, a kitten gets its wings!
  Reply With Quote
02-11-14, 01:52 PM   #7
Duugu
Premium Member
 
Duugu's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2006
Posts: 851
Originally Posted by elcius View Post
What I'd do is a weighted average of each number with its 2 closest neighbours. Preferably put the whole thing into a brand new array so that you actually work with the original numbers
:O
Thank you elcius.

I'm still trying to understand what exactly you're doing with this. ;D

I'll report back in a few minutes.

Last edited by Duugu : 02-11-14 at 03:10 PM.
  Reply With Quote
02-11-14, 02:05 PM   #8
Nimhfree
A Frostmaul Preserver
AddOn Author - Click to view addons
Join Date: Aug 2006
Posts: 267
I don't understand the problem the OP is having. Basically my understanding is from a group of three degree values, take the middle one and replace it with the average of the two outer ones. The math is easy, and if the resulting value < 360 just add 360 to it. However, this math does not take into account the original value of the middle number. So, with an array like:

10, 80, 20, 95, 30, 160, 40

you would get an array of:

10, 15, 55, 42.5, 101.25, 70.625, 40

(assuming the end value of 40 does not change, like the first value does not change).

I have no idea what this is supposed to be for, but I think it is not the proper solution based on the fact that the OP says the numbers can come in any order, etc.
  Reply With Quote

WoWInterface » Developer Discussions » General Authoring Discussion » I need an idea, approach or algorithm to solve an development issue


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