Okay! I will now walk through the solution using the equation presented in the book mentioned rather than use taylor series approximation. First, I will identify what the specific type of distortion you are probably dealing with looks like.
~
When you project a square on the wall your projection probably looks like ") (" when you really want "| |" where the second geometrically fits inside the first and is tangent at the min and max X values when y=0
~
The equations from the book are y = d tanθy and x = (d / cosθy + e) * tanθx
~
Briefly, as long as you see no curvature along a horizontal line, your y value stays the same. Meanwhile, your X value when y=0 is correct but is flung increasingly further from the center as the magnitude of y increases.
~
What we want to do is calculate our X values such that with the distortion, the X value will be the value we intended. Since the distortion always adds to the X value, we can reason that as the magnitude of Y increases, the magnitude of our corrected X must decrease in order to reach our intended X coordinate. So there is a straightforward way to accomplish this which is using the X formula above to compute your desired tanθx (and consequently your new X value) by plugging in you desired Xvalue on the left side of the equation. We expect the computed tanθx value to be less than original tanθx.
~
Say you want to get to the top right corner of your projection region with a 16-bit projector with a ±30 degree FOV. The distortion actually causes your X to go farther than 30 degrees out from center...
~
Step 1) Compute θy using ratios. So if your projector FOV is 30 degrees and with 16 bits your max coordinate is ~32768
θy = y-coordinate / max-y-coordinate * max-y-angle or in this case 32768 / 32768 * 30 = 30. An important note is that with value 0, your max positive value is actually 32767. Add 1 to any y >= 0 value to prevent undesired consequences.
~
Step 2) if you know or can find your physical d and e values use them. Otherwise, use e=0 and for d use max-y-coordinate / tan(max-y-angle) or in this case that would be 32768 / tan(30) = 56755.84... Note that if you use your own d and e then you have to worry about units but will get a more precise result if you were able to obtain precise measurements.
~
Step 3) Compute tanθx = x-desired / (d / cosθy + e) or in this example 32768 / (56755.84 / cos(30) + 0) = 0.5
Note that the angle θx is the inverse tangent of 0.5 which is approximately 26.57 degrees
~
Step 4) Compute the X value you need to use to get x-desired. I use the angle to max value ratio like in step 1) so x-needed = θx / max-x-angle * max-x-coordinate or in this case 26.57 / 30 * 32768 = 29016.
~
So if you use the point (29016, 32767) your laser beam will go to the top right corner of your projection region.
~
Hope this helps! As I said I will try to post code later this week but I tried this and it worked very well. I am attempting to attach pictures but we will see if it works.