Centripetal Catmull–Rom spline

In computer graphics, the centripetal Catmull–Rom spline is a variant form of the Catmull–Rom spline, originally formulated by Edwin Catmull and Raphael Rom,[1] which can be evaluated using a recursive algorithm proposed by Barry and Goldman.[2] It is a type of interpolating spline (a curve that goes through its control points) defined by four control points , with the curve drawn only from to .

Catmull–Rom spline interpolation with four points

Definition

Barry and Goldman's pyramidal formulation
Knot parameterization for the Catmull–Rom algorithm

Let denote a point. For a curve segment defined by points and knot sequence , the centripetal Catmull–Rom spline can be produced by:

where

and

in which ranges from 0 to 1 for knot parameterization, and with . For centripetal Catmull–Rom spline, the value of is . When , the resulting curve is the standard uniform Catmull–Rom spline; when , the result is a chordal Catmull–Rom spline.

Gif animation for uniform, centripetal and chordal parameterization of Catmull–Rom spline depending on the α value

Plugging into the spline equations and shows that the value of the spline curve at is . Similarly, substituting into the spline equations shows that at . This is true independent of the value of since the equation for is not needed to calculate the value of at points and .

3D centripetal Catmull-Rom spline segment.

The extension to 3D points is simply achieved by considering a generic 3D point and

Advantages

Centripetal Catmull–Rom spline has several desirable mathematical properties compared to the original and the other types of Catmull-Rom formulation.[3] First, it will not form loop or self-intersection within a curve segment. Second, cusp will never occur within a curve segment. Third, it follows the control points more tightly.[4][vague]

In this figure, there is a self-intersection/loop on the uniform Catmull-Rom spline (green), whereas for chordal Catmull-Rom spline (red), the curve does not follow tightly through the control points.

Other uses

In computer vision, centripetal Catmull-Rom spline has been used to formulate an active model for segmentation. The method is termed active spline model.[5] The model is devised on the basis of active shape model, but uses centripetal Catmull-Rom spline to join two successive points (active shape model uses simple straight line), so that the total number of points necessary to depict a shape is less. The use of centripetal Catmull-Rom spline makes the training of a shape model much simpler, and it enables a better way to edit a contour after segmentation.

Code example in Python

The following is an implementation of the Catmull–Rom spline in Python that produces the plot shown beneath.

import numpy
import matplotlib.pyplot as plt


QUADRUPLE_SIZE: int = 4


def num_segments(point_chain: tuple) -> int:
    # There is 1 segment per 4 points, so we must subtract 3 from the number of points  
    return len(point_chain) - (QUADRUPLE_SIZE - 1)


def flatten(list_of_lists) -> list:
    # E.g. mapping [[1, 2], [3], [4, 5]] to  [1, 2, 3, 4, 5] 
    return [elem for lst in list_of_lists for elem in lst]


