Spacing of fence posts with minimal distance to other fence posts Definition 1: A "fence" is a set of "fence post positions", where each pair of adjacent positions has the same difference (the spacing), e.g. $\{1,2, 3, 4\}$.
A fence is described by three values ($\in \mathbb{R}$): lower bound ($l$), upper bound ($u$) and spacing ($s$), with $l \leq u$ and $s > 0$.
$Fence(l,u,s)=\{x|x=l+n \cdot s, n \in \mathbb{N_0}, x \le u \}$
Definition  2: For two fences $X$ and $Y$, their distance $\Delta(X,Y)$ is the sum of all $|x-y|$ for each $x \in X$ (that is also $\in [Y_l,Y_u]$) and the closest corresponding $y \in Y$.
The problem: Three fences $A$, $B$ and $C$ are given. Find a value for $C_s$ that satisfies the following conditions:


*

*$C$ is the best approximation of both $A$ and $B$: $C_s$ minimizes $\Sigma\Delta = \Delta(A,C)+\Delta(B,C)$.

*$C_s$ is not smaller than the smallest possible spacing: $C_s \geq \mu$.

*If there are several solutions, then the spacing should be as large as possible (to minimize the number of fence posts).


For some special cases this is easy, e.g. $A_l = B_l = C_l \land A_s \bmod{B_s} = 0 \Rightarrow C_s = B_s$. But I am struggling to find a general solution and don't really know where to start.
Remarks: All values can be assumed to be multiples of $\mu$. This allows us to discretize the problem, so that all bounds are $\in \mathbb{Z}$ and all spacings $\in \mathbb{N}$. This somewhat simplifies the problem by making it possible to enumerate and compare all possible values for $C_s$. But due to its bad computational complexity, I want to avoid such a brute-force search algorithm. I'm looking for a a closed form expression (if it exists) or a better algorithm.
Application: In case you are wondering, I need to write an algorithm that combines two measurements of a spatial light sensor (goniophotometer) and I want the new scan grid to closely resemble the original ones in ordner to minimize interpolation and loss of information (e.g. local intensity peaks).
 A: I think I found a solution...
If we discretize the values, the problem does indeed become easier: Now, we know that there is always at least one perfect fit ($\Sigma\Delta=0$), namely $C_s=1$. Therefore, we do not really need to optimize for $\Sigma\Delta$, just find a better $C_s$ that is also a perfect fit.
This implies the following conditions:
(1) $C_s$ divides the other spacings: $C_s|A_s \land C_s|B_s $. If it did not, the frequency of $C$ would be wrong and $A$ and/or $B$ would occasionally "overshoot".
(2) If the lower bounds are not all equal, $C_s$ must divide the differences: 
$$ \delta_A=|A_l-C_l|, \ \ \ \delta_B=|B_l-C_l| $$
$$ C_s|\delta_A \land C_s|\delta_B $$
If it did not, it would be impossible to reach $C_l$ from $A_l$ and $B_l$, and vice versa.
(3) $C_s$ should be as large as possible.
Solution: This can be solved using the greatest common divisor ($gcd$):
$C_s^1 = gcd(A_s, B_s)$ satisfies (1) and (3).
$C_s^2 = gcd(\delta_A, \delta_B)$ satisfies (2) and (3).
$C_s = gcd(C_s^1, C_s^2)$ satisfies all conditions.
The $gcd$ can be calculated very quickly using the Euclidean algorithm.
