For all issues regarding the Forums use, please, refer to the Forum Rules.

Our Solutions

Need professional assistance?
Consider our:

Support Offerings

 

Need to speed up your development?
Have a look at our:

Samples & Tools

 

Need some functionality extending standard OCCT capabilities?
Check out our:

Adv. Components

Related pages

HOW TO COMPUTE DISTANCE BETWEEN POINT AND LINE??

Giorgii's picture
Forums: 

I need to compute distance between cylinder and a point,how can i do this?

Sharjith Naramparambath's picture

Check out GeomAPI_ProjectPointOnSurf::NearestPoint(). It should be helpful not only in your case for cylinder but any surface.

m-sazonov's picture

double CylDist(const gp_Cylinder& cyl, const gp_Pnt& pnt)
{
double u, v;
ElSLib::Parameters(cyl, pnt, u, v);
return pnt.Distance(ElSLib::Value(u, v, cyl));
}

Giorgii's picture

Thank you!it is working!=)

Sharjith Naramparambath's picture

This works equally well and is more generic:

double CylDist(const Handle(Geom_Surface)& cyl, const gp_Pnt& pnt)
{
GeomAPI_ProjectPointOnSurf PPS(pnt, cyl);
return PPS.LowerDistance();
}

Only issue that needs to be looked at is performance.. don't know the effect on performance.

Giorgii's picture

Sorry,but it does not link..
error LNK2028: ññûëêà íà íåðàçðåøåííóþ ëåêñåìó (0A00067F) "public: double __thiscall GeomAPI_ProjectPointOnSurf::LowerDistance(void)const " (?LowerDistance@GeomAPI_ProjectPointOnSurf@@$$FQBENXZ) â ôóíêöèè "double __cdecl CylDist2(class Handle_Geom_Surface const &,class gp_Pnt const &)" (?CylDist2@@$$FYANABVHandle_Geom_Surface@@ABVgp_Pnt@@@Z)
1>: error LNK2028: ññûëêà íà íåðàçðåøåííóþ ëåêñåìó (0A000680) "public: __thiscall GeomAPI_ProjectPointOnSurf::GeomAPI_ProjectPointOnSurf(class gp_Pnt const &,class Handle_Geom_Surface const &)" (??0GeomAPI_ProjectPointOnSurf@@$$FQAE@ABVgp_Pnt@@ABVHandle_Geom_Surface@@@Z) â ôóíêöèè "double __cdecl CylDist2(class Handle_Geom_Surface const &,class gp_Pnt const &)" (?CylDist2@@$$FYANABVHandle_Geom_Surface@@ABVgp_Pnt@@@Z)
1> error LNK2019: ññûëêà íà íåðàçðåøåííûé âíåøíèé ñèìâîë "public: double __thiscall GeomAPI_ProjectPointOnSurf::LowerDistance(void)const " (?LowerDistance@GeomAPI_ProjectPointOnSurf@@$$FQBENXZ) â ôóíêöèè "double __cdecl CylDist2(class Handle_Geom_Surface const &,class gp_Pnt const &)" (?CylDist2@@$$FYANABVHandle_Geom_Surface@@ABVgp_Pnt@@@Z)
1 error LNK2019: ññûëêà íà íåðàçðåøåííûé âíåøíèé ñèìâîë "public: __thiscall GeomAPI_ProjectPointOnSurf::GeomAPI_ProjectPointOnSurf(class gp_Pnt const &,class Handle_Geom_Surface const &)" (??0GeomAPI_ProjectPointOnSurf@@$$FQAE@ABVgp_Pnt@@ABVHandle_Geom_Surface@@@Z) â ôóíêöèè "double __cdecl CylDist2(class Handle_Geom_Surface const &,class gp_Pnt const &)" (?CylDist2@@$$FYANABVHandle_Geom_Surface@@ABVgp_Pnt@@@Z)

Fabian Hachenberg's picture

have you passed libTKGeomAlgo.so to your linker?

Sharjith Naramparambath's picture

use these libraries:
TKernel.lib TKMath.lib TKG3d.lib TKGeomAlgo.lib TKGeomBase.lib

I have attached a simple VS2010 Express solution that I made for testing both the methods discussed above, hopefully you should find it helpful.

Attachments: 

Contact us

Attention: DO NOT use this form for all kind of request for the removal of your personal data. Please follow this link for such cases.