PCB钻孔时,当钻刀>6.3mm时,超出钻孔范围,钻孔工序是没有这么大的钻刀,当这种情况,工程CAM会都采用G84命令用小孔扩孔的方式制作, 在这里介绍一种如果不用G84命令,用程序实现将大孔生成小孔钻孔达到扩孔的目的。

一.我们先了解一下G84命令扩孔

孔尺寸大小

孔密度

连一篇文章有关于孔数计算方式: https://www.cnblogs.com/pcbren/p/9379178.html

二.求解思路

1.通过孔密度,求出孔与孔中心距离

2.求出单次增量方位角

3.以大孔中心为,长度为(大孔半径-小孔半径), 任选择一个方位角作为起始方位角,并增加一个起始孔,并围绕这个起始方位角不断递增方位角,直到360度递增完成后即结束。

三.C#简易代码实现:

1.扩孔钻孔代码

            string drilllayer = "drl";
gLayer layer = g.getFEATURES($"{drilllayer}", g.STEP, g.JOB, "mm", true);
List<gPP> pList = new List<gPP>(); double HoleSize = ; //扩孔所用钻刀大小
foreach (var pad in layer.Plist)
{
if (pad.width > ) //钻孔>6300需扩孔
{
gA arc = calc2.p_2A(new gP(pad.p, pad.width - HoleSize));
arc.width = HoleSize;
var HoleCenterDi = calc2.p_Convex(arc.width * 0.0005)*;
pList.AddRange(calc2.a_2Plist(arc, HoleCenterDi, , true));
}
}
addCOM.pad(pList);

2.计算函数

/// <summary>
/// 通过孔半径与凸高位求 孔中心距
/// </summary>
/// <param name="Rradius">孔半径</param>
/// <param name="tol_">凸位高度值</param>
/// <returns></returns>
public double p_Convex(double Rradius, double tol_ = 0.0127)
{
return Math.Sqrt(Math.Pow(Rradius, ) - Math.Pow(Rradius - tol_, )) * ;
}
/// <summary>
/// 求方位角
/// </summary>
/// <param name="ps"></param>
/// <param name="pe"></param>
/// <returns></returns>
public double p_ang(gPoint ps, gPoint pe)
{
double a_ang = Math.Atan((pe.y - ps.y) / (pe.x - ps.x)) / Math.PI * ;
//象限角 转方位角 计算所属象限 并求得方位角
if (pe.x >= ps.x && pe.y >= ps.y) //↗ 第一象限
{
return a_ang;
}
else if (!(pe.x >= ps.x) && pe.y >= ps.y) // ↖ 第二象限
{
return a_ang + ;
}
else if (!(pe.x >= ps.x) && !(pe.y >= ps.y)) //↙ 第三象限
{
return a_ang + ;
}
else if (pe.x >= ps.x && !(pe.y >= ps.y)) // ↘ 第四象限
{
return a_ang + ;
}
else
{
return a_ang;
}
}//求方位角
/// <summary>
/// 求增量坐标
/// </summary>
/// <param name="ps">起点</param>
/// <param name="val">增量值</param>
/// <param name="ang_direction">角度</param>
/// <returns></returns>
public gPP p_val_ang(gPP ps, double val, double ang_direction)
{
gPP pe = ps;
pe.p.x = ps.p.x + val * Math.Cos(ang_direction * Math.PI / );
pe.p.y = ps.p.y + val * Math.Sin(ang_direction * Math.PI / );
return pe;
}
/// <summary>
/// 弧Arc 转点P组集
/// </summary>
/// <param name="a"></param>
/// <param name="val_">此数值表示:分段数值</param>
/// <param name="type_">代表值数值类型 【0】弧长 【1】角度 【2】弦长 </param>
/// <param name="is_avg">是否平均分布 </param>
/// <returns></returns>
public List<gPP> a_2Plist(gA a, double val_ = 0.1d, int type_ = , bool is_avg = false)
{
List<gPP> list_point = new List<gPP>();
gPP tempP;
tempP.p = a.ps;
tempP.symbols = a.symbols;
tempP.width = a.width;
list_point.Add(tempP); double avg_count;
double angle_val = ;
double rad_ = p2p_di(a.pc, a.pe);
double sum_alge = a_Angle(a);
if (type_ == ) // 【1】角度
{
angle_val = val_;
avg_count = (int)(Math.Ceiling(sum_alge / angle_val)) - ; // 总角度/单角度
}
else if (type_ == ) //【2】弦长
{
angle_val = Math.Asin(val_ / (rad_ * )) * / pi;
avg_count = (int)(Math.Ceiling(sum_alge / angle_val)) - ; // 总角度/单角度
}
else // 【0】弧长
{
angle_val = val_ * / (pi * rad_);
avg_count = (int)(Math.Ceiling(sum_alge / angle_val)) - ; // 总角度/单角度
//avg_count = (int)(Math.Ceiling(a_Lenght(a) / val_)) - 1; // 或 总弧长/单弧长
}
if (is_avg)
angle_val = sum_alge / avg_count;
if (avg_count > )
{
gPP centerP = tempP;
centerP.p = a.pc;
double angle_s = p_ang(a.pc, a.ps);
if (a.ccw) { angle_val = - angle_val; }
for (int i = ; i < avg_count; i++)
{
tempP = p_val_ang(centerP, rad_, angle_s - angle_val * i);
list_point.Add(tempP);
}
}
if (!(zero(a.ps.x - a.pe.x) && zero(a.ps.y - a.pe.y)))
{
tempP.p = a.pe;
list_point.Add(tempP);
}
return list_point;
}
/// <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));
}
/// <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 == ) { angle_s = ; }
if (angle_e >= angle_s)
angle_sum = - Math.Abs(angle_s - angle_e);
else
angle_sum = Math.Abs(angle_s - angle_e);
return angle_sum;
}
/// <summary>
/// 检查值决对值 小于 (eps = 0.001) 浮点误差处理
/// </summary>
/// <param name="x"></param>
/// <returns></returns>
public bool zero(double x)
{
return (((x) > ? (x) : (-x)) < eps);
}

