Cg Toolkit Cg 3.1 Toolkit Documentation
Cg / Standard Library / distance

Name

distance - return the Euclidean distance between two points

Synopsis

float distance(float pt1, float pt2);
float distance(float1 pt1, float1 pt2);
float distance(float2 pt1, float2 pt2);
float distance(float3 pt1, float3 pt2);
float distance(float4 pt1, float4 pt2);

half distance(half pt1, half pt2);
half distance(half1 pt1, half1 pt2);
half distance(half2 pt1, half2 pt2);
half distance(half3 pt1, half3 pt2);
half distance(half4 pt1, half4 pt2);

fixed distance(fixed pt1, fixed pt2);
fixed distance(fixed1 pt1, fixed1 pt2);
fixed distance(fixed2 pt1, fixed2 pt2);
fixed distance(fixed3 pt1, fixed3 pt2);
fixed distance(fixed4 pt1, fixed4 pt2);

Parameters

pt1
First point.
pt2
Second point.

Description

Returns the Euclidean distance from a first point pt1 to a second point pt2.

Reference Implementation

distance for a float3 vector could be implemented like this.

float distance(float3 pt1, float3 pt2)
{
  float3 v = vt2 - pt1;
  return sqrt(dot(v,v));
}

Profile Support

distance is supported in all profiles except fp20.

See Also

dot, length, normalize, sqrt


Cg Toolkit | Cg Toolkit | Download | Release Archive | Profiles | Reference | Books | Discussions |


Cg Standard Library

abs
acos
all
any
asin
atan2
atan
bitCount
bitfieldExtract
bitfieldInsert
bitfieldReverse
ceil
clamp
clip
cosh
cos
cross
ddx
ddy
degrees
determinant
distance
dot
exp2
exp
faceforward
findLSB
findMSB
floatToIntBits
floatToRawIntBits
floor
fmod
frac
frexp
fwidth
intBitsToFloat
inverse
isfinite
isinf
isnan
ldexp
length
lerp
lit
log10
log2
log
max
min
modf
mul
normalize
pack
pow
radians
reflect
refract
round
rsqrt
saturate
sign
sincos
sinh
sin
smoothstep
sqrt
step
tanh
tan
tex1DARRAYbias
tex1DARRAYcmpbias
tex1DARRAYcmplod
tex1DARRAYfetch
tex1DARRAYlod
tex1DARRAY
tex1DARRAYproj
tex1DARRAYsize
tex1Dbias
tex1Dcmpbias
tex1Dcmplod
tex1Dfetch
tex1Dlod
tex1D
tex1Dproj
tex1Dsize
tex2DARRAYbias
tex2DARRAYfetch
tex2DARRAYlod
tex2DARRAY
tex2DARRAYproj
tex2DARRAYsize
tex2Dbias
tex2Dcmpbias
tex2Dcmplod
tex2Dfetch
tex2Dlod
tex2DMSARRAYfetch
tex2DMSARRAYsize
tex2DMSfetch
tex2DMSsize
tex2D
tex2Dproj
tex2Dsize
tex3Dbias
tex3Dfetch
tex3Dlod
tex3D
tex3Dproj
tex3Dsize
texBUF
texBUFsize
texCUBEARRAYbias
texCUBEARRAYlod
texCUBEARRAY
texCUBEARRAYsize
texCUBEbias
texCUBElod
texCUBE
texCUBEproj
texCUBEsize
texRBUF
texRBUFsize
texRECTbias
texRECTfetch
texRECTlod
texRECT
texRECTproj
texRECTsize
transpose
trunc
unpack