0

Please bear with me, this is my first question here and I hope it fits and is understandable.

I want to construct a "curved" grid on the screen in a computer program.

Visualization of the curved grid

The grid shall consist of a parametric x-/y-baseline curve, perpendiculars to that curve in regular arc length intervals, and then curves which are "parallel" to the baseline and again orthogonal to the perpendiculars.

We shall not consider the case that any of the perpendiculars intersect with each other. This is ensured not to happen by preconditions.

The baseline (bottom-most green curve in the picture):

The user interactively defines $N$ points $\mathbf{P}_i = (x_i, y_i)$ with $i = 1, ..., N$ (marked with small squares in the image above).
With these, I perform natural cubic spline interpolation to determine two splines $x(t)$ and $y(t)$, and subsequently the parameterized baseline curve $\mathbf{B}(t) = (x(t), y(t))$ with real-valued $t \in [0, N]$. The boundary conditions of the interpolations are chosen such that the 2nd derivatives vanish at $t=0$ and $t=n$.
$t$ and $\mathbf{B}(t)$ are defined such that $\mathbf{B}(t=0) = \mathbf{P}_0, \mathbf{B}(t = 1) = \mathbf{P}_1$, etc.

The perpendiculars:

Next, I calculate line segments which are perpendicular to the $\mathbf{B}(t)$ curve at regular arc length intervals $l$. For this, I start at $t_0 = 0$ and find $t_{i+1} = t_i + \Delta t_i$, as long as $t_{i+1} \le N$, such that: $$l = \int\limits_{t_i}^{t_{i+1}} \sqrt { \left( \frac{dx}{dt} \right)^2 + \left( \frac{dy}{dt} \right)^2 } dt $$

Calculation of the integral is done numerically, and I solve for $\Delta t_i$ using a Newton iteration with a bisection method as fallback (sometimes my initial guess is too bad and Newton does not converge).

Eventually, this leads to $M$ values $t_0, t_1, ..., t_M$, for which I have $\mathbf{B}(t_i)$ as the starting point of the perpendicular line, $\mathbf{B}'(t_i) := \left( \frac{dx}{dt}(t_i), \frac{dy}{dt} (t_i) \right)$ as the slope, and thus $ \left( -\frac{dy}{dt}(t_i), \frac{dx}{dt}(t_i) \right) $ as a direction vector for the $i$-th perpendicular.
The length of each perpendicular line is just some constant $c$.

The curved gridlines:

Finally, I construct "parallel" curves to the baseline by interpolating between matching points on the perpendiculars.
I.e. choose any constant $\tau \in [0, 1]$ and for each perpendicular line $\mathbf{L}_i$ with start point $\mathbf{a}_i$ and end point $\mathbf{b}_i$, let $\mathbf{c}_i(\tau) = \mathbf{a}_i + \tau \cdot (\mathbf{b}_i - \mathbf{a}_i)$.

For the sake of simplicity, consider only one such curve with $\tau := 1$ so that $\mathbf{c}_i(\tau) = \mathbf{b}_i$ with $i = 0, ..., M$ identifies the end point of each perpendicular line.

The associated curved gridline is then found by again performing cubic spline interpolations for the $x$- and $y$-components. Let's call this curve $\mathbf{C}(s) := \left( c_x(s), c_y(s) \right)$ with $s \in [0, M]$. Thus, for $s_0 = 0, s_1 = 1, ..., s_M = M$ it follows that $\mathbf{C}(s_i) = \mathbf{b}_i$ identifies the intersections between the curve $\mathbf{C}$ and the perpendicular lines $\mathbf{L}_i$.

The problem:
While the perpendicular lines $\mathbf{L}_i$, by construction, are orthogonal to the baseline $\mathbf{B}(t)$, they are in general not orthogonal to the curved gridlines $\mathbf{C}(s)$.

Initially, my idea was to use a slope-based spline interpolation (Hermite) for $\mathbf{C}(s)$ such that at $s_0, s_1, ...$ not only the points $\mathbf{C}(s_i) = \mathbf{b}_i$ are prescribed, but also the first derivatives which follow from the slope of the perpendicular line $\mathbf{L}_i$. But the slope/perpendiculars only provide me with a $\frac{dx}{dy}$ relation, where as the curve $\mathbf{C}(s) := \left( c_x(s), c_y(s) \right)$ is evidently a function in $s$.

At the baseline $\mathbf{B}(t)$, I do know the derivatives $\frac{dx}{dt}$ and $\frac{dy}{dt}$ at each point $t$, but since I do not know the relation between the curve parameters $s$ and $t$, I cannot infer $dc_x/ds$ or $dc_y/ds$.

What can I do?

  • Once you have parameterized the baseline, the levelset (your gridline) can be computed at many more points instead of just your initial points for interpolation. Maybe I misunderstood your problem? – Yimin Nov 24 '23 at 00:56
  • @Yimin please notice that the baseline curve B(t) only represents the bottom-most curve in the sketch. Visually speaking, the parameter t just follows the bottom curve from left to right. – dheller Nov 24 '23 at 05:48

2 Answers2

0

I have found some references leading me to the conclusion that my whole approach was not useful.

It seems what I must do in essence is to find Parallel curves to my baseline, and to draw them on the screen (as Bézier curves), for which there are algorithms available. So please ignore the section "The curved gridlines:" of my original post.

0

Your ideas seem fine, to me. Your algorithm for constructing the $C$ curves just needs to be tweaked a little. When you construct a specific $C$ curve, you want it to pass through certain points on the $L$ lines, and you want it to be perpendicular to each of these lines. So, you have a sequence of points and tangent directions that define the $C$ curve you’re constructing. So, constructing the $C$ curve is a fairly simple Hermite interpolation problem. Or, saying it another way, between each two $L$ lines, your $C$ curve will be a Bézier curve whose end-points and end tangent directions are known to you. In Bézier terms, you just need to know how long the first and third legs of the control polygon need to be. This isn’t a huge hurdle — just choose some reasonable lengths. The easiest approach is to use a length equal to one-third of the distance between the Bézier curve’s end-points. Or, use the control polygon leg lengths dictated by the Tiller-Hanson algorithm.

The $C$ curves constructed this way will not be exactly “parallel” to each other, but they’ll be close. If you want exact parallelism, you have a much harder problem. Look up “offsets of Bézier curves” on this site and elsewhere. Like here.

bubba
  • 43,483
  • 3
  • 61
  • 122