3.Point,PAD,Arc数据结构

/// <summary>
/// 精简 PAD 数据类型
/// </summary>
public struct gPP
{
public gPP(double x_val, double y_val, double width_)
{
this.p = new gPoint(x_val, y_val);
this.symbols = "r";
this.width = width_;
}
public gPP(gPoint p_, double width_)
{
this.p = p_;
this.symbols = "r";
this.width = width_;
}
public gPP(gPoint p_, string symbols_, double width_)
{
this.p = p_;
this.symbols = symbols_;
this.width = width_;
}
public gPoint p;
public string symbols;
public double width;
public static gPP operator +(gPP p1, gPP p2)
{
p1.p += p2.p;
return p1;
}
public static gPP operator +(gPP p1, gPoint p2)
{
p1.p += p2;
return p1;
}
public static gPP operator -(gPP p1, gPP p2)
{
p1.p -= p2.p;
return p1;
}
public static gPP operator -(gPP p1, gPoint p2)
{
p1.p -= p2;
return p1;
}
}
/// <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;
}
}
/// <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, 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, gP move_p)
{
arc1.ps -= move_p.p;
arc1.pe -= move_p.p;
arc1.pc -= move_p.p;
return arc1;
}
}

四.实现效果

最新文章

  1. 12. UITextField
  2. 安装appcan后打开eclipse出错
  3. Android Spinner控件数据绑定
  4. WCF 超时情形
  5. 新建android项目报错,代码中找不到错误
  6. 【MYSQL】update/delete/select语句中的子查询
  7. SRM566 1000pts
  8. input type=file accept中可以限制的文件类型
  9. Android笔记(一):从this关键字发散
  10. (转)requirejs:杏仁的优化(almond)
  11. C# DataGridView 列的显示顺序
  12. Django使用第三方模块django-password-reset重置密码
  13. AC自动机相关Fail树和Trie图相关基础知识
  14. AD 16 下绘图的几个技巧
  15. SSE,MSE,RMSE,R-square指标讲解
  16. Intellij新建Spring项目引入用户目录下的Spring jar包
  17. python核心编程笔记——Chapter7
  18. J2EE开发工作中遇到的异常问题及解决方法总结
  19. MySQL中常用字符串函数
  20. Android使用LinearViewLayout展示数据

热门文章

  1. UVA - 11212 Editing a Book (IDA*搜索)
  2. Linux学习笔记记录(五)
  3. webpack3 + vue 添加 serviceWorker
  4. Import CAD geometry in BladeModeler, turbogrid
  5. Linux 复习二
  6. 2018.5.7每天一题面试题----final, finally, finalize 的区别
  7. hdu2852 KiKi&#39;s K-Number
  8. hdu 2844 多重背包二进制优化
  9. hust 1017
  10. hdu——3836 Equivalent Sets