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:
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:
I'm starting my 'normalization' with the second value ([2]). (The first one is my reference and is not modified.) Lua Code:
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:
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:
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:
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. :) |
I don't understand why you use this algorithm.
Averaging the two neighboring numbers - fine. Substracting the result from the current number - wtf? |
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 |
Lua Code:
|
Like this?
Lua Code:
|
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 :p
|
Quote:
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. :) |
Now that the raid is over, I'll try to write a piece of code for this :p
|
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. |
I assumed that averaging would be easy despite the fact we're talking about degrees. I was wrong. Going to have to work on it a bit more :p
|
Is this a curve fitting problem or am I misunderstanding what you're trying to do?
|
I think OP needs to describe the end result they're looking to achieve, rather than just the means they're trying to use to achieve it... the only thing I can think of is trying to evenly space minimap buttons, but nobody uses those things anymore, so it must be something else...
|
Quote:
I have some frames that are lined up on a curve and that are rotated according to their position. In some cases the calculated rotation angle does not perfectly fit. And I'm trying to fix this. Button 5 (starting from the left) needs one degree more, button 6 one less. I know it's hard to see. It is getting more visible in action if the curve knots are moving. But I don't have the time to make a video of it. :) |
This was bloody annoying to do... I shouldn't have neglected my math studies... but this seems to work, generally speaking, even though it's not perfect mathematically, and the code is a bit ugly as well.
Lua Code:
You can play around with the weights, naturally, and I suspect that changing the order of those smoothing lines would change the outcome in a way that would make a mathematician cringe :D [Edit] A mathematician, or someone who takes their computer graphics seriously, would have done it with vectors :( |
Thank you Elcius and Malsomnus for the code (mixed you up below, sorry :/) and to everyone else to pointing me into the right direction. That was exactly what I was looking for.
I was so locked into my approach that it just did not came to my mind that taking the average is the solution. Don't ask. Can't believe it myself. :) That was one of those situations where I lost the ability to think after unsuccessfully trying to solve a problem for hours. |
Quote:
Quote:
|
Quote:
Actually it does not exactly the same as it doesn't takes the 0/360 degree threshold into account. |
Quote:
|
Quote:
|
Lets say the values are 14, 6, 340
The intented result for the second value would be 357. Using Resike's code Lua Code:
(14 + 340) / 2 = 177 |
All times are GMT -6. The time now is 02:21 AM. |
vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI