public virtual float Dot(PO vec1, PO vec2) { return(vec1.x * vec2.x + vec1.y * vec2.y + vec1.z * vec2.z); }
public void copy_p(PO p1, PO p2) { p1.x = p2.x; p1.y = p2.y; p1.z = p2.z; }
public void cal_vec(PO p0, PO p1, PO vec) { vec.x = p1.x - p0.x; vec.y = p1.y - p0.y; vec.z = p1.z - p0.z; }
public void cal_vecdot(PO vec1, PO vec2, PO vec) { vec.x = vec1.y * vec2.z - vec1.z * vec2.y; vec.y = -(vec1.x * vec2.z - vec1.z * vec2.x); vec.z = vec1.x * vec2.y - vec1.y * vec2.x; }
private PO[] Look_for_four_PO(PO p10, PO p20, float d) { /* * 输入:要处理的边的两个顶点,两个圆弧的圆心到要处理的边的距离; * 输出:一个长方形的四个顶点,且它们在集合中有序存放; */ PO pm, vt, vt0, vt10, pm0, p1, p2; p1 = new PO(); p2 = new PO(); p1.x = p10.x + X; p1.y = p10.y + Y; p2.x = p20.x + X; p2.y = p20.y + Y;//将实际点变换到网格系统中的点 PO[] p0 = new PO[4]; for (int i = 0; i < 4; i++) { p0[i] = new PO(); } float d0, d1, r; pm = new PO(); vt = new PO(); vt0 = new PO(); vt10 = new PO(); pm0 = new PO(); d0 = (float)(System.Math.Pow((p1.x - p2.x) * (p1.x - p2.x) + (p1.y - p2.y) * (p1.y - p2.y), 0.5)); //计算当前要处理的边的长度 r = (float)(System.Math.Pow(System.Math.Pow(d, 2) + System.Math.Pow(d0 / 2, 2), 0.5)); //计算当前边所对应的圆的半径的长度 pm.x = (p1.x + p2.x) / 2; pm.y = (p1.y + p2.y) / 2; //计算当前边的中点的坐标 vt.x = p1.x - p2.x; vt.y = p1.y - p2.y; d1 = (float)(System.Math.Pow(vt.x * vt.x + vt.y * vt.y, 0.5)); vt.x = vt.x / d1; vt.y = vt.y / d1; //计算沿当前边的向量对应的单位向量 vt0.x = -vt.y; vt0.y = vt.x; //计算与当前边垂直的向量对应的单位向量 vt10.x = pm.x + vt0.x * (r + d); vt10.y = pm.y + vt0.y * (r + d); p0[0].x = vt10.x + vt.x * r; p0[0].y = vt10.y + vt.y * r; //计算长方形的第一个角点的坐标 p0[1].x = vt10.x - vt.x * r; p0[1].y = vt10.y - vt.y * r; //计算长方形第二个角点的坐标 vt10.x = pm.x - vt0.x * (r + d); vt10.y = pm.y - vt0.y * (r + d); p0[2].x = vt10.x + vt.x * r; p0[2].y = vt10.y + vt.y * r; //计算长方形的第一个角点的坐标 p0[3].x = vt10.x - vt.x * r; p0[3].y = vt10.y - vt.y * r; //计算长方形第二个角点的坐标 for (int i = 0; i <= 2; i++) { for (int j = i + 1; j <= 3; j++) { if (p0[i].y > p0[j].y) { pm0.x = p0[i].x; pm0.y = p0[i].y; p0[i].x = p0[j].x; p0[i].y = p0[j].y; p0[j].x = pm0.x; p0[j].y = pm0.y; } } } return(p0); }
public void GetPL(PO pl1) { pl.Insert(pl1); return; }
public void Get_initial_center(PO center0) { initial_center = center0; }
private void Insert1() { util u1 = new util(); LINE l0 = nt_current.Data; pg.ToPrint(info); /*获取线链的头边和尾边的外端点*/ PO PLa, PFa; if (pkey.IsEqualToMe(l0.p1)) { PLa = l0.p2; } else { PLa = l0.p1; } if (pkey.IsEqualToMe(pre_l.Head.Data.p1)) { PFa = pre_l.Head.Data.p2; } else { PFa = pre_l.Head.Data.p1; } if (pg.selected) { info.Insert("po selected"); } else { info.Insert("po not selected"); } LINE lt;//获取相应边 info.Insert("t4"); #region PLa-PFa已存在 //如果PLa-PFa已存在,且尾边位于首边未搜索侧或首边两侧都搜索过 lt = Is_OutSide(PLa, PFa); if (lt != null) { info.Insert("ok"); } if (lt != null && (u1.noSearched(pre_l.Head.Data, PLa) || !pre_l.Head.Data.positive && !pre_l.Head.Data.negtive) && pkey.key != 3) { info.Insert("t1"); pkey.non_merged = false; Set_direction(pre_l.Head.Data, PLa); Set_direction(pre_l.Last.Data, PFa); Set_direction(lt, pkey); nt_current = nt_current.Next; // u1.InFile(u1.tri_num, (numbertri++).ToString() + '\t' + pkey.number + '\t' + PLa.number + '\t' + PFa.number); return; } #endregion //后面的没有PLa-PFa已存在的情况 #region pg位于其已搜索侧 if (!u1.noSearched(pre_l.Head.Data, pg) && u1.noSearched(pre_l.Head.Data, PLa) || pg == PFa) { //pg是当前边首边的外端点 info.Insert("t3"); pkey.non_merged = false; Set_direction(pre_l.Head.Data, PLa); Set_direction(l0, PFa); AddLine(PFa, PLa, pkey); nt_current = nt_current.Next; return; //u1.InFile(u1.tri_num, (numbertri++).ToString() + '\t' + pkey.number + '\t' + PLa.number + '\t' + PFa.number); } #endregion if (pg.selected) { //如果pg已经被选过 #region delete shadowpo //当前被处理的点的影子点位于pg的边链上 LINE shadow_l = Is_OutSide(pg, pkey); if (shadow_l != null) { info.Insert("shadow_pg_side"); PO shadow_po = shadow_l.getanotherpo(pg); PO shadow_po1, shadow_po2, shadow_pokey; shadow_po1 = shadow_po.ll.Head.Data.getanotherpo(shadow_po); shadow_po2 = shadow_po.ll.Last.Data.getanotherpo(shadow_po); float shadow_ang1, shadow_ang2; shadow_pokey = shadow_po1; shadow_ang1 = u1.d2_Cal_Op_Angle(PLa, shadow_po1, pkey); shadow_ang2 = u1.d2_Cal_Op_Angle(PLa, shadow_po2, pkey); if (shadow_ang2 < shadow_ang1) { shadow_pokey = shadow_po2; } lt = Is_OutSide(shadow_pokey, PLa); if (lt == null) { lt = AddLine(shadow_pokey, PLa, shadow_po); } PAINT.GetLL(lt); shadowPO(shadow_po, shadow_pokey, pkey, PLa); nt_current = pkey.ll.Last; return; } #endregion #region last's outside //如果pg是last的边链的外端点 lt = Is_OutSide(PLa, pg); if (lt != null) { info.Insert("last's outside\n"); Set_direction(pre_l.Last.Data, pg); AddLine(pkey, pg, PLa); //以上两句代码的顺序不能反,否则会出错 Set_direction(lt, pkey); nt_current = nt_current.Next; return; } #endregion last'soutside #region shadow_deal #region create shadowpo //如果pg是非特殊位置 info.Insert("arbitrary POint\n"); PO pt = new PO(pg.x, pg.y, pg.z); if (pg.shadow_pl != null) { pg.shadow_pl.Insert(pt); } else { info.Insert("add new shadow po\n"); pg.shadow_pl = new LinkList <PO>(); pg.shadow_pl.Insert(pg); pg.shadow_pl.Insert(pt); } pt.shadow_pl = pg.shadow_pl; pg = pt; //u1.InFile(u1.infopath, "here1"); AddLine(pkey, pg, PLa); // u1.InFile(u1.infopath, "here2"); AddLine(PLa, pg, pkey); //u1.InFile(u1.infopath, "here3"); Set_direction(l0, pg); // u1.InFile(u1.infopath, "here4"); //u1.InFile(u1.tri_num, (numbertri++).ToString() + '\t' + pkey.number + '\t' + PLa.number + '\t' + pg.number); work_pl.Insert(pg); //u1.InFile(u1.infopath,"here5"); pg.selected = true; nt_current = nt_current.Next; #endregion #endregion } else { #region ordinary_po info.Insert("ordinary point" + pg.number); //pg作为普通点处理 pg.number = number++; pg.selected = true; //u1.InFile(u1.node_key, pg.number.ToString() + '\t' + pg.x + '\t' + pg.y + '\t' + pg.key); AddLine(pkey, pg, PLa); AddLine(PLa, pg, pkey); Set_direction(l0, pg); //u1.InFile(u1.tri_num, (numbertri++).ToString() + '\t' + pkey.number + '\t' + PLa.number + '\t' + pg.number); if (pg.key != 3) { work_pl.Insert(pg); } //work_pl.Dispaly(); nt_current = nt_current.Next; #endregion } }
private void shadowPO(PO shap, PO shapflag, PO pap, PO papflag) { /* * 将影子点的边转移到父点中去 * shap是影子点,shapflag是影子点的标记点 * pap是父点,papflag是父点的标记点 */ util u1 = new util(); if (pap.ll.Head.Data.Po_insideme(papflag)) {//如果标记点在父点的首边上 if (shap.ll.Head.Data.Po_insideme(shapflag)) { #region case1 Node <LINE> lnt = shap.ll.Head; while (lnt != null) { //用父点换掉边中的影子点 lnt.Data.Po_insideme_and_changeit(pap); pap.ll.Head_Insert(lnt.Data); lnt = lnt.Next; } #endregion case1 } else { #region case2 LinkList <LINE> lt = new LinkList <LINE>(); Node <LINE> lnt = shap.ll.Head; while (lnt != null)//将shap的线链反序 { lt.Head_Insert(lnt.Data); lnt = lnt.Next; } lnt = lt.Head; while (lnt != null) { lnt.Data.Po_insideme_and_changeit(pap); pap.ll.Head_Insert(lnt.Data); lnt = lnt.Next; } #endregion case2 } } else {//如果标记点在父点的尾边上 if (shap.ll.Head.Data.Po_insideme(shapflag)) { shap.ToString(); #region case3 Node <LINE> lnt = shap.ll.Head; while (lnt != null) { lnt.Data.Po_insideme_and_changeit(pap); pap.ll.Insert(lnt.Data); lnt = lnt.Next; } #endregion case3 } else { #region case4 LinkList <LINE> lt = new LinkList <LINE>(); Node <LINE> lnt = shap.ll.Head; while (lnt != null)//将shap的线链反序 { lt.Head_Insert(lnt.Data); lnt = lnt.Next; } lnt = lt.Head; while (lnt != null) { lnt.Data.Po_insideme_and_changeit(pap); pap.ll.Insert(lnt.Data); lnt = lnt.Next; } #endregion case4 } } work_pl.Delete(shap); //如果此时父节点的尾边封闭,则开启其尾边相应方向 if (!pap.ll.Last.Data.negtive && !pap.ll.Last.Data.positive && pkey.key != 3) { Open_direction(pap.ll, pap); } }
private void PEBIGrid(PO p0) { util u1 = new util(); Node <LINE> la, lb, lc; PO pk1, pk2, pk3; PO p1, p2; la = p0.ll.Head; while (la.Next.Next != null) { lb = la.Next; lc = la.Next.Next; if (la.Data.p1 == p0) { pk1 = la.Data.p2; } else { pk1 = la.Data.p1; } if (lb.Data.p1 == p0) { pk2 = lb.Data.p2; } else { pk2 = lb.Data.p1; } if (lc.Data.p1 == p0) { pk3 = lc.Data.p2; } else { pk3 = lc.Data.p1; } p1 = u1.SearchOutHeart(p0, pk1, pk2); p2 = u1.SearchOutHeart(p0, pk2, pk3); PAINT.GetLL_pebi(new LINE(p1, p2)); la = la.Next; } PO pt1, pt2; pt1 = p0.ll.Head.Data.getanotherpo(p0); pt2 = p0.ll.Last.Data.getanotherpo(p0); if (Is_OutSide(pt1, pt2) != null) { lb = la.Next; lc = p0.ll.Head; if (la.Data.p1.IsEqualToMe(p0)) { pk1 = la.Data.p2; } else { pk1 = la.Data.p1; } if (lb.Data.p1.IsEqualToMe(p0)) { pk2 = lb.Data.p2; } else { pk2 = lb.Data.p1; } if (lc.Data.p1.IsEqualToMe(p0)) { pk3 = lc.Data.p2; } else { pk3 = lc.Data.p1; } p1 = u1.SearchOutHeart(p0, pk1, pk2); p2 = u1.SearchOutHeart(p0, pk2, pk3); PAINT.GetLL_pebi(new LINE(p1, p2)); //l2 la = p0.ll.Last; lb = p0.ll.Head; lc = lb.Next; if (la.Data.p1.IsEqualToMe(p0)) { pk1 = la.Data.p2; } else { pk1 = la.Data.p1; } if (lb.Data.p1.IsEqualToMe(p0)) { pk2 = lb.Data.p2; } else { pk2 = lb.Data.p1; } if (lc.Data.p1.IsEqualToMe(p0)) { pk3 = lc.Data.p2; } else { pk3 = lc.Data.p1; } p1 = u1.SearchOutHeart(p0, pk1, pk2); p2 = u1.SearchOutHeart(p0, pk2, pk3); PAINT.GetLL_pebi(new LINE(p1, p2)); } }
void Four_po_netnumber(PO[] p) { /* * 输入:长方形区域的四个角点的坐标 * 输出:长方形所包括的网格的坐标 */ util u1 = new util(); int x1, x1g, x2, x2g, xm, X0, Y0, X1, Y1, i; PO p1d, p2d, pm; pm = new PO(); if (u1.Direct_2d(new LINE(p[1], p[2]), p[3]) * u1.Direct_2d(new LINE(p[1], p[2]), p[0]) >= 0) { pm.x = p[2].x; pm.y = p[2].y; p[2].x = p[3].x; p[2].y = p[3].y; p[3].x = pm.x; p[3].y = pm.y; } X0 = (int)(p[0].x / Xi); Y0 = (int)(p[0].y / Yi); X1 = (int)(p[3].x / Xi); Y1 = (int)(p[3].y / Yi); p1d = p[0]; p2d = p[0]; x1g = x2g = 0; net_choosed.Clear(); for (i = Y0 + 1; i <= Y1 + 1; i++) { if (p1d.x == p[1].x) { x1 = (int)(p[1].x / Xi); } else if (p1d.y == p[1].y) { x1 = (int)(p[1].x / Xi); } else { x1 = (int)(u1.Cal_po_on_Line(p1d, p[1], (i + x1g) * Yi) / Xi); } if (p2d.x == p[2].x) { x2 = (int)(p[2].x / Xi); } else if (p2d.y == p[2].y) { x2 = (int)(p[2].x / Xi); } else { x2 = (int)(u1.Cal_po_on_Line(p2d, p[2], (i + x2g) * Yi) / Xi); } if (i - 1 == (int)(p[1].y / Yi)) { x1 = (int)(p[1].x / Xi); p1d = p[3]; x1g = -1; } if (i - 1 == (int)(p[2].y / Yi)) { x2 = (int)(p[2].x / Xi); x2g = -1; p2d = p[3]; } if (x1 > x2) { xm = x1; x1 = x2; x2 = xm; } while (x1 <= x2) { net_choosed.Insert(new PO(x1, i - 1)); x1++; } } }