最近有好幾個寫腳本的朋友問我,SLOT槽孔孔的如何計算的,要求孔數與CAM350孔數保持一致。
前幾年通過在CAM350里面不斷測試,結果是:CAM 350中SLOT槽孔,孔與孔之間最高位,凸位高度值為0.0127mm
這里將計算方法分享一下,下次有同樣的問題可以看此篇文章即可得到答案了。哈。。。。
通過這個凸位值就很好的計算出SLOT槽孔數了,弧型SLOT槽的原理也是同樣的。
一.SLOT槽為線段,求解SLOT槽孔數 (Mod類在后面代碼中)
/// <summary> /// 求線Line slot槽孔數 (同CAM350一致) /// </summary> /// <param name="l"></param> /// <param name="tol_">凸位高度值</param> /// <returns></returns> public int l_2hole_count(gL l, double tol_ = 0.0127) { double r, center_L, hole_L; r = l.width / 1000 * 0.5; center_L = p2p_di(l.ps, l.pe); hole_L = Math.Sqrt(Math.Pow(r, 2) - Math.Pow(r - tol_, 2)) * 2; return (int)Math.Abs(Math.Floor(-center_L / hole_L)) + 1; } /// <summary> /// 返回兩點之間歐氏距離 /// </summary> /// <param name="p1"></param> /// <param name="p2"></param> /// <returns></returns> public double p2p_di(gPoint p1, gPoint p2) { return Math.Sqrt((p1.x - p2.x) * (p1.x - p2.x) + (p1.y - p2.y) * (p1.y - p2.y)); }
二.SLOT槽為弧段,求解SLOT槽孔數 (Mod類在后面代碼中)
/// <summary> /// 求弧Arc slot槽孔數 (同CAM350一致) /// </summary> /// <param name="a"></param> /// <param name="tol_">凸位高度值</param> /// <returns></returns> public int a_2hole_count(gA a, double tol_ = 0.0127) { double r, center_L, hole_L; r = a.width / 1000 * 0.5; center_L = a_Length(a); hole_L = Math.Sqrt(Math.Pow(r, 2) - Math.Pow(r - tol_, 2)) * 2; return (int)Math.Abs(Math.Floor(-center_L / hole_L)) + 1; } /// <summary> /// 求弧Arc長度 /// </summary> /// <param name="a"></param> /// <returns></returns> public double a_Length(gA a) { return pi / 180 * p2p_di(a.pc, a.ps) * a_Angle(a); } /// <summary> /// 求弧Arc圓心角 //后續改進 用叉積 與3P求角度求解 驗證哪個效率高 /// </summary> /// <param name="a"></param> /// <returns></returns> public double a_Angle(gA a) { double angle_s, angle_e, angle_sum; if (a.ccw) { angle_s = p_ang(a.pc, a.pe); angle_e = p_ang(a.pc, a.ps); } else { angle_s = p_ang(a.pc, a.ps); angle_e = p_ang(a.pc, a.pe); } if (angle_s == 360) { angle_s = 0; } if (angle_e >= angle_s) angle_sum = 360 - Math.Abs(angle_s - angle_e); else angle_sum = Math.Abs(angle_s - angle_e); return angle_sum; }
三.使用的Mod類
線 mod類型
/// <summary> /// Line 數據類型 /// </summary> public struct gL { public gL(double ps_x, double ps_y, double pe_x, double pe_y, double width_) { this.ps = new gPoint(ps_x, ps_y); this.pe = new gPoint(pe_x, pe_y); this.negative = false; this.symbols = "r"; this.attribut = string.Empty; this.width = width_; } public gL(gPoint ps_, gPoint pe_, double width_) { this.ps = ps_; this.pe = pe_; this.negative = false; this.symbols = "r"; this.attribut = string.Empty; this.width = width_; } public gL(gPoint ps_, gPoint pe_, string symbols_, double width_) { this.ps = ps_; this.pe = pe_; this.negative = false; this.symbols = symbols_; this.attribut = string.Empty; this.width = width_; } public gPoint ps; public gPoint pe; public bool negative;//polarity-- positive negative public string symbols; public string attribut; public double width; public static gL operator +(gL l1, gPoint move_p) { l1.ps += move_p; l1.pe += move_p; return l1; } public static gL operator +(gL l1, gPP move_p) { l1.ps += move_p.p; l1.pe += move_p.p; return l1; } public static gL operator +(gL l1, gP move_p) { l1.ps += move_p.p; l1.pe += move_p.p; return l1; } public static gL operator -(gL l1, gPoint move_p) { l1.ps -= move_p; l1.pe -= move_p; return l1; } public static gL operator -(gL l1, gPP move_p) { l1.ps -= move_p.p; l1.pe -= move_p.p; return l1; } public static gL operator -(gL l1, gP move_p) { l1.ps -= move_p.p; l1.pe -= move_p.p; return l1; } }
弧 mod類型
/// <summary> /// ARC 數據類型 /// </summary> public struct gA { public gA(double ps_x, double ps_y, double pc_x, double pc_y, double pe_x, double pe_y, double width_, bool ccw_) { this.ps = new gPoint(ps_x, ps_y); this.pc = new gPoint(pc_x, pc_y); this.pe = new gPoint(pe_x, pe_y); this.negative = false; this.ccw = ccw_; this.symbols = "r"; this.attribut = string.Empty; this.width = width_; } public gA(gPoint ps_, gPoint pc_, gPoint pe_, double width_, bool ccw_=false) { this.ps = ps_; this.pc = pc_; this.pe = pe_; this.negative = false; this.ccw = ccw_; this.symbols = "r"; this.attribut = string.Empty; this.width = width_; } public gPoint ps; public gPoint pe; public gPoint pc; public bool negative;//polarity-- positive negative public bool ccw; //direction-- cw ccw public string symbols; public string attribut; public double width; public static gA operator +(gA arc1, gPoint move_p) { arc1.ps += move_p; arc1.pe += move_p; arc1.pc += move_p; return arc1; } public static gA operator +(gA arc1, gPP move_p) { arc1.ps += move_p.p; arc1.pe += move_p.p; arc1.pc += move_p.p; return arc1; } public static gA operator +(gA arc1, gP move_p) { arc1.ps += move_p.p; arc1.pe += move_p.p; arc1.pc += move_p.p; return arc1; } public static gA operator -(gA arc1, gPoint move_p) { arc1.ps -= move_p; arc1.pe -= move_p; arc1.pc -= move_p; return arc1; } public static gA operator -(gA arc1, gPP move_p) { arc1.ps -= move_p.p; arc1.pe -= move_p.p; arc1.pc -= move_p.p; return arc1; } public static gA operator -(gA arc1, gP move_p) { arc1.ps -= move_p.p; arc1.pe -= move_p.p; arc1.pc -= move_p.p; return arc1; } }
點 mod類型
/// <summary> /// 點 數據類型 (XY) /// </summary> public struct gPoint { public gPoint(gPoint p_) { this.x = p_.x; this.y = p_.y; } public gPoint(double x_val, double y_val) { this.x = x_val; this.y = y_val; } public double x; public double y; public static gPoint operator +(gPoint p1, gPoint p2) { p1.x += p2.x; p1.y += p2.y; return p1; } public static gPoint operator -(gPoint p1, gPoint p2) { p1.x -= p2.x; p1.y -= p2.y; return p1; } }