Skip to content
Member Filters
Show Inherited
Show Protected
Show abstract
GR32_ColorGradients🞂TBarycentricGradientSamplerClass

TBarycentricGradientSampler

Samples linear color gradients inside or across 3 triangular vertices using barycentric coordinates.

Inheritance:TObject 🞂 TPersistent 🞂 TNotifiablePersistent 🞂 TCustomSampler 🞂 TCustomSparsePointGradientSampler 🞂 TBarycentricGradientSampler

Declaration ​

pascal
TBarycentricGradientSampler = class(TCustomSparsePointGradientSampler)

Description ​

A sparse point gradient interpolator using a barycentric coordinate system for interpolation.

Based on three (and only three) vertices, with each vertex specified with a certain color, a linear triangle of color is calculated. Outside this triangle the colours extends as before.

Mathematics & Algorithm ​

Given a triangle with vertices P1,P2,P3 and associated colors C1,C2,C3, any sampling point P=(X,Y) is expressed in barycentric coordinates (λ1,λ2,λ3):

P=λ1P1+λ2P2+λ3P3,λ1+λ2+λ3=1

The weights λi are computed via determinants:

λ1=(Y2−Y3)(X−X3)+(X3−X2)(Y−Y3)(Y2−Y3)(X1−X3)+(X3−X2)(Y1−Y3)λ2=(Y3−Y1)(X−X3)+(X1−X3)(Y−Y3)(Y2−Y3)(X1−X3)+(X3−X2)(Y1−Y3)λ3=1−λ1−λ2

The interpolated color C(P) is:

C(P)=λ1C1+λ2C2+λ3C3

References ​

See also ​