規劃解題與檢驗函式

檢驗出功能缺損

規劃解題 :

計算題目,並一邊利用SciTE的偵錯窗來檢查之前寫的函式資料。

之前的題目:

http://chiamingyen.github.io/kmolab/blog/zi-xing-che-chuan-dong-2d-lian-tiao-hui-tu-er.html

規劃了一支程式來計算鍊輪的點座標(半成品):

鍊條解題:18齒與30齒的鏈條,上下外切線長為200。

小圓圓心為原點,大圓圓心在X軸上,求四個切點的座標

from slvs import from math import sys = Syst鏈m(500) g = 1

相關參數

n0 = 20 #鍊條長度(mm) n1 = 18 #小輪齒數(t) n2 = 30 #大輪齒數(t)

邊長為a的的正n邊形外接圓半徑為:

R=a/(2sin(pi/n)) or R=(a/2)csc(pi/n)

R1 = n0/(2sin(pi/n1)) R2 = n0/(2sin(pi/n2))

開始繪圖

原點Point0

p0 = sys.add_param(0.0) p1 = sys.add_param(0.0) p2 = sys.add_param(0.0) Point0 = Point3d(p0, p1, p2)

XY法線

qw, qx, qy, qz = Slvs_MakeQuaternion(1, 0, 0, 0, 1, 0) p3 = sys.add_param(qw) p4 = sys.add_param(qx) p5 = sys.add_param(qy) p6 = sys.add_param(qz) Normal1 = Normal3d(p3, p4, p5, p6, sys)

工作平面

Workplane1 = Workplane(Point0, Normal1)

3D版的Point0=>Point1

Point1 = Point2d(Workplane1, p0, p1)

小圓

p7 = sys.add_param(R1) Distance1 = Distance(Workplane1, p7) Circle1 = Circle(Workplane1, Normal1, Point1, Distance1)

Point2

p8 = sys.add_param(500.0) p9 = sys.add_param(0.0) Point2 = Point2d(Workplane1, p7, p8)

大圓

p10 = sys.add_param(R2) Distance2 = Distance(Workplane1, p10) Circle2 = Circle(Workplane1, Normal1, Point2, Distance2)

上端外切線的兩個點Point3和Point4

p11 = sys.add_param(300.0) p12 = sys.add_param(500.0) Point3 = Point2d(Workplane1, p11, p12) p13 = sys.add_param(500.0) p14 = sys.add_param(500.0) Point4 = Point2d(Workplane1, p13, p14)

下端外切線的兩個點Point5和Point6

p15 = sys.add_param(300.0) p16 = sys.add_param(-500.0) Point5 = Point2d(Workplane1, p15, p16) p17 = sys.add_param(500.0) p18 = sys.add_param(-500.0) Point6 = Point2d(Workplane1, p17, p18)

...

以下解題

sys.solve()

if (sys.result == SLVS_RESULT_OKAY): print ("兩點座標:") print(("(%.3f %.3f %.3f)")%(sys.get_param(0).val, sys.get_param(1).val, sys.get_param(2).val)) print(("(%.3f %.3f %.3f)\n")%(sys.get_param(8).val, sys.get_param(9).val, sys.get_param(2).val)) print ("上切點座標:") print(("(%.3f %.3f %.3f)")%(sys.get_param(11).val, sys.get_param(12).val, sys.get_param(2).val)) print(("(%.3f %.3f %.3f)\n")%(sys.get_param(13).val, sys.get_param(14).val, sys.get_param(2).val)) print ("下切點座標:") print(("(%.3f %.3f %.3f)")%(sys.get_param(15).val, sys.get_param(16).val, sys.get_param(2).val)) print(("(%.3f %.3f %.3f)\n")%(sys.get_param(17).val, sys.get_param(18).val, sys.get_param(2).val)) print ("導入函數測試:") print(pi) print ("%d DOF" % sys.dof) else: print ("solve failed")

但是在使用畫線並約束與圓相切的指令時,之前臆測的程式碼卻沒有這個功能,於是去倉儲搜尋函式名稱。

發現某些Solvespace的功能並沒有轉給CDemo使用,之前DOC.txt簡介只是說明出本體支援的功能。


h++的標頭檔slvs_python.hpp中,有以下項目:

class Constraint {
...
public:
    // This constructor can be used to make arbitrary
    // constraints. It has a very ugly name to discourage
    // its use. If you need a constraint that the library
    // doesn't support, you should implement it.
//以下是所有約束函式
...

而那些沒做出的功能都用註解的方式放在這些做好的函式之間,所以看來好像是要自己做了。

目前瞭解需要編寫的檔案為slvs.i的Interface檔、slvs_python.hpp標頭檔、constrainteq.cpp約束方程式的函式。

畢竟是用別人寫好的架構,自己修改應該沒甚麼太大的障礙,以一個Python模組而言,拓展所需才是協同作業重要之處。


Comments

comments powered by Disqus