guenseli Posted September 9, 2012 Report Posted September 9, 2012 Hello Pete, as I'm not the big mathematician, I hope you could help me a bit: I have a LUA script assigned to an axis. Working so far. But I want the axis now the other way round: var = round((ipcPARAM+16384)/32768*100) Now, var is 100 at 16384 and I want var to be zero at 16384 and 100 at -16834 ("round" is a selfmade function for roundings as you surely assume) There must be somewhere a -1 inserted, could you point me please to the right direction? many thanks! Günter
Gypsy Baron Posted September 9, 2012 Report Posted September 9, 2012 Günter, Just off the top of my head, how about this: Rev_Axis = abs(var - 100) Just subtract 100 from the 0 to 100 "var" and then take the absolute value. or using your equation above: var = abs(round((ipcPARAM+16384)/32768*100) - 100) Paul
Pete Dowson Posted September 9, 2012 Report Posted September 9, 2012 var = round((ipcPARAM+16384)/32768*100) Now, var is 100 at 16384 and I want var to be zero at 16384 and 100 at -16834 If that's the case it would be clearer written as var = ((ipcPARAM+16384) * 100)/32768 because it is ambiguous the way you have it -- whether the multiplication is done before the division, as would probably be assumed in normal everyday notation. ("round" is a selfmade function for roundings as you surely assume) If you are writing "var" back as an integer it will be rounded down to the nearest integer in any case. To round up or down to the nearest, just add 0.5 first. i.e. var = 0.5 + (((ipcPARAM + 16384) * 100) / 32768) Finally, assuming ipcPARAM is running from 0 to 16384, as you are implying, to reverse it all you need to do is subtract it from 16384, so: var = 0.5 + ((((16384 - ipcPARAM) + 16384) * 100) / 32768) Pete
guenseli Posted September 9, 2012 Author Report Posted September 9, 2012 Many thanks Pete, outstanding service as always!!! Substracting from 16384 was the magic trick :) "If you are writing "var" back as an unteger it will be rounded down to the nearest integer in any case. To round up or down to the nearest, just add 0.5 first. i.e." Ah, ok will try that. Looks like a lot better then my "trick" many thanks and many greetings! Günter
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now