0

ポイント間のメッシュを補間しようとしています。私はいくつかの調査を行い、いくつかの解決策を見つけましたが、それらはすべて私にとって奇妙な結果をもたらします. Cosinus 補間と Cubic 補間を試しましたが、メッシュ全体が滑らかではなく小さな波になってしまいました。

私はこれを試しました

 mu2 = mu*mu;
   a0 = y3 - y2 - y0 + y1;
   a1 = y0 - y1 - a0;
   a2 = y2 - y0;
   a3 = y1;

   return(a0*mu*mu2+a1*mu2+a2*mu+a3);

ここから: http://paulbourke.net/miscellaneous/interpolation/

必要なすべてのポイントを取得し、すべてが機能するはずですが、そうではありません。私はそれをデバッグするのに多くの時間を費やしましたが、問題であることがわかった唯一のことは、mu(補間で0.0から1.0までの通常のt)がP1で0.0から始まるように見えることですが、1.0ではP3にあります。 P2(ポイントP0、P1、P2、P3、P1とP2の間で補間が発生する必要があります)にある必要があります

2 点間を補間する簡単な方法が他にある場合は、お知らせください。コントロールポイントでベジエ曲線などをしたくありません。上の例のように、ポイントが 2 つしかないので、両側にもう 1 つのポイントを使用できます。

助けてくれてありがとう ルーク

4

1 に答える 1

1

Catmull-Rom スプラインがデータに適しているようです。

VB.NET で実装する例として:

Module Module1

    ''' <summary>
    ''' A class for a 2-D point and operations on it.
    ''' </summary>
    Class PointD
        Property X As Double
        Property Y As Double

        Public Shared Operator +(p1 As PointD, p2 As PointD) As PointD
            Return New PointD(p1.X + p2.X, p1.Y + p2.Y)
        End Operator

        Public Shared Operator -(p As PointD) As PointD
            Return New PointD(-p.X, -p.Y)
        End Operator

        Public Shared Operator -(p1 As PointD, p2 As PointD) As PointD
            Return New PointD(p1.X - p2.X, p1.Y - p2.Y)
        End Operator

        Public Shared Operator *(a As Double, p As PointD) As PointD
            Return New PointD(a * p.X, a * p.Y)
        End Operator

        Public Shared Operator *(p As PointD, a As Double) As PointD
            Return New PointD(a * p.X, a * p.Y)
        End Operator

        'TODO: (Optional) Add methods for magnitude, cross product and dot product.

        Public Sub New()
            ' empty contructor
        End Sub

        Public Sub New(x As Double, y As Double)
            Me.X = x
            Me.Y = y
        End Sub

        Public Overrides Function ToString() As String
            ' use the N3 format string for tidiness in this example
            Return $"({X:N3}, {Y:N3})"
        End Function

    End Class

    ''' <summary>
    ''' Ordinary Catmull-Rom interpolation.
    ''' </summary>
    ''' <param name="t">Vary from 0.0 to 1.0 to get an interpolated point between data points p1 and p2.</param>
    ''' <param name="p0">The first control point.</param>
    ''' <param name="p1">The first data point.</param>
    ''' <param name="p2">The second data point.</param>
    ''' <param name="p3">The second control point.</param>
    ''' <returns>The interpolated point.</returns>
    Function CatmullRomInterpolate(t As Double, p0 As PointD, p1 As PointD, p2 As PointD, p3 As PointD) As PointD
        ' this is the regular Catmull-Rom spline
        ' other ways of treating it can be found at:
        ' https://stackoverflow.com/questions/9489736/catmull-rom-curve-with-no-cusps-And-no-self-intersections
        Return 0.5 * ((2 * p1) +
            t * (p2 - p0) +
            Math.Pow(t, 2) * (2 * p0 - 5 * p1 + 4 * p2 - p3) +
            Math.Pow(t, 3) * (3 * (p1 - p2) + p3 - p0))

    End Function


    Sub Main()
        ' some sample data which will produce a symmetrical wave shape...
        Dim p0 As New PointD(-1, 1)
        Dim p1 As New PointD(0, 0)
        Dim p2 As New PointD(1, 0)
        Dim p3 As New PointD(2, -1)

        For t = 0.0 To 1.0 Step 0.1
            Console.WriteLine(CatmullRomInterpolate(t, p0, p1, p2, p3))
        Next

        Console.ReadLine()

    End Sub

End Module

必要なものによっては、カスプや自己交差のない Catmull-rom 曲線が役立つ場合があります。

于 2016-09-01T19:31:38.950 に答える