def catmull_rom_spline(
    P0: tuple,
    P1: tuple,
    P2: tuple,
    P3: tuple,
    num_points: int,
    alpha: float = 0.5,
):
    """
    Compute the points in the spline segment
    :param P0, P1, P2, and P3: The (x,y) point pairs that define the Catmull-Rom spline
    :param num_points: The number of points to include in the resulting curve segment
    :param alpha: 0.5 for the centripetal spline, 0.0 for the uniform spline, 1.0 for the chordal spline.
    :return: The points
    """

    # Calculate t0 to t4. Then only calculate points between P1 and P2.
    # Reshape linspace so that we can multiply by the points P0 to P3
    # and get a point for each value of t.
    def tj(ti: float, pi: tuple, pj: tuple) -> float:
        xi, yi = pi
        xj, yj = pj
        dx, dy = xj - xi, yj - yi
        l = (dx ** 2 + dy ** 2) ** 0.5
        return ti + l ** alpha

    t0: float = 0.0
    t1: float = tj(t0, P0, P1)
    t2: float = tj(t1, P1, P2)
    t3: float = tj(t2, P2, P3)
    t = numpy.linspace(t1, t2, num_points).reshape(num_points, 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
    points = (t2 - t) / (t2 - t1) * B1 + (t - t1) / (t2 - t1) * B2
    return points


def catmull_rom_chain(points: tuple, num_points: int) -> list:
    """
    Calculate Catmull-Rom for a sequence of initial points and return the combined curve.
    :param points: Base points from which the quadruples for the algorithm are taken
    :param num_points: The number of points to include in each curve segment
    :return: The chain of all points (points of all segments)
    """
    point_quadruples = (  # Prepare function inputs
        (points[idx_segment_start + d] for d in range(QUADRUPLE_SIZE))
        for idx_segment_start in range(num_segments(points))
    )
    all_splines = (catmull_rom_spline(*pq, num_points) for pq in point_quadruples)
    return flatten(all_splines)


if __name__ == "__main__":
    POINTS: tuple = ((0, 1.5), (2, 2), (3, 1), (4, 0.5), (5, 1), (6, 2), (7, 3))  # Red points
    NUM_POINTS: int = 100  # Density of blue chain points between two red points

    chain_points: list = catmull_rom_chain(POINTS, NUM_POINTS)
    assert len(chain_points) == num_segments(POINTS) * NUM_POINTS  # 400 blue points for this example

    plt.plot(*zip(*chain_points), c="blue")
    plt.plot(*zip(*POINTS), c="red", linestyle="none", marker="o")
    plt.show()
Plot obtained by the Python example code given above

Code example in Unity C#

using UnityEngine;

// a single catmull-rom curve
public struct CatmullRomCurve
{
	public Vector2 p0, p1, p2, p3;
	public float alpha;

	public CatmullRomCurve(Vector2 p0, Vector2 p1, Vector2 p2, Vector2 p3, float alpha)
   {
		(this.p0, this.p1, this.p2, this.p3) = (p0, p1, p2, p3);
		this.alpha = alpha;
	}

	// Evaluates a point at the given t-value from 0 to 1
	public Vector2 GetPoint(float t)
    {
		// calculate knots
		const float k0 = 0;
		float k1 = GetKnotInterval(p0, p1);
		float k2 = GetKnotInterval(p1, p2) + k1;
		float k3 = GetKnotInterval(p2, p3) + k2;

		// evaluate the point
		float u = Mathf.LerpUnclamped(k1, k2, t);
		Vector2 A1 = Remap(k0, k1, p0, p1, u);
		Vector2 A2 = Remap(k1, k2, p1, p2, u);
		Vector2 A3 = Remap(k2, k3, p2, p3, u);
		Vector2 B1 = Remap(k0, k2, A1, A2, u);
		Vector2 B2 = Remap(k1, k3, A2, A3, u);
		return Remap(k1, k2, B1, B2, u);
	}

	static Vector2 Remap(float a, float b, Vector2 c, Vector2 d, float u)
    {
		return Vector2.LerpUnclamped(c, d, (u - a) / (b - a));
	}

	float GetKnotInterval(Vector2 a, Vector2 b)
    {
		return Mathf.Pow(Vector2.SqrMagnitude(a - b), 0.5f * alpha);
	}
}


using UnityEngine;

// Draws a catmull-rom spline in the scene view,
// along the child objects of the transform of this component
public class CatmullRomSpline : MonoBehaviour
{
	[Range(0, 1)]
    public float alpha = 0.5f;
	int PointCount => transform.childCount;
	int SegmentCount => PointCount - 3;
	Vector2 GetPoint(int i) => transform.GetChild(i).position;

	CatmullRomCurve GetCurve(int i)
    {
		return new CatmullRomCurve(GetPoint(i), GetPoint(i+1), GetPoint(i+2), GetPoint(i+3), alpha);
	}

	void OnDrawGizmos()
    {
		for (int i = 0; i < SegmentCount; i++)
			DrawCurveSegment(GetCurve(i));
	}

	void DrawCurveSegment(CatmullRomCurve curve)
    {
		const int detail = 32;
		Vector2 prev = curve.p1;

		for (int i = 1; i < detail; i++)
        {
			float t = i / (detail - 1f);
			Vector2 pt = curve.GetPoint(t);
			Gizmos.DrawLine(prev, pt);
			prev = pt;
		}
	}
}

Code example in Unreal C++

float GetT( float t, float alpha, const FVector& p0, const FVector& p1 )
{
    auto d  = p1 - p0;
    float a = d | d; // Dot product
    float b = FMath::Pow( a, alpha*.5f );
    return (b + t);
}

FVector CatmullRom( const FVector& p0, const FVector& p1, const FVector& p2, const FVector& p3, float t /* between 0 and 1 */, float alpha=.5f /* between 0 and 1 */ )
{
    float t0 = 0.0f;
    float t1 = GetT( t0, alpha, p0, p1 );
    float t2 = GetT( t1, alpha, p1, p2 );
    float t3 = GetT( t2, alpha, p2, p3 );
    t = FMath::Lerp( t1, t2, t );
    FVector A1 = ( t1-t )/( t1-t0 )*p0 + ( t-t0 )/( t1-t0 )*p1;
    FVector A2 = ( t2-t )/( t2-t1 )*p1 + ( t-t1 )/( t2-t1 )*p2;
    FVector A3 = ( t3-t )/( t3-t2 )*p2 + ( t-t2 )/( t3-t2 )*p3;
    FVector B1 = ( t2-t )/( t2-t0 )*A1 + ( t-t0 )/( t2-t0 )*A2;
    FVector B2 = ( t3-t )/( t3-t1 )*A2 + ( t-t1 )/( t3-t1 )*A3;
    FVector C  = ( t2-t )/( t2-t1 )*B1 + ( t-t1 )/( t2-t1 )*B2;
    return C;
}

See also

References

  1. ^ Catmull, Edwin; Rom, Raphael (1974). "A class of local interpolating splines". In Barnhill, Robert E.; Riesenfeld, Richard F. (eds.). Computer Aided Geometric Design. pp. 317–326. doi:10.1016/B978-0-12-079050-0.50020-5. ISBN 978-0-12-079050-0.
  2. ^ Barry, Phillip J.; Goldman, Ronald N. (August 1988). A recursive evaluation algorithm for a class of Catmull–Rom splines. Proceedings of the 15st Annual Conference on Computer Graphics and Interactive Techniques, SIGGRAPH 1988. Vol. 22. Association for Computing Machinery. pp. 199–204. doi:10.1145/378456.378511.
  3. ^ Yuksel, Cem; Schaefer, Scott; Keyser, John (July 2011). "Parameterization and applications of Catmull-Rom curves". Computer-Aided Design. 43 (7): 747–755. CiteSeerX 10.1.1.359.9148. doi:10.1016/j.cad.2010.08.008.
  4. ^ Yuksel; Schaefer; Keyser, Cem; Scott; John. "On the Parameterization of Catmull-Rom Curves" (PDF).{{cite web}}: CS1 maint: multiple names: authors list (link)
  5. ^ Jen Hong, Tan; Acharya, U. Rajendra (2014). "Active spline model: A shape based model-interactive segmentation" (PDF). Digital Signal Processing. 35: 64–74. arXiv:1402.6387. doi:10.1016/j.dsp.2014.09.002. S2CID 6953844.

Read other articles:

Ivan Nikonovich MoshlyakNama asliИван Никонович МошлякLahir(1907-10-15)15 Oktober 1907Rodino, Uyezd Barnaul, Kegubernuran Tomsk, Kekaisaran Rusia(kini Distrik Rodinsky, Krai Altai, Rusia)Meninggal22 April 1981(1981-04-22) (umur 73)Leningrad, SFSR Rusia, USSR(kini Sankt-Peterburg, Rusia)Pengabdian Uni SovietDinas/cabangAngkatan Darat Uni SovietLama dinas1929 – 1968PangkatMayor JenderalPerang/pertempuranKonflik perbatasan Soviet–Jepang Pertempuran Danau Kha...

 

 

Halaman ini berisi artikel tentang perusahaan balet. Untuk bank, lihat New York Community Bank. New York City BalletInformasi umumNamaNew York City BalletNama sebelumnyaAmerican BalletBallet CaravanAmerican Ballet CaravanThe Ballet SocietyDidirikan1948PendiriGeorge BalanchineLincoln KirsteinKoreografer pendiriGeorge BalanchineJerome RobbinsLetakDavid H. Koch TheaterLincoln Centre for the Performing ArtsNew York CityAS Situs webwww.nycballet.comStaf artistikPemimpin baletPeter MartinsIbu balet...

 

 

Catherine Zeta-JonesCBECatherine Zeta-Jones pada acara Tribeca Film Festival 2012.LahirCatherine Zeta Jones25 September 1969 (umur 54)Swansea, Wales, Britania RayaPekerjaanAktrisSuami/istriMichael Douglas ​(m. 2000)​Anak2 Catherine Zeta-Jones (lahir 25 September 1969) adalah seorang pemeran asal Wales, Britania Raya. Dia adalah salah satu pemenang Academy Awards yang berasl dari Wales. Kariernya pertama kali dimulai adalah pada saat dia membintangi berbagai ...

American author, Watergate figure For other people named John Dean, see John Dean (disambiguation). This biography of a living person relies too much on references to primary sources. Please help by adding secondary or tertiary sources. Contentious material about living persons that is unsourced or poorly sourced must be removed immediately, especially if potentially libelous or harmful.Find sources: John Dean – news · newspapers · books · scholar · JS...

 

 

Oversight division of a United States federal or state agency This article is about investigative offices in the United States. For similar offices in all countries, see Inspector general. This article has multiple issues. Please help improve it or discuss these issues on the talk page. (Learn how and when to remove these template messages) This article relies excessively on references to primary sources. Please improve this article by adding secondary or tertiary sources. Find sources: ...

 

 

Andrea Bertolacci Bertolacci con la nazionale italiana nel 2015 Nazionalità  Italia Altezza 179 cm Peso 75 kg Calcio Ruolo Centrocampista Squadra  Fatih Karagümrük CarrieraGiovanili 2006-2010 RomaSquadre di club1 2010-2012→  Lecce43 (6)2012-2015 Genoa88 (12)2015-2017 Milan42 (2)2017-2018→  Genoa33 (1)2018-2019 Milan0 (0)2019-2020 Sampdoria12 (0)2020-2022 Fatih Karagümrük37 (9)2022-2023 Kayserispor17 (2)2023 Fatih Karagümr�...

Hato Mayor Tỉnh Cộng hòa Dominicana [[Hình:|border|125px|Flag of the Province]] [[Hình:|100px|Coat of arms of Province]] Vị trí [[Hình:|200px|Vị trí của tỉnh {{{name}}}]] Thông tin Quốc gia  Cộng hòa Dominica Tên gọi dân cư HatoMayorense Ngày thành lập1984 Tỉnh lỵ • Dân số Hato Mayor del Rey98.017 Thành phố lớn nhất • Dân số Hato Mayor del Rey98,017 Diện tích • Tổng số • % của tổng dân số X�...

 

 

Arabic-language version of Wikipedia Arabic WikipediaThe logo of Arabic Wikipedia, a globe with puzzle pieces featuring several glyphs from various writing systems. In response to the 2023 Israel–Hamas war, the pieces are in the colours of the Palestinian flagType of siteInternet encyclopedia projectAvailable inArabicHeadquartersMiami, FloridaOwnerWikimedia FoundationCreated byArab wiki communityURLar.wikipedia.orgCommercialNoRegistrationOptionalLaunched9 July 2003; 2...

 

 

Top Indonesian association football league Football leagueLiga 1Organising bodyPT Liga Indonesia BaruFounded2008; 16 years ago (2008) (as Indonesia Super League)2017; 7 years ago (2017) (as Liga 1)First season2008–09CountryIndonesiaConfederationAFCNumber of teams18Level on pyramid1Relegation toLiga 2Domestic cup(s)Piala IndonesiaInternational cup(s)AFC Champions League 2AFC Challenge LeagueASEAN Club ChampionshipCurrent championsPSM (1st title) (2022–23...

Choate, Hall & Stewart LLPHeadquartersBostonNo. of offices1No. of attorneys170Major practice areasBusiness and Technology, Finance & Restructuring, Litigation, Intellectual Property, Private Equity, Wealth ManagementRevenue$274.7 million (2021)Profit per equity partner$3.24 million (2021)Date founded1899 (1899)FounderCharles F. Choate Jr., John Hall, Ralph A. StewartCompany typeLLPWebsitewww.choate.com Choate Hall & Stewart LLP, commonly referre...

 

 

جانسون كريك     الإحداثيات 43°04′45″N 88°46′16″W / 43.0792°N 88.7711°W / 43.0792; -88.7711   [1] تقسيم إداري  البلد الولايات المتحدة[2][3]  التقسيم الأعلى مقاطعة جيفرسون  خصائص جغرافية  المساحة 7.846086 كيلومتر مربع7.83974 كيلومتر مربع (1 أبريل 2010)  ارتفاع 253 مت�...

 

 

Family of fishes This article needs additional citations for verification. Please help improve this article by adding citations to reliable sources. Unsourced material may be challenged and removed.Find sources: Gourami – news · newspapers · books · scholar · JSTOR (July 2012) (Learn how and when to remove this message) GouramisTemporal range: Eocene–present PreꞒ Ꞓ O S D C P T J K Pg N Dwarf gourami (Trichogaster lalius) Scientific classification...

This article's factual accuracy may be compromised due to out-of-date information. Please help update this article to reflect recent events or newly available information. (March 2013) The Filipino Veterans Fairness Act is the name of a number of acts that have been introduced to the United States Congress in both the United States House of Representatives and the United States Senate since the 103rd Congress in 1993.[1] Since then, nearly every session of Congress has seen a new vers...

 

 

2009 greatest hits album by Our Lady PeaceThe Very Best of Our Lady PeaceGreatest hits album by Our Lady PeaceReleasedMarch 31, 2009[1]Recorded1992–2005GenreAlternative rock, post-grunge, art rockLength64:06LabelLegacy, ColumbiaOur Lady Peace chronology A Decade(2006) The Very Best of Our Lady Peace(2009) Burn Burn(2009) Professional ratingsReview scoresSourceRatingAllmusic[2] Playlist: The Very Best of Our Lady Peace is a compilation album consisting of select rema...

 

 

French politician Henri Georges Boulay de la MeurtheVice President of FranceIn office20 January 1849 – 14 January 1852PresidentLouis-Napoléon BonapartePreceded byOffice establishedSucceeded byOffice abolished Personal detailsBorn(1797-07-15)15 July 1797Nancy, FranceDied24 November 1858(1858-11-24) (aged 61)Paris, FranceSignature Henri Georges Boulay de la Meurthe, 2nd Count Boulay de La Meurthe (15 July 1797 – 24 November 1858) was a French politician who served as vice pre...

Torre delle CannelleUbicazioneStato Repubblica di Siena Stato attuale Italia RegioneToscana CittàMonte Argentario IndirizzoVia dei Limoni Coordinate42°22′34.58″N 11°08′36.29″E42°22′34.58″N, 11°08′36.29″E Informazioni generaliTipoTorre Inizio costruzioneXV secolo Costruttore Repubblica di Siena Informazioni militariFunzione strategicadifesa, avvistamento voci di architetture militari presenti su Wikipedia Modifica dati su Wikidata · Manuale La Torre delle Cannel...

 

 

City in Illinois, United StatesMartinsvilleCityCity Hall and Police stationLocation of Martinsville in Clark County, Illinois.Location of Illinois in the United StatesCoordinates: 39°20′17″N 87°52′53″W / 39.33806°N 87.88139°W / 39.33806; -87.88139[1]CountryUnited StatesStateIllinoisCountyClarkGovernment • MayorHerman DavidsonArea[2] • Total2.05 sq mi (5.31 km2) • Land2.02 sq mi (5...

 

 

Pietro Metastasio Pietro Metastasio, pseudonimo di Pietro Antonio Domenico Bonaventura Trapassi (Roma, 3 gennaio 1698 – Vienna, 12 aprile 1782), è stato un poeta, librettista, drammaturgo e presbitero italiano. È considerato il riformatore del melodramma italiano. Indice 1 Biografia 1.1 Infanzia e gioventù 1.2 Vita e lavori in Italia 1.3 Metastasio alla Corte di Vienna 2 L'opera seria 3 Libretti 3.1 Melodrammi 3.2 Feste, azioni, componimenti 3.3 Oratori 3.4 Cantate 3.5 Canzonette 3.6 Alt...

حسام الدين الحاجري معلومات شخصية الميلاد سنة 1186   أربيل  الوفاة سنة 1235 (48–49 سنة)  أربيل  سبب الوفاة اغتيال  الحياة العملية المهنة شاعر  اللغات العربية  تعديل مصدري - تعديل   حسام الدين عيسى بن سنجر بن بهرام الحاجري الإربلي يعرف أيضًا بالـبلبل الغرام (1186...

 

 

Japanese manga series by Kōhei Horikoshi This article is about the manga series. For other uses, see My Hero Academia (disambiguation). My Hero AcademiaFirst tankōbon volume cover, featuring Izuku Midoriya (front), All Might (back), and several other Pro Heroes (background)僕のヒーローアカデミア(Boku no Hīrō Akademia)GenreAdventure[1]Science fantasy[1]Superhero[2][3] MangaWritten byKōhei HorikoshiPublished byShueishaEnglish publisherNA...