Results 1 to 4 of 4
 07012010, 07:58 PM #1Member
 Join Date
 Jun 2010
 Posts
 4
 Rep Power
 0
A clever way of doing this ... (avoiding a LOT of ifelse statements)
Hi, currently my code looks like this:
Java Code:// Adjust x aim point if(xWind < 0.50) { offsetX = 1; } else if(xWind < 0.70) { offsetX = 1; } else if(xWind < 0.80) { offsetX = 2; } else if(xWind < 1.00) { offsetX = 5; } else { offsetX = 7; } // Adjust y aim point if(yWind < 0.50) { offsetY = 14; } else if(yWind < 0.70) { offsetY = 16; } else if(yWind < 0.80) { offsetY = 17; } else if(yWind < 1.00) { offsetY = 18; } else { offsetY = 19; }
Java Code:if(xWind < 0.50) { if(yWind < 0.50) { offsetX = 1; offsetY = 14; } else if(yWind < 0.70) { offsetX = 1; offsetY = 16; } else if(yWind < 0.80) { offsetX = 1; offsetY = 17; } else if(yWind < 1.00) { offsetX = 2; offsetY = 18; } else { offsetX = 2; offsetY = 19; } } else if(xWind < 0.70) { if(yWind < 0.50) { offsetX = 1; offsetY = 14; } else if(yWind < 0.70) { offsetX = 2; offsetY = 17; } // and so on...

The best way is to use a mathematical formula for calcuating x and y offsets based on the input. How that's done, I have no idea based on what you've told us. Perhaps you can tell us how these numbers are calculated?
 07012010, 08:35 PM #3Member
 Join Date
 Jun 2010
 Posts
 4
 Rep Power
 0
Ok thanks. I think the formula is hard to figure out manually, so I guess I'll have to collect as much data as possible so I can use a curve fitting tool to find polynomials that match the data (nonlinear regression I guess).
 07012010, 08:39 PM #4
 Join Date
 Sep 2008
 Location
 Voorschoten, the Netherlands
 Posts
 13,942
 Blog Entries
 7
 Rep Power
 22
You can do without that long sequence of nested ifelse statements but you have to supply the actual data in a couple of matrixes (or, as Fubarable suggested: find a functional depenceny fx(x, y) and fy(x, y) where both fx and fy are the wanted offsets).
Else a few data matrixes and a bit of code are a solution:
Java Code:double winds[][] = // you have to supply the data here. double[] windx[] = // you have to supply the data here. int offsetsX[][] = // again, you supply the data here. int offsetsY[][] = // again, you supply the data here. for (int x= 0; x < windx.length; x++) if (windx[x] >= actualX) for (int y= 0; y < winds[x].length; y++) if (winds[x][y] >= actualY) // found a value for actualX and actualY: offsetsX[x][y] and offsetsY[x][y] are the answer ...
JosLast edited by JosAH; 07012010 at 08:42 PM.
Similar Threads

avoiding memory overconsuming
By itaipee in forum New To JavaReplies: 4Last Post: 12142009, 12:59 PM 
Avoiding system.exit()
By swati.jyoti in forum New To JavaReplies: 5Last Post: 07012009, 10:17 AM 
Avoiding refresh
By java_srinivasan in forum JavaServer Pages (JSP) and JSTLReplies: 0Last Post: 06252008, 09:01 AM 
avoiding if statements
By valoyivd in forum New To JavaReplies: 1Last Post: 04022008, 09:08 AM
Bookmarks