• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            eryar

            PipeCAD - Plant Piping Design Software.
            RvmTranslator - Translate AVEVA RVM to OBJ, glTF, etc.
            posts - 603, comments - 590, trackbacks - 0, articles - 0

            PlaneGCS-平面幾何約束求解器用法

            Posted on 2023-03-24 22:10 eryar 閱讀(1510) 評(píng)論(0)  編輯 收藏 引用 所屬分類: 2.OpenCASCADE

            PlaneGCS-平面幾何約束求解器用法

            eryar@163.com

            1 Introduction

            在傳統(tǒng)的機(jī)械設(shè)計(jì)軟件中,一般使用幾何約束求解器來(lái)畫(huà)草圖,再通過(guò)對(duì)草圖進(jìn)行拉伸旋轉(zhuǎn)等生成特征實(shí)現(xiàn)建模功能?;趨?shù)化歷史特征方式來(lái)建模的軟件繞不開(kāi)幾何約束求解器,目前主流商用軟件一般使用西門(mén)子D-Cubed DCM及達(dá)索的CGM。開(kāi)源世界也有兩款幾何約束求解器:SolveSpace和PlaneGCS。

            PlaneGCS字面意思是平面幾何約束求解器,主要用于繪制二維草圖。因?yàn)镻laneGCS代碼相對(duì)清晰,功能簡(jiǎn)單,只能處理平面幾何元素的約束,本文主要結(jié)合示例代碼介紹PlaneGCS的使用方法,在會(huì)用的基礎(chǔ)上去理解源碼的實(shí)現(xiàn)邏輯。

            2 PlaneGCS

            PlaneGCS主要包含三部分:

            • 幾何元素?cái)?shù)據(jù)結(jié)構(gòu)文件:h/Geo.cpp
            • 約束條件文件:h/Constraints.cpp
            • 約束求解實(shí)現(xiàn)文件:h/GCS.cpp

            其中幾何元素?cái)?shù)據(jù)結(jié)構(gòu)中定義的幾何元素如下圖所示:

            從上圖可以看到,目前支持的幾何元素有點(diǎn)Point,直線Line,圓Circle,橢圓Ellipse,雙曲線Hyperbola,拋物線Parabola,圓弧Arc/ArcOfEllipse/ArcOfHyperbola/ArcOfParabola,及B樣條曲線BSpline,不過(guò)看代碼BSpline部分函數(shù)沒(méi)有實(shí)現(xiàn),應(yīng)該是不支持的。

            約束條件文件定義的約束類型如下圖所示:

            從約束求解文件中可以看到,其中數(shù)學(xué)計(jì)算主要使用Eigen中非線性方程組求解算法和boost的圖graph算法,從中可以推測(cè)出實(shí)現(xiàn)平面幾何約束求解器中需要的關(guān)鍵技術(shù)。先掌握PlaneGCS的用法,然后再分析其背后的實(shí)現(xiàn)原理細(xì)節(jié)。

            3 Code Example

            這里給出一個(gè)簡(jiǎn)單的示例程序,先讓大家對(duì)PlaneGCS有個(gè)認(rèn)識(shí)。示例程序中演示了給兩條直線加上水平和垂直約束。為了便于查看約束后的結(jié)果,在代碼中生成Draw Test Harness腳本文件。

            程序代碼如下所示:

            /*
            Copyright(C) 2023 Shing Liu(eryar@163.com)
            Permission is hereby granted, free of charge, to any person obtaining a copy
            of this software and associated documentation files(the "Software"), to deal
            in the Software without restriction, including without limitation the rights
            to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
            copies of the Software, and to permit persons to whom the Software is
            furnished to do so, subject to the following conditions :
            The above copyright notice and this permission notice shall be included in all
            copies or substantial portions of the Software.
            THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
            IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
            FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
            AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
            LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
            OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
            SOFTWARE.
            */
            #include "GCS.h"
            #include <fstream>
            void test()
            {
                double aPx1 = 0.0;
                double aPy1 = 0.0;
                double aPx2 = 3.0;
                double aPy2 = 3.0;
                double aPx3 = 6.0;
                double aPy3 = 9.0;
                GCS::VEC_pD aParameters;
                aParameters.push_back(&aPx1);
                aParameters.push_back(&aPy1);
                aParameters.push_back(&aPx2);
                aParameters.push_back(&aPy2);
                aParameters.push_back(&aPx3);
                aParameters.push_back(&aPy3);
                GCS::Point aP1(&aPx1, &aPy1);
                GCS::Point aP2(&aPx2, &aPy2);
                GCS::Point aP3(&aPx3, &aPy3);
                GCS::Line aLine1;
                GCS::Line aLine2;
                aLine1.p1 = aP1;
                aLine1.p2 = aP2;
                aLine2.p1 = aP2;
                aLine2.p2 = aP3;
                std::ofstream aTclFile("d:/gcs.tcl");
                aTclFile << "# 2 lines before PlaneGCS solve" << std::endl;
                aTclFile << "vinit" << std::endl;
                aTclFile << "vertex aP1 " << aPx1 << " " << aPy1 << " 0" << std::endl;
                aTclFile << "vertex aP2 " << aPx2 << " " << aPy2 << " 0" << std::endl;
                aTclFile << "vertex aP3 " << aPx3 << " " << aPy3 << " 0" << std::endl;
                aTclFile << "polyvertex aPolyline1 aP1 aP2 aP3" << std::endl;
                aTclFile << "vdisplay aPolyline1 " << std::endl;
                aTclFile << "vsetcolor aPolyline1 RED" << std::endl;
                GCS::System aSolver;
                aSolver.addConstraintHorizontal(aLine1);
                aSolver.addConstraintVertical(aLine2);
                if (aSolver.solve(aParameters) == GCS::Success)
                {
                    aSolver.applySolution();
                    aTclFile << "# 2 lines after PlaneGCS solve" << std::endl;
                    aTclFile << "vertex aV1 " << aPx1 << " " << aPy1 << " 0" << std::endl;
                    aTclFile << "vertex aV2 " << aPx2 << " " << aPy2 << " 0" << std::endl;
                    aTclFile << "vertex aV3 " << aPx3 << " " << aPy3 << " 0" << std::endl;
                    aTclFile << "polyvertex aPolyline2 aV1 aV2 aV3" << std::endl;
                    aTclFile << "vdisplay aPolyline2 " << std::endl;
                    aTclFile << "vsetcolor aPolyline2 GREEN" << std::endl;
                }
                aTclFile.close();
            }
            int main(int argc, char* argv[])
            {
                test();
                return 0;
            }

            從程序代碼中可以看出PlaneGCS的使用先要定義需要計(jì)算的參數(shù)aParameters,這些參數(shù)是幾何元素中的數(shù)據(jù),都是使用的指針。然后將約束加入到GCS::System中,最后代入?yún)?shù)調(diào)用solve函數(shù)進(jìn)行求解。求解成功后使用applySolution()函數(shù)應(yīng)用求解結(jié)果。求解結(jié)果在Draw中顯示的綠色的線如下圖所示:

            4 Conclusion

            本文結(jié)合示例代碼演示如何使用PlaneGCS,主要使用了水平和垂直約束。PlaneGCS中還支持其他約束類型,童鞋們可以自己探索一下。幾何造型內(nèi)核和幾何約束求解器常被看作是工業(yè)CAD軟件的卡脖子技術(shù),開(kāi)源庫(kù)一般功能不太完善,但是用來(lái)探索背后的實(shí)現(xiàn)原理還是有參考借鑒意義的。希望有更多的童鞋去了解背后的原理,共同來(lái)提高國(guó)內(nèi)三維CAD軟件開(kāi)發(fā)水平。

            久久久久人妻一区精品| 狠狠色婷婷综合天天久久丁香 | 久久精品国产网红主播| 久久精品aⅴ无码中文字字幕不卡| 午夜精品久久久久久中宇| 91久久精品无码一区二区毛片| 国产99久久久国产精免费| 日批日出水久久亚洲精品tv| 久久久久久国产a免费观看黄色大片 | 久久精品成人免费网站| 久久亚洲国产成人影院网站 | 久久精品国产亚洲精品| 久久精品国产免费观看三人同眠| 亚洲精品美女久久777777| 久久久久久极精品久久久| 久久这里只有精品18| 亚洲国产精品成人久久蜜臀| 国产麻豆精品久久一二三| 久久久久香蕉视频| 2021精品国产综合久久| 伊人精品久久久久7777| 久久久受www免费人成| 国产精品无码久久综合 | 香蕉99久久国产综合精品宅男自 | 精品人妻伦九区久久AAA片69| 99久久精品费精品国产一区二区| 亚洲综合伊人久久综合| 亚洲人成电影网站久久| 久久成人国产精品一区二区| 久久精品国产精品亚洲人人| 曰曰摸天天摸人人看久久久| 欧美熟妇另类久久久久久不卡| 狠狠色丁香婷婷久久综合五月| www亚洲欲色成人久久精品| 久久99免费视频| 久久免费线看线看| 99久久精品国产麻豆| 亚洲综合精品香蕉久久网97| 久久久久久a亚洲欧洲aⅴ| 国产成人99久久亚洲综合精品| 久久综合综合久久狠狠狠97色88|