📄 mgcdistvec3lin3.cpp
字号:
// Magic Software, Inc.
// http://www.magic-software.com
// Copyright (c) 2000, All Rights Reserved
//
// Source code from Magic Software is supplied under the terms of a license
// agreement and may not be copied or disclosed except in accordance with the
// terms of that agreement. The various license agreements may be found at
// the Magic Software web site. This file is subject to the license
//
// FREE SOURCE CODE
// http://www.magic-software.com/License/free.pdf
#include "MgcDistVec3Lin3.h"
//----------------------------------------------------------------------------
MgcReal MgcSqrDistance (const MgcVector3& rkPoint, const MgcLine3& rkLine,
MgcReal* pfParam)
{
MgcVector3 kDiff = rkPoint - rkLine.Origin();
MgcReal fSqrLen = rkLine.Direction().SquaredLength();
MgcReal fT = kDiff.Dot(rkLine.Direction())/fSqrLen;
kDiff -= fT*rkLine.Direction();
if ( pfParam )
*pfParam = fT;
return kDiff.SquaredLength();
}
//----------------------------------------------------------------------------
MgcReal MgcSqrDistance (const MgcVector3& rkPoint, const MgcRay3& rkRay,
MgcReal* pfParam)
{
MgcVector3 kDiff = rkPoint - rkRay.Origin();
MgcReal fT = kDiff.Dot(rkRay.Direction());
if ( fT <= 0.0 )
{
fT = 0.0;
}
else
{
fT /= rkRay.Direction().SquaredLength();
kDiff -= fT*rkRay.Direction();
}
if ( pfParam )
*pfParam = fT;
return kDiff.SquaredLength();
}
//----------------------------------------------------------------------------
MgcReal MgcSqrDistance (const MgcVector3& rkPoint,
const MgcSegment3& rkSegment, MgcReal* pfParam)
{
MgcVector3 kDiff = rkPoint - rkSegment.Origin();
MgcReal fT = kDiff.Dot(rkSegment.Direction());
if ( fT <= 0.0 )
{
fT = 0.0;
}
else
{
MgcReal fSqrLen= rkSegment.Direction().SquaredLength();
if ( fT >= fSqrLen )
{
fT = 1.0;
kDiff -= rkSegment.Direction();
}
else
{
fT /= fSqrLen;
kDiff -= fT*rkSegment.Direction();
}
}
if ( pfParam )
*pfParam = fT;
return kDiff.SquaredLength();
}
//----------------------------------------------------------------------------
MgcReal MgcDistance (const MgcVector3& rkPoint, const MgcLine3& rkLine,
MgcReal* pfParam)
{
return MgcMath::Sqrt(MgcSqrDistance(rkPoint,rkLine,pfParam));
}
//----------------------------------------------------------------------------
MgcReal MgcDistance (const MgcVector3& rkPoint, const MgcRay3& rkRay,
MgcReal* pfParam)
{
return MgcMath::Sqrt(MgcSqrDistance(rkPoint,rkRay,pfParam));
}
//----------------------------------------------------------------------------
MgcReal MgcDistance (const MgcVector3& rkPoint, const MgcSegment3& rkSegment,
MgcReal* pfParam)
{
return MgcMath::Sqrt(MgcSqrDistance(rkPoint,rkSegment,pfParam));
}
//----------------------------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -