明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 2023|回复: 2

请问龙龙仔,如何得到实体质心?

[复制链接]
发表于 2003-9-8 15:38:00 | 显示全部楼层 |阅读模式
用VLISP如何得到一个封闭Pline线的质心?
谢谢!
"觉得好,就打赏"
还没有人打赏,支持一下
发表于 2003-9-8 16:45:00 | 显示全部楼层
查看
http://bbs.mjtd.com/forum.php?mod=viewthread&tid=2277
发表于 2017-10-17 16:20:13 | 显示全部楼层
/*********************************************************************
**
**  getCurveProp:    求闭合曲线的质心
**
******************************************/
struct Curve_Prop {
                 AcGePoint3d  origin;
                                 AcGeVector3d xAxis;
                                 AcGeVector3d yAxis;
                                 double       perimeter;
                                 double       area;
                                 AcGePoint2d  centroid;
                                 double       momInertia[2];
                                 double       prodInertia;
                                 double       prinMoments[2];
                                 AcGeVector2d prinAxes[2];
                                 double       radiiGyration[2];
                                 AcGePoint2d  extentsLow;
                                 AcGePoint2d  extentsHigh;
};

Acad::ErrorStatus getCurveProp(AcDbEntity * pEnt,Curve_Prop & mCurveInfo)
{   AcDbCurve *pCurve;
    AcDbRegion *pRegion;
    AcDbVoidPtrArray curves,regions;
    AcDbLine *mLine=NULL;
    AcGePoint3d spt,ept;
    Acad::ErrorStatus es;
    AcDbPolyline *pLwpoly=NULL;
    int type=0,type1=0;

    if (pEnt->isKindOf(AcDbLine::desc())){
        return Acad::eNotImplementedYet;
    }
    if (pCurve=AcDbCurve::cast(pEnt)){
        if (pEnt->isKindOf(AcDb2dPolyline::desc())){
            if (Poly2dToLWPoly(pEnt,pLwpoly)!=Acad::eOk){
                return Acad::eNotImplementedYet;
            }
            pCurve=(AcDbCurve *)pLwpoly;
        }
        curves.append((void *)pCurve);
        if ((pCurve->isClosed())!=Adesk::kTrue){
            pCurve->getStartPoint(spt);
            pCurve->getEndPoint(ept);
            mLine=new AcDbLine(spt,ept);
            curves.append((void *)mLine);
        }
        es=AcDbRegion::createFromCurves(curves,regions);
        if (es!=Acad::eOk) return Acad::eNotImplementedYet;
        if (regions.length()<=0) return Acad::eNotImplementedYet;
        pRegion=(AcDbRegion *)regions.at(0);
        type=1;
    }
    else if (pRegion=AcDbRegion::cast(pEnt)){
    }
    else{
        return Acad::eNotImplementedYet;
    }
    mCurveInfo.origin.set(0,0,0);
    resbuf ucs;
    acedGetVar(_T("UCSXDIR"),&ucs);
    mCurveInfo.xAxis=asPnt3d(ucs.resval.rpoint).asVector();
    acedGetVar(_T("UCSYDIR"),&ucs);
    mCurveInfo.yAxis=asPnt3d(ucs.resval.rpoint).asVector();
    pRegion->getAreaProp(mCurveInfo.origin,mCurveInfo.xAxis,mCurveInfo.yAxis,mCurveInfo.perimeter,
                         mCurveInfo.area,mCurveInfo.centroid,mCurveInfo.momInertia,
                         mCurveInfo.prodInertia,mCurveInfo.prinMoments,mCurveInfo.prinAxes,
                         mCurveInfo.radiiGyration,mCurveInfo.extentsLow,mCurveInfo.extentsHigh);
    if (type){
        delete pRegion;
        if (mLine!=NULL){
            double len;
            AcGePoint3d pt;
            len=mLine->startPoint().distanceTo(mLine->endPoint());
            mCurveInfo.perimeter-=len;
            delete mLine;
        }
        if (pLwpoly!=NULL)
            delete pLwpoly;         
    }
    return Acad::eOk;
}


您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2025-5-19 23:39 , Processed in 0.150784 second(s), 26 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表