2016-08-27 7 views
0

ポイント間のメッシュ内で補間しようとしています。私はいくつかの研究を行い、いくつかのソリューションを見つけましたが、それらのすべてが私のために奇妙な結果を生み出します。私はCosinusとCubicの補間を試みましたが、全体のメッシュは滑らかではなく小さな波を得ます。2点間の滑らかな補間

私はここからこの

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/

私は私が必要とするすべてのポイントを持って、すべてが動作するはずですが、それはイマイチ。私はそれをデバッグするのに多くの時間を費やしましたが、私が問題であることが分かったのは、μで補間された0.0〜1.0の正規のtがP1で0.0で始まるようですが、1.0ではP3にあり、 (P1とP2の間で補間が行われるポイントP0、P1、P2、P3)

2点間の補間方法が他にもある場合は、教えてください。私はベジェ曲線や何かをコントロールポイントでやってみたいです。私はちょうど2つのポイントを持っており、私は上記の例のように各側に1つ以上のポイントを使用することができます。任意の助け

おかげで ルーク

+1

[Catmull-Rom spline](http://www.mvps.org/directx/articles/catmull/)を使用すると思われます。 –

+0

あなたの魅力のように働いてくれてありがとう、ありがとう。もし私ができるなら、これを正解と記しておきます。 – CosmicSeizure

答えて

1

キャットマル-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 curve with no cusps and no self-intersectionsが役立つかもしれません。

関連する問題