캣멀롬 스플라인

testwiki
둘러보기로 이동 검색으로 이동

틀:위키데이터 속성 추적 캣멀롬 스플라인컴퓨터 그래픽스 용어로, 에드윈 캣멀과 Raphael Rom에 의해 정의되었다. 이는 보간 스플라인의 한 종류로서 제어점을 뚫는 모양을 가진다. 𝐏0,𝐏1,𝐏2,𝐏3 네 개의 제어점이 주어지면 곡선은 𝐏1 과 𝐏2 사이에 정의된다.

캣멀롬 스플라인은 네 개의 점 사이를 보간한다

정의

배리와 골드만의 피라미드 공식
캣멀롬 알고리즘에서의 노트 매개변수화

점은 𝐏i=[xiyi]T 와 같이 표현하기로 하자. 네 개의 점 𝐏0,𝐏1,𝐏2,𝐏3 과 노트 t0,t1,t2,t3 로 정의되는 곡선 일부 \mathbf{C} 즉 캣멀롬 스플라인은 다음과 같이 표현할 수 있다 :

𝐂=t2tt2t1𝐁1+tt1t2t1𝐁2

이는 다음과 같다

𝐁1=t2tt2t0𝐀1+tt0t2t0𝐀2
𝐁2=t3tt3t1𝐀2+tt1t3t1𝐀3
𝐀1=t1tt1t0𝐏0+tt0t1t0𝐏1
𝐀2=t2tt2t1𝐏1+tt1t2t1𝐏2
𝐀3=t3tt3t2𝐏2+tt2t3t2𝐏3

또한

ti+1=[(xi+1xi)2+(yi+1yi)2]α+ti

노트 매개변수화에서 α가 0부터 1 사이의 범위를 가지고 i=0,1,2,3 일 때 t0=0 이다. 구심적(centripetal) 캣멀롬 스플라인에서 α 값은 0.5이다.  α=0 일 때, 곡선은 표준(uniform) 캣멀롬 스플라인의 모양을 가진다. α=1일 때,  코달(chordal) 스플라인의 모양을 가진다.

코드 예제

아래는 파이썬으로 구현한 캣멀롬 스플라인의 예제이다

import numpy
import pylab as plt

def CatmullRomSpline(P0, P1, P2, P3, nPoints=100):
  """
  P0, P1, P2, and P3 should be (x,y) point pairs that define the Catmull-Rom spline.
  nPoints is the number of points to include in this curve segment.
  """
  # Convert the points to numpy so that we can do array multiplication
  P0, P1, P2, P3 = map(numpy.array, [P0, P1, P2, P3])

  # Calculate t0 to t4
  alpha = 0.5
  def tj(ti, Pi, Pj):
    xi, yi = Pi
    xj, yj = Pj
    return ( ( (xj-xi)**2 + (yj-yi)**2 )**0.5 )**alpha + ti

  t0 = 0
  t1 = tj(t0, P0, P1)
  t2 = tj(t1, P1, P2)
  t3 = tj(t2, P2, P3)

  # Only calculate points between P1 and P2
  t = numpy.linspace(t1,t2,nPoints)

  # Reshape so that we can multiply by the points P0 to P3
  # and get a point for each value of t.
  t = t.reshape(len(t),1)

  A1 = (t1-t)/(t1-t0)*P0 + (t-t0)/(t1-t0)*P1
  A2 = (t2-t)/(t2-t1)*P1 + (t-t1)/(t2-t1)*P2
  A3 = (t3-t)/(t3-t2)*P2 + (t-t2)/(t3-t2)*P3

  B1 = (t2-t)/(t2-t0)*A1 + (t-t0)/(t2-t0)*A2
  B2 = (t3-t)/(t3-t1)*A2 + (t-t1)/(t3-t1)*A3

  C  = (t2-t)/(t2-t1)*B1 + (t-t1)/(t2-t1)*B2
  return C

def CatmullRomChain(P):
  """
  Calculate Catmull Rom for a chain of points and return the combined curve.
  """
  sz = len(P)

  # The curve C will contain an array of (x,y) points.
  C = []
  for i in range(sz-3):
    c = CatmullRomSpline(P[i], P[i+1], P[i+2], P[i+3])
    C.extend(c)

  return C

# Define a set of points for curve to go through
Points = [[0,1.5],[2,2],[3,1],[4,0.5],[5,1],[6,2],[7,3]]

# Calculate the Catmull-Rom splines through the points
c = CatmullRomChain(Points)

# Convert the Catmull-Rom curve points into x and y arrays and plot
x,y = zip(*c)
plt.plot(x,y)

# Plot the control points
px, py = zip(*Points)
plt.plot(px,py,'or')

plt.show()

같이 보기

참조

↑ E. Catmull and R. Rom. A class of local interpolating splines. Computer Aided Geometric Design, pages 317-326, 1974.↑ P. J. Barry and R. N. Goldman. A recursive evaluation algorithm for a class of Catmull–Rom splines. SIGGRAPH Computer Graphics, 22(4):199-204, 1988.↑ Yuksel, C.; Schaefer, S.; Keyser, J. (2011). "Parameterization and applications of Catmull-Rom curves". Computer-Aided Design 43: 747–755. ↑ Jen Hong, Tan; U. R., Acharya (2014). "Active spline model: A shape based model—interactive segmentation". Digital Signal Processing 35: 64–74.

외부 링크