views:

491

answers:

3

I have two shapes which are cross sections of a channel. I want to calculate the cross section of an intermediate point between the two defined points. What's the simplest (relatively simple?) algorithm to use in this situation?

P.S.: I came across several algorithms like natural neighbor and poisson, which seemed complex. I'm looking for a simple solution, which could be implemented quickly.

EDIT: I removed the word "Simplest" from the title since it might be misleading

+2  A: 

This is simple:

  1. On each cross section draw N points at evenly spaced intervals along the boundary of the cross-section.
  2. Draw straight lines from the n-th point on cross-section 1 to the n-th point on cross-section 2.
  3. Take off your new cross-section at the desired distance between the old cross-sections.

Simpler still:

  1. Use one of the existing cross-sections without modification.

This second suggestion might be too simple I suppose, but I bet no-one suggests a simpler one !

EDIT following OP's comment: (too much for a re-comment)

Well, you did ask for a simple method ! I'm not sure I see the same problem with the first method as you do. If the cross sections are not too weird (probably best if they are convex polygons) and you don't do anything strange such as map the left side of one cross-section to the right side of the other (thereby forcing lots of crossing lines) then the method should produce some kind of sensible cross section. In the case you suggest of a triangle and a rectangle, suppose the triangle is sitting on its base, one vertex at the top. Map that point to, say, the top left corner of the rectangle, then proceed in the same direction (clockwise or anti-clockwise) around the boundaries of both cross-sections joining corresponding points. I don't see any crossing lines, and I see a well-defined shape at any distance between the two cross-sections.

High Performance Mark
The second one is definitely too simple :)The first algorithm is dependent on the perimeter of the shapes and would fail in certain cases s.a. morphing from a rectangle to a triangle. The points on the two cross sections would not overlap properly
Gayan
Got it. I'd misunderstood the first method when making the previous comment. Thanks.
Gayan
+1--the first solution seems like the right one. Note that having evenly spaced intervals is unnecessary (and, in general, impossible); you just need to pick a corresponding point on both (e.g. top center) and then go around both shapes, adding vertices wherever the other is missing one. For example, a rectangle 1x2 rectangle might have vertices at 1/6, 2/6, 4/6, and 5/6 of the way around; an equilateral triangle might have them at 1/3=2/6 and 2/3=4/6, so it needs new vertices at 1/6 and 5/6 of the way around (i.e. the midpoint of the first and last side).
Rex Kerr
@Rex -- who said anything about the cross-sections having vertices ? If the boundary of the cross-section is a continuous and closed line then one could certainly measure along its length and set out N evenly spaced points.
High Performance Mark
@HPM: if it doesn't have vertices, one can certainly approximate the smooth curve with a N-ary polygon with sides of equal length, I agree.
Rex Kerr
I came across a problem when analyzing this solution. Given that there are certain points on the cross sections which define the profile, how can we make sure that these points would be considered when taking our N points? (could be done by taking the ratio of the distances between two newly defined points and our "major" point and adding a point to the other cross section, but is there a simpler way?)
Gayan
+1  A: 

Note there are some ambiguities about High Performance Mark's answers you will probably need to address and will define the quality of the output of his method. The most important one is, when you draw the n points on both cross-sections, what sort of correspondence do you determine between them, that is if you do it that way High Performance Mark suggested, then the order of labeling the points becomes important.

I suggest rotating (orthogonal) plane simultaneously through both cross sections, then the set of points which intersect that plane on one cross section just need to be matched to the set of points that intersect that plane on the other cross section. Hypothetically, there is no limit on the number of points in these sets, but it certainly reduces the complexity of the correspondence problem in the original situation.

ldog
+1  A: 

Here is another try at the problem, which I think is a much better attempt.

Given the two cross-sections C_1, C_2

Place each C_i into a global reference frame with coordinate system (x,y) so that the way they are relatively situated makes sense. Split each C_i into an upper and lower curve U_i and L_i. The idea is going to be that you will want to continuously deform curve U_1 to U_2 and L_1 to L_2. (Note you can extend this method to split each C_i into m curves if you wish.)

The way to do this is as follows. For each T_i = U_i, or L_i sample n points, and determine the interpolating polynomial P{T_i}(x). As some one duly noted below, interpolating polynomials are susceptible to oscillation especially at the endpoints. Instead of the interpolating polynomial, one may instead use the least squares fit polynomial which would be much more robust. Then define the deformation of the polynomial P{U_1}(x) = a_0 + a_1 * x + ... + a_n * x^n to P{U_2}(x) = b_0 + b_1 * x + ... + b_n * x^n as Q{P{U_1},P{U_2}}(x, t) = ( t * a_0 + (1 - t ) b_0 ) + ... + (t * a_n + (1-t) * b_n ) * x^n where the deformation Q is defined over 0<=t<=1 where t defines at which point the deformation is at (i.e. at t=0 we are at U_2 and at t=1 we are at U_1 and at every other t we are at some continuous deformation of the two.) The exact same follows for Q{P{L_1},P{L_2}}(x, t). These two deformations construct you a continuous representation between the two cross-sections which you can sample at any t.

Note all this is really doing is linearly interpolation the coefficients of the interpolation polynomials of the two pieces of both cross-sections. Note also when spliting the cross-sections you should probably put the constraint that they must be split at end points that match up otherwise you may have "holes" in your deformation.

I hope thats clear.

edit: addressed the issue of oscillation in interpolating polynomials.

ldog
Interpolating polynomials are _very_ susceptible to oscillation for high n -- see http://en.wikipedia.org/wiki/Runge%27s_phenomenon
Martin B
yes that is correct, however if you split up your cross sections into enough sub-curves, *I think* you basically get spline interpolation (if you pick n=3). However, how many sub-curves you want to split up into I think is the key point, as it will determine the oscillation.
ldog
Much better, but simple ?
High Performance Mark
heh, I guess thats a matter of opinion :P
ldog
More complex than HPM's answer. This would not be suitable for my current purpose (which is an initial prototype of the system) but I'd definitely consider it for the actual production system.
Gayan