# BedLeveling X/Y computation incorrect for linear

Computation for px and py for Bedleveling is creating incorrect grid for ZProbe sampling.
Note: It is using incorrect LOOP index (using BOTH ix and iy for both X and Y computations, rather than ix for X, and iy for Y)

#elif BED_LEVELING_METHOD == 1 // linear regression
float delta = 1.0 / (BED_LEVELING_GRID_SIZE - 1);
float ox = EEPROM::zProbeX1();
float oy = EEPROM::zProbeY1();
float ax = delta * (EEPROM::zProbeX2() - EEPROM::zProbeX1());
float ay = delta * (EEPROM::zProbeY2() - EEPROM::zProbeY1());
float bx = delta * (EEPROM::zProbeX3() - EEPROM::zProbeX1());
float by = delta * (EEPROM::zProbeY3() - EEPROM::zProbeY1());
for (int ix = 0; ix < BED_LEVELING_GRID_SIZE; ix++) {
for (int iy = 0; iy < BED_LEVELING_GRID_SIZE; iy++) {
//float px = ox + static_cast<float>(ix) * ax + static_cast<float>(iy) * bx;
float px = ox + static_cast<float>(ix) * ax + static_cast<float>(ix) * bx;
//float py = oy + static_cast<float>(iy) * ay + static_cast<float>(ix) * by;
float py = oy + static_cast<float>(iy) * ay + static_cast<float>(iy) * by;

• No,
float px = ox + static_cast<float>(ix) * ax + static_cast<float>(iy) * bx;
float py = oy + static_cast<float>(ix) * ay + static_cast<float>(iy) * by;

is correct.
A = P2-P1
B = P3-P1

POS = P1 + ix * A + iy * B

is the equation spanning the measured parallelogram. And that is why ix and iy are required on all equations.
• Repetier said:
No,
float px = ox + static_cast<float>(ix) * ax + static_cast<float>(iy) * bx;
float py = oy + static_cast<float>(ix) * ay + static_cast<float>(iy) * by;

is correct.
A = P2-P1
B = P3-P1

POS = P1 + ix * A + iy * B

is the equation spanning the measured parallelogram. And that is why ix and iy are required on all equations.
Okay, and thank you for the explanation (though I don't know why I want to measure a parallelogram over a rectangular bed, but what do I know).

One more thing, if I may...

When adding the Point to the grid matrix, shouldn't the point (and corresponding h [height]) have the X and Y adjusted by the ZProbe offsets (since that is the X/Y coordinate where the Z measurement is actually being probed)?

In my case, my BLTouch ZProbe is (-8.93, -52.17) from the extruder.  If the Bed Leveling moves to (0,0), the PROBE is actually measuring the bed height at coordinate (8.93, 52.17) - isn't it?

I would argue, therefore, that when addPoint is storing the coordinates for computing the bed leveling matrix, it should be storing:
builder.addPoint(px - EEPROM::zProbeXOffset(), py - EEPROM::zProbeYOffset(), h);
• The probe is measuring where the extruder would be over the bed at given coordinates. So if extruder has offset 0/0 the probing will move extruder to 8.93/52.17 but it measures the height when extruder is active so that is correct. We assume here that it is the bed that is rotated and bumped and tool motion is linear.