private void SplitInHalf(Vector3 x, NewPointsGetter newPoints, Shape2 shapeAbove, Shape2 shapeBelow) { var a = new Point2(x); var b = new Point2(x); newPoints.AddPoints(EdgeP1, EdgeP2, a, b); shapeAbove.AddPoint(a); shapeBelow.AddPoint(b); if (EdgeP1.PlaneRelationship == PointPlaneRelationship.Above) { var newForBelow = new Edge2(EdgeP2, b); EdgeP2 = a; shapeAbove.Edges.Add(this); shapeBelow.Edges.Add(newForBelow); } else { var newForAbove = new Edge2(EdgeP2, a); EdgeP2 = b; shapeAbove.Edges.Add(newForAbove); shapeBelow.Edges.Add(this); } }
private static IEnumerable <Edge2> GetPolygonEdges(IEnumerable <Vector2> vectors) { var edges = new List <Edge2>(); var vectorsEnumerator = vectors.GetEnumerator(); vectorsEnumerator.MoveNext(); var firstPoint = vectorsEnumerator.Current; var point1 = firstPoint; var point2 = firstPoint; while (vectorsEnumerator.MoveNext()) { point1 = point2; point2 = vectorsEnumerator.Current; var edge = new Edge2(point1, point2); edges.Add(edge); } var lastEdge = new Edge2(point2, firstPoint); edges.Add(lastEdge); return(edges); }
public void AddEdge(Edge2 e) { e.EdgeP1.AddLink(e.EdgeP2); e.EdgeP2.AddLink(e.EdgeP1); m_Head = e.EdgeP1; }
// dessine une edge d'une epaisseur thickness en appliquant les transformations // de planMatrix public static void Draw(Edge2 edge, Matrix4x4 planMatrix, int thickness = 10, float offsetWidth=0, float offsetHeight=0) { Matrix4x4 matrix = GUI.matrix; Vector2 nextPt = edge.GetNextPoint2 (); nextPt.Set(nextPt.x+offsetWidth, nextPt.y+offsetHeight); nextPt = planMatrix.MultiplyPoint (nextPt); Vector2 prevPt = edge.GetPrevPoint2 (); prevPt.Set(prevPt.x+offsetWidth, prevPt.y+offsetHeight); prevPt = planMatrix.MultiplyPoint (prevPt); float angle = Vector2.Angle(nextPt - prevPt, Vector2.right); if (prevPt.y > nextPt.y) { angle = -angle; } GUIUtility.RotateAroundPivot (angle, prevPt); GUI.DrawTexture(new Rect (prevPt.x, prevPt.y - thickness / 2 , (nextPt - prevPt).magnitude, thickness), SOLID_EDGE_TEXTURE); GUI.matrix = matrix; }
public void AddNeighbor(string v1, string v2, double w) { Edge2 e1 = new Edge2(v2, w); List <Edge2> value; g.TryGetValue(v1, out value); value.Add(e1); }
public double ComputeArea() { //Compute area using Heron's formula double semiperimiter = (Edge1.ComputeLength() + Edge2.ComputeLength() + Edge3.ComputeLength()) / 2; double area = Math.Sqrt(semiperimiter * (semiperimiter - Edge1.ComputeLength()) * (semiperimiter - Edge2.ComputeLength()) * (semiperimiter - Edge3.ComputeLength())); return(area); }
private List <List <Vector2> > GenerateEdgeIslands(HashSet <Edge2> edgeSet) { // Run though edge set and get individual edge islands List <List <Vector2> > edgeIslands = new List <List <Vector2> >(); while (edgeSet.Count > 0) { List <Vector2> wallPath = new List <Vector2>(); IEnumerator <Edge2> en = edgeSet.GetEnumerator(); en.MoveNext(); Edge2 start = en.Current; Edge2 current = start; wallPath.Add(current.first); edgeSet.Remove(current); while (current.second != start.first) { wallPath.Add(current.second); Edge2 oldCurrent = new Edge2(current.first, current.second); foreach (Edge2 edge in edgeSet) { if (edge == start) { continue; } if (edge.first == current.second) { current = edge; break; } else if (edge.second == current.second) { current = new Edge2(edge.second, edge.first); break; } } if (current == oldCurrent) { throw new System.Exception("Infinite loop while iterating through edges."); } edgeSet.Remove(current); } wallPath.Add(start.first); edgeIslands.Add(wallPath); } return(edgeIslands); }
private void ProcessNewFace(Shape2 shape, List <Point2> points, Edge2 newEdge) { if (DefinesNewFace(points)) { shape.Faces.Add(GetNewFace(points, m_Normal)); if (IsNewlyFormedEdge(newEdge)) { shape.AddNewEdgeFromFaceSplit(newEdge); } } }
public void Split(NewPointsGetter newPoints, Shape2 shapeAbove, Shape2 shapeBelow) { m_InUse = false; var abovePoints = new List <Point2>(); var belowPoints = new List <Point2>(); var newAboveEdge = new Edge2(); var newBelowEdge = new Edge2(); for (int i = 0; i < m_Points.Count; i++) { var next = (i + 1) % m_Points.Count; var p1 = m_Points[i]; var p2 = m_Points[next]; if (p1.PlaneRelationship == PointPlaneRelationship.Above) { abovePoints.Add(p1); } else if (p1.PlaneRelationship == PointPlaneRelationship.Below) { belowPoints.Add(p1); } else { var a = newPoints.GetPointAbove(p1); var b = newPoints.GetPointBelow(p1); abovePoints.Add(a); belowPoints.Add(b); newAboveEdge.AddPoint(a); newBelowEdge.AddPoint(b); } if (Point2.PointsBridgePlane(p1, p2)) { var a = newPoints.GetPointAbove(p1, p2); var b = newPoints.GetPointBelow(p1, p2); abovePoints.Add(a); belowPoints.Add(b); newAboveEdge.AddPoint(a); newBelowEdge.AddPoint(b); } } ProcessNewFace(shapeAbove, abovePoints, newAboveEdge); ProcessNewFace(shapeBelow, belowPoints, newBelowEdge); }
void add_edge(int a, int b, int cap) { a = v(a); b = v(b); Edge2 e1 = new Edge2(a, b, cap, 0); Edge2 e2 = new Edge2(b, a, 0, 0); g[a].Add(e.Count); e.Add(e1); g[b].Add(e.Count); e.Add(e2); }
void add_edge(int a, int b, int cap) { a = GetOrCreateIndex(a); b = GetOrCreateIndex(b); Edge2 e1 = new Edge2(a, b, cap, 0); Edge2 e2 = new Edge2(b, a, 0, 0); edgeLists[a].Add(edges.Count); edges.Add(e1); edgeLists[b].Add(edges.Count); edges.Add(e2); }
/// <summary> /// 辺をy座標値で分割 /// 座標値は上から下にソートしてあること /// </summary> public List<Edge2>[] DivisionEdges(float[] divisions) { //下準備 int len = divisions.Length; List<Edge2>[] edges = new List<Edge2>[len - 1]; //左側(topBottomEdges) Edge2 divEdge = topBottomEdges[0]; //分割対象の辺 for (int i = 0; i < len; ++i) { if(divEdge) } return edges; }
private bool AreEdgeSlopesEqual() { if (Edge1.ComputeSlope() == Edge2.ComputeSlope()) { return(true); } if (Edge2.ComputeSlope() == Edge3.ComputeSlope()) { return(true); } if (Edge1.ComputeSlope() == Edge3.ComputeSlope()) { return(true); } return(false); }
public override bool Equals(object obj) { return(obj is Triangle triangle && Transform.Equals(triangle.Transform) && Material.Equals(triangle.Material) && Parent == triangle.Parent && HasParent == triangle.HasParent && P1.Equals(triangle.P1) && P2.Equals(triangle.P2) && P3.Equals(triangle.P3) && Edge1.Equals(triangle.Edge1) && Edge2.Equals(triangle.Edge2) && Normal.Equals(triangle.Normal) && N1.Equals(triangle.N1) && N2.Equals(triangle.N2) && N3.Equals(triangle.N3) && IsSmoothed == triangle.IsSmoothed); }
public void Construction2() { // Arrange var graph = new Graph <Node2, Edge2>(); // Act Node2 node1, node2; graph.Add(node1 = new Node2()); graph.Add(node2 = new Node2()); Edge2 edge; graph.Add(edge = new Edge2(node1, node2, 1)); // Assert edge.MyEdgeProp.ShouldBe(1); edge.Reverse.MyEdgeProp.ShouldBe(-1); }
/// <summary> /// Get the edge of this face with vertices v1, v2 /// </summary> /// <param name="v1">a vertex of the edge</param> /// <param name="v2">the other vertex</param> /// <returns>null if it cannot be found</returns> public Edge GetEdge(DualSite v1, DualSite v2) { if (Edge0.EqualEdge(v1, v2)) { return(Edge0); } else if (Edge1.EqualEdge(v1, v2)) { return(Edge1); } else if (Edge2.EqualEdge(v1, v2)) { return(Edge2); } else { return(null); } }
public override IntersectionList LocalIntersect(Ray ray) { var intersections = new IntersectionList(); var directionCrossEdge2 = ray.Direction.Cross(Edge2); var determinant = Edge1.Dot(directionCrossEdge2); if (Math.Abs(determinant) < DoubleExtensions.EPSILON) { return(intersections); } var f = 1.0 / determinant; var point1ToOrigin = ray.Origin - Point1; var u = f * point1ToOrigin.Dot(directionCrossEdge2); if (u < 0 || u > 1) { return(intersections); } var originCrossEdge1 = point1ToOrigin.Cross(Edge1); var v = f * ray.Direction.Dot(originCrossEdge1); if (v < 0 || (u + v) > 1) { return(intersections); } var t = f * Edge2.Dot(originCrossEdge1); var intersection = new Intersection { Shape = this, Time = t, U = u, V = v }; intersections.Add(intersection); return(intersections); }
//Are two lines intersecting? private void LineLine() { MyVector2 l1_p1 = t1_p1_trans.position.ToMyVector2(); MyVector2 l1_p2 = t1_p2_trans.position.ToMyVector2(); MyVector2 l2_p1 = t2_p1_trans.position.ToMyVector2(); MyVector2 l2_p2 = t2_p2_trans.position.ToMyVector2(); Edge2 l1 = new Edge2(l1_p1, l1_p2); Edge2 l2 = new Edge2(l2_p1, l2_p2); bool isIntersecting = _Intersections.LineLine(l1, l2, includeEndPoints: true); //Display //Gizmos.DrawLine(l1_p1.ToVector3(), l1_p2.ToVector3()); //Gizmos.DrawLine(l2_p1.ToVector3(), l2_p2.ToVector3()); //if (isIntersecting) //{ // MyVector2 intersectionPoint = Intersections.GetLineLineIntersectionPoint(l1_p1, l1_p2, l2_p1, l2_p2); // //Gizmos.color = Color.red; // //Gizmos.DrawSphere(intersectionPoint.ToVector3(), 1f); //} //With mesh //Line TestAlgorithmsHelpMethods.DisplayLineMesh(l1_p1, l1_p2, 0.5f, Color.white); TestAlgorithmsHelpMethods.DisplayLineMesh(l2_p1, l2_p2, 0.5f, Color.white); //If they are intersecting we can also get the intersection point if (isIntersecting) { MyVector2 intersectionPoint = _Intersections.GetLineLineIntersectionPoint(l1, l2); TestAlgorithmsHelpMethods.DisplayCircleMesh(intersectionPoint, 1f, 20, Color.red); } }
public override int GetHashCode() { int hashCode = -2063967696; hashCode = hashCode * -1521134295 + Transform.GetHashCode(); hashCode = hashCode * -1521134295 + Material.GetHashCode(); hashCode = hashCode * -1521134295 + SavedRay.GetHashCode(); hashCode = hashCode * -1521134295 + Parent.GetHashCode(); hashCode = hashCode * -1521134295 + HasParent.GetHashCode(); hashCode = hashCode * -1521134295 + P1.GetHashCode(); hashCode = hashCode * -1521134295 + P2.GetHashCode(); hashCode = hashCode * -1521134295 + P3.GetHashCode(); hashCode = hashCode * -1521134295 + Edge1.GetHashCode(); hashCode = hashCode * -1521134295 + Edge2.GetHashCode(); hashCode = hashCode * -1521134295 + Normal.GetHashCode(); hashCode = hashCode * -1521134295 + N1.GetHashCode(); hashCode = hashCode * -1521134295 + N2.GetHashCode(); hashCode = hashCode * -1521134295 + N3.GetHashCode(); hashCode = hashCode * -1521134295 + IsSmoothed.GetHashCode(); return(hashCode); }
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) { if (comboBox1.Text == "Circle") { Radius.Show(); RadiusTextBox.Show(); Edge1TextBox.Hide(); Edge2TextBox.Hide(); Edge1.Hide(); Edge2.Hide(); } if (comboBox1.Text == "Rectangle") { Edge1.Show(); Edge2.Show(); Edge1TextBox.Show(); Edge2TextBox.Show(); Radius.Hide(); RadiusTextBox.Hide(); } if (comboBox1.Text == "Select") { Radius.Hide(); RadiusTextBox.Hide(); Edge1TextBox.Hide(); Edge2TextBox.Hide(); Edge1.Hide(); Edge2.Hide(); } }
public void DrawPolygonFilled(ITransformation transformation, IEnumerable <Vector2> vectors, ushort?colorOverride = null, byte?pixelOverride = null) { var transformedVectors = vectors .Select(transformation.Transform) .ToList(); var yMax = (int)System.Math.Ceiling(transformedVectors.Max(vector => vector.Y)); var yMin = (int)System.Math.Floor(transformedVectors.Min(vector => vector.Y)); var edges = GetPolygonEdges(transformedVectors); for (var scanlineY = yMin; scanlineY <= yMax; scanlineY++) { var yEdgeIntersections = edges .Where(edge => edge.IsYValueOnEdge(scanlineY)) .Select(edge => edge.GetPointFromY(scanlineY)) .ToList(); var xSortedIntersections = yEdgeIntersections.OrderBy(vector => vector.X).ToList(); var index1 = 0; var index2 = 1; while (index2 < xSortedIntersections.Count) { var point1 = xSortedIntersections[index1]; var point2 = xSortedIntersections[index2]; var line = new Edge2(point1, point2); var startX = point1.X; var endX = point2.X; for (var x = startX; x <= endX; x++) { var point = new Vector2(x, scanlineY); DrawPoint(Transformation.None, point, colorOverride, pixelOverride); } index1 += 2; index2 += 2; } } }
/// <summary> /// y軸で分割する。分割したならtrueを返す /// </summary> public bool Division(float y, out Edge2 a, out Edge2 b) { a = b = null; if (isHorizontal) { //水平な場合 return(false); } else { //水平以外 if (isUpward) { if (from.y < y && y < to.y) { } } else { } } return(true); }
//生成三角网TIN public List <Edge> GeneTIN() { arrEdges.Clear(); arrTris.Clear(); arrDots = new PointF[mPointSet.PointList.Count]; for (int kk = 0; kk < mPointSet.PointList.Count; kk++) { arrDots[kk] = new PointF((float)mPointSet.PointList[kk].X, (float)mPointSet.PointList[kk].Y); } int i, idxStart = 0, endTemp, ptindex; bool isExist; double angMax, angMin, angTemp, angRcdMax, angRcdTmp, lenMin, lenCur, lenTmp1, lenTmp2; Edge2 edge = new Edge2(); //找到边界---(删除不需要的点,从X最小的地方开始找,直至回到起始点) PointF dirCur = new PointF(); PointF dirTmp1 = new PointF(); PointF dirTmp2 = new PointF(); PointF ptStart = new PointF(); for (i = 1; i < arrDots.Length; i++) { if (arrDots[i].X < arrDots[idxStart].X) { idxStart = i; } } endTemp = idxStart - 1; ptStart.X = arrDots[idxStart].X; ptStart.Y = arrDots[idxStart].Y; edge.Start = idxStart; angMin = Math.PI; dirCur.X = 0; dirCur.Y = 500; while (endTemp != idxStart) { lenCur = Math.Sqrt(dirCur.X * dirCur.X + dirCur.Y * dirCur.Y); lenMin = 1000; for (i = 0; i < arrDots.Length; i++)//找边界 { if (i != edge.Start) { dirTmp1.X = arrDots[i].X - ptStart.X; dirTmp1.Y = arrDots[i].Y - ptStart.Y; lenTmp1 = Math.Sqrt(dirTmp1.X * dirTmp1.X + dirTmp1.Y * dirTmp1.Y); angTemp = Math.Acos((dirCur.X * dirTmp1.X + dirCur.Y * dirTmp1.Y) / (lenTmp1 * lenCur)); if (angTemp < angMin) { angMin = angTemp; edge.End = i; lenMin = lenTmp1; } else if (angTemp == angMin && lenTmp1 < lenMin) { edge.End = i; lenMin = lenTmp1; } } } arrEdges.Add(edge); endTemp = edge.End; edge = new Edge2(); angMin = Math.PI; dirCur.X = arrDots[endTemp].X - ptStart.X; dirCur.Y = arrDots[endTemp].Y - ptStart.Y; ptStart = arrDots[endTemp]; edge.Start = endTemp; } //以下为自动生成TIN //从第一条边开始,按照先左后右的顺序寻找,找到则加入三角形数组和边数组,没有则继续下一边,直到边到达最后 //注意边可能有两种顺序存储。 for (i = 0; i < arrEdges.Count; i++) { //取出一条边 edge = new Edge2(); edge = (Edge2)arrEdges[i]; //先左后右计算扩展点-判断三角形是否存在过(若本边的左三角已存在,则计算右三角)?? if (edge.LeftTri == -1) { ptindex = -1;//选中的点的index dirCur.X = arrDots[edge.End].X - arrDots[edge.Start].X; dirCur.Y = arrDots[edge.End].Y - arrDots[edge.Start].Y; angRcdMax = 0; //与该边夹角最大值 angMax = 0; //最大圆内接角 for (int j = 0; j < arrDots.Length; j++) { if (j != edge.Start && j != edge.End)//排除边的端点 { dirTmp1.X = arrDots[j].X - arrDots[edge.Start].X; dirTmp1.Y = arrDots[j].Y - arrDots[edge.Start].Y; if (dirCur.X * dirTmp1.Y - dirCur.Y * dirTmp1.X < 0)//如果该点在左边,则计算 { //找角度最大的 lenCur = Math.Sqrt(dirCur.X * dirCur.X + dirCur.Y * dirCur.Y);//当前向量长度 lenTmp1 = Math.Sqrt(dirTmp1.X * dirTmp1.X + dirTmp1.Y * dirTmp1.Y); dirTmp2.X = arrDots[j].X - arrDots[edge.End].X; dirTmp2.Y = arrDots[j].Y - arrDots[edge.End].Y; lenTmp2 = Math.Sqrt(dirTmp2.X * dirTmp2.X + dirTmp2.Y * dirTmp2.Y); angRcdTmp = Math.Acos((dirCur.X * dirTmp1.X + dirCur.Y * dirTmp1.Y) / (lenTmp1 * lenCur)); angTemp = Math.Acos((dirTmp2.X * dirTmp1.X + dirTmp2.Y * dirTmp1.Y) / (lenTmp1 * lenTmp2)); if (angTemp > angMax) { angMax = angTemp; angRcdMax = angRcdTmp; ptindex = j; } else if (angTemp == angMax && angRcdMax < angRcdTmp)//相等取最左 { angRcdMax = angRcdTmp; ptindex = j; } } } } if (ptindex != -1)//选择有点 { //记录三角形 Tri tri = new Tri(); tri.NodeA = edge.Start; tri.NodeB = edge.End; tri.NodeC = ptindex; edge.LeftTri = arrTris.Count; isExist = false; //记录边1-需要检索是否存在过这条边-由于每条边都先有左三角形,如有三角形加入,必定为右三角形 for (int k = 0; k < arrEdges.Count; k++) { Edge2 e = (Edge2)arrEdges[k]; if (e.Start == edge.Start && e.End == ptindex)//如果存在过这条边,则记录其右三角形 { e.RightTri = arrTris.Count; tri.AdjTriB = e.LeftTri; isExist = true; break; } else if (e.Start == ptindex && e.End == edge.Start) { e.LeftTri = arrTris.Count; tri.AdjTriB = e.RightTri; isExist = true; break; } } if (isExist == false)//如果不存在这条边,则新建一条边 { Edge2 edgeadd = new Edge2(); edgeadd.Start = ptindex; edgeadd.End = edge.Start; edgeadd.LeftTri = arrTris.Count; arrEdges.Add(edgeadd); } isExist = false; //记录边2 for (int k = 0; k < arrEdges.Count; k++) { Edge2 e = (Edge2)arrEdges[k]; if (e.Start == ptindex && e.End == edge.End)//如果存在过这条边,则记录其右三角形 { e.RightTri = arrTris.Count; tri.AdjTriA = e.LeftTri; isExist = true; break; } else if (e.Start == edge.End && e.End == ptindex) { e.LeftTri = arrTris.Count; tri.AdjTriA = e.RightTri; isExist = true; break; } } if (isExist == false)//如果不存在这条边,则新建一条边 { Edge2 edgeadd = new Edge2(); edgeadd.Start = edge.End; edgeadd.End = ptindex; edgeadd.LeftTri = arrTris.Count; arrEdges.Add(edgeadd); } tri.AdjTriC = edge.RightTri; //如果edge的右三角形不存在,由if进来可见左三角也不存在,这只能是边界,从而tri.AdjTriC=-1合理 arrTris.Add(tri); //add the tri to the arraylist } } else if (edge.RightTri == -1)//由于最开始的那部分都是边界,只有一个三角形;以后的边都已存在一个三角形,也仅剩余一个,故可以else if { //仅在右边找 ptindex = -1;//选中的点的index dirCur.X = arrDots[edge.End].X - arrDots[edge.Start].X; dirCur.Y = arrDots[edge.End].Y - arrDots[edge.Start].Y; angMax = 0; //最大角度 angRcdMax = 0; //与该边夹角最大值 for (int j = 0; j < arrDots.Length; j++) { if (j != edge.Start && j != edge.End) //排除边的端点 { lenCur = Math.Sqrt(dirCur.X * dirCur.X + dirCur.Y * dirCur.Y); //当前向量长度 dirTmp1.X = arrDots[j].X - arrDots[edge.Start].X; dirTmp1.Y = arrDots[j].Y - arrDots[edge.Start].Y; if (dirCur.X * dirTmp1.Y - dirCur.Y * dirTmp1.X > 0)//如果该点在右边,则计算 { //找角度最大的 lenTmp1 = Math.Sqrt(dirTmp1.X * dirTmp1.X + dirTmp1.Y * dirTmp1.Y); dirTmp2.X = arrDots[j].X - arrDots[edge.End].X; dirTmp2.Y = arrDots[j].Y - arrDots[edge.End].Y; lenTmp2 = Math.Sqrt(dirTmp2.X * dirTmp2.X + dirTmp2.Y * dirTmp2.Y); angRcdTmp = Math.Acos((dirCur.X * dirTmp1.X + dirCur.Y * dirTmp1.Y) / (lenTmp1 * lenCur)); angTemp = Math.Acos((dirTmp2.X * dirTmp1.X + dirTmp2.Y * dirTmp1.Y) / (lenTmp1 * lenTmp2)); if (angTemp > angMax) { angMax = angTemp; angRcdMax = angRcdTmp; ptindex = j; } else if (angTemp == angMax && angRcdTmp > angTemp)//相等取最左 { angRcdTmp = angTemp; ptindex = j; } } } } if (ptindex != -1)//选择有点 { //记录三角形 //记录三角形 Tri tri = new Tri(); tri.NodeA = edge.Start; tri.NodeB = edge.End; tri.NodeC = ptindex; edge.RightTri = arrTris.Count; isExist = false; //记录边1-需要检索是否存在过这条边-由于每条边都先有左三角形,如有三角形加入,必定为右三角形 for (int k = 0; k < arrEdges.Count; k++) { Edge2 e = (Edge2)arrEdges[k]; if (e.Start == ptindex && e.End == edge.Start)//如果存在过这条边,则记录其右三角形 { e.RightTri = arrTris.Count; tri.AdjTriB = e.LeftTri; isExist = true; break; } else if (e.Start == edge.Start && e.End == ptindex) { e.LeftTri = arrTris.Count; tri.AdjTriB = e.RightTri; isExist = true; break; } } if (isExist == false)//如果不存在这条边,则新建一条边 { Edge2 edgeadd = new Edge2(); edgeadd.Start = edge.Start; edgeadd.End = ptindex; edgeadd.LeftTri = arrTris.Count; arrEdges.Add(edgeadd); } isExist = false; //记录边2 for (int k = 0; k < arrEdges.Count; k++) { Edge2 e = (Edge2)arrEdges[k]; if (e.Start == edge.End && e.End == ptindex)//如果存在过这条边,则记录其右三角形 { e.RightTri = arrTris.Count; tri.AdjTriA = e.LeftTri; isExist = true; break; } else if (e.Start == ptindex && e.End == edge.End) { e.LeftTri = arrTris.Count; tri.AdjTriA = e.RightTri; isExist = true; break; } } if (isExist == false)//如果不存在这条边,则新建一条边 { Edge2 edgeadd = new Edge2(); edgeadd.Start = ptindex; edgeadd.End = edge.End; edgeadd.LeftTri = arrTris.Count; arrEdges.Add(edgeadd); } tri.AdjTriC = edge.LeftTri; //如果edge的左三角形不存在,由if进来可见右三角也不存在,这只能是边界,从而tri.AdjTriC=-1合理 arrTris.Add(tri); //add the tri to the arraylist } } } List <Edge> EdgeList = new List <Edge>(); for (int gg = 0; gg < arrEdges.Count; gg++) { Edge2 eg = (Edge2)arrEdges[gg]; PointF pt1, pt2; pt1 = arrDots[eg.Start]; pt2 = arrDots[eg.End]; EdgeList.Add(new Edge( new DataPoint(gg, gg.ToString(), pt1.X, pt1.Y, 0), new DataPoint(-gg, (-gg).ToString(), pt2.X, pt2.Y, 0))); } return(EdgeList); }
/// <summary> /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// </summary> private void InitializeComponent() { this.button1 = new System.Windows.Forms.Button(); this.comboBox1 = new System.Windows.Forms.ComboBox(); this.Radius = new System.Windows.Forms.Label(); this.Edge1 = new System.Windows.Forms.Label(); this.Edge2 = new System.Windows.Forms.Label(); this.Edge1TextBox = new System.Windows.Forms.TextBox(); this.RadiusTextBox = new System.Windows.Forms.TextBox(); this.Edge2TextBox = new System.Windows.Forms.TextBox(); this.SuspendLayout(); // // button1 // this.button1.Location = new System.Drawing.Point(96, 100); this.button1.Name = "button1"; this.button1.Size = new System.Drawing.Size(81, 23); this.button1.TabIndex = 0; this.button1.Text = "REDIRECT"; this.button1.UseVisualStyleBackColor = true; this.button1.Click += new System.EventHandler(this.button1_Click); // // comboBox1 // this.comboBox1.FormattingEnabled = true; this.comboBox1.Location = new System.Drawing.Point(70, 50); this.comboBox1.Name = "comboBox1"; this.comboBox1.Size = new System.Drawing.Size(137, 23); this.comboBox1.TabIndex = 1; this.comboBox1.SelectedIndexChanged += new System.EventHandler(this.comboBox1_SelectedIndexChanged); // // Radius // this.Radius.AutoSize = true; this.Radius.Location = new System.Drawing.Point(47, 194); this.Radius.Name = "Radius"; this.Radius.Size = new System.Drawing.Size(42, 15); this.Radius.TabIndex = 2; this.Radius.Text = "Radius"; // // Edge1 // this.Edge1.AutoSize = true; this.Edge1.Location = new System.Drawing.Point(47, 239); this.Edge1.Name = "Edge1"; this.Edge1.Size = new System.Drawing.Size(39, 15); this.Edge1.TabIndex = 3; this.Edge1.Text = "Edge1"; // // Edge2 // this.Edge2.AutoSize = true; this.Edge2.Location = new System.Drawing.Point(47, 286); this.Edge2.Name = "Edge2"; this.Edge2.Size = new System.Drawing.Size(39, 15); this.Edge2.TabIndex = 4; this.Edge2.Text = "Edge2"; // // Edge1TextBox // this.Edge1TextBox.Location = new System.Drawing.Point(145, 236); this.Edge1TextBox.Name = "Edge1TextBox"; this.Edge1TextBox.Size = new System.Drawing.Size(117, 23); this.Edge1TextBox.TabIndex = 5; // // RadiusTextBox // this.RadiusTextBox.Location = new System.Drawing.Point(145, 191); this.RadiusTextBox.Name = "RadiusTextBox"; this.RadiusTextBox.Size = new System.Drawing.Size(117, 23); this.RadiusTextBox.TabIndex = 5; // // Edge2TextBox // this.Edge2TextBox.Location = new System.Drawing.Point(145, 283); this.Edge2TextBox.Name = "Edge2TextBox"; this.Edge2TextBox.Size = new System.Drawing.Size(117, 23); this.Edge2TextBox.TabIndex = 5; // // MainForm // this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(290, 369); this.Controls.Add(this.Edge2TextBox); this.Controls.Add(this.RadiusTextBox); this.Controls.Add(this.Edge1TextBox); this.Controls.Add(this.Edge2); this.Controls.Add(this.Edge1); this.Controls.Add(this.Radius); this.Controls.Add(this.comboBox1); this.Controls.Add(this.button1); this.Name = "MainForm"; this.Text = "MainForm"; this.ResumeLayout(false); this.PerformLayout(); comboBox1.Items.Add("Select"); comboBox1.Text = comboBox1.Items[0].ToString(); comboBox1.Items.Add("Circle"); comboBox1.Items.Add("Rectangle"); Radius.Hide(); RadiusTextBox.Hide(); Edge1TextBox.Hide(); Edge2TextBox.Hide(); Edge1.Hide(); Edge2.Hide(); }
// Update is called once per frame protected void Update() { #if (UNITY_IPHONE || UNITY_ANDROID) && !UNITY_EDITOR _touches = Input.touches; #endif if (_gui.GetCurrentMode () == PoolDesignerMode.PolygonEdition) { _cursor = _planTransformation.GetTransformedMousePosition (); // on cherche le point et l'edge qui sont sous le curseur FindIntersectedPoint (); FindIntersectedEdge (); //#if (UNITY_IPHONE || UNITY_ANDROID) && !UNITY_EDITOR // if(Input.touchCount == 1) // { // _firstTouch = _planTransformation.GetTouches()[0]; // Touch testouch = _touches[0]; // // if (!_gui.isOnUI () && _firstTouch.phase == TouchPhase.Began) // { // Debug.Log("---------> firstTouch "+_firstTouch.deltaTime+", "+_firstTouch.position+", "+_firstTouch.deltaPosition+", "+_firstTouch.phase); // Debug.Log("---------> testTouch "+testouch.deltaTime+", "+testouch.position+", "+testouch.deltaPosition+", "+testouch.phase); //#else //if UNITY_STANDALONE_OSX || UNITY_STANDALONE_WIN || UNITY_EDITOR if (!_gui.isOnUI () && _planTransformation.GetClickBegan()/*PC.In.Click1Down()*/ && !_gui.IsOpen()) { //#endif if(_gui.IsJustCloseMenu()) { _gui.setIsJustCloseMenu(false); return; } if (_selectedPointIndexCandidate >= 0) // selection { _selectedPointIndex = _selectedPointIndexCandidate; _selectedPoint = _polygon.GetPoints ()[_selectedPointIndex]; if (!_polygon.IsClosed () && _selectedPointIndex == 0 /*&& _polygon.GetPoints ().Count > 2*/) { _polygon.Close (); _selectedPointIndex = _polygon.GetPoints ().IndexOf (_selectedPoint); } _canMove = true; } else if (_selectedEdgeIndexCandidate >= 0) // insert point { _selectedEdgeIndex = _selectedEdgeIndexCandidate; _selectedEdge = _polygon.GetEdges ()[_selectedEdgeIndex]; Point2 newPoint = new Point2 (_cursor); newPoint.Set(newPoint.GetX()-_offsetWidth, newPoint.GetY()-_offsetHeight); _polygon.InsertPoint (_selectedEdgeIndex, newPoint); _selectedPointIndex = _polygon.GetPoints ().IndexOf (newPoint); _selectedPoint = newPoint; _canMove = true; } else if (!_polygon.IsClosed ()) // add point { Point2 newPoint = new Point2 (_cursor); newPoint.Set(newPoint.GetX()-_offsetWidth, newPoint.GetY()-_offsetHeight); _polygon.AddPoint (newPoint); _selectedPointIndex = _polygon.GetPoints ().Count - 1; _selectedPoint = newPoint; _canMove = true; } else // deselection { _selectedPointIndex = -1; _selectedPoint = null; _selectedEdgeIndex = -1; _selectedEdge = null; } if (_selectedPointIndex >= 0) // update radius slider values { _pointOffset = (Vector2)_selectedPoint - _cursor; if (_selectedPoint.GetJunction () == JunctionType.Broken) { _gui.SetSliderValues (0, 1); } else if (_selectedPoint.GetJunction () == JunctionType.Curved) { ArchedPoint2 ar = _selectedPoint as ArchedPoint2; _gui.SetSliderValues (ar.GetMeasuredRadius () / 100, ar.GetMaxRadius () / 100); } } } //#if (UNITY_IPHONE || UNITY_ANDROID) && !UNITY_EDITOR // } //#endif if (PC.In.Click1Up()) //Input.GetMouseButtonUp (0)) { _canMove = false; if (!_polygon.IsClosed () && _polygon.GetPoints ().Count > 2 && _selectedPointIndex == _polygon.GetPoints ().Count - 1) // close polygon { Vector2 firstPoint = _polygon.GetPoints ()[0]; float rectSize = 100; Rect closeRect = new Rect ( firstPoint.x - rectSize/2, firstPoint.y - rectSize/2, rectSize, rectSize); if (closeRect.Contains (_cursor)) { _polygon.CloseAndFusion (); _selectedPointIndex = -1; _selectedPoint = null; _selectedEdgeIndex = -1; _selectedEdge = null; } } } if(PC.In.Click1Hold() && _selectedPointIndex >= 0 && _canMove) // move selected point { _snapper.SetExclusionPoint (_selectedPoint); Vector2 pointPosition = _cursor + _pointOffset; if (_snapper.IsAngleSnapActivate () && _snapper.IsAngleSnapped ()) { pointPosition = _snapper.GetAngleSnapPosition (); } if (_snapper.IsAlignedPointSnapActivate ()) { if (_snapper.IsHSnapped ()) { pointPosition.y = _snapper.GetHSnapY () /*+ _offsetHeight*/; } if (_snapper.IsVSnapped ()) { pointPosition.x = _snapper.GetVSnapX () /*+ _offsetWidth*/; } } if (_snapper.IsPointSnapActivate () && _snapper.IsIntersectedSnapped ()) { pointPosition = _snapper.GetIntersectedSnapPosition (); // pointPosition.Set(pointPosition.x + _offsetWidth, pointPosition.y + _offsetHeight); } _polygon.MovePoint (_selectedPointIndex, pointPosition); } //#endif } if(m_isModifyingH || m_isModifyingW) { if (PC.In.Click1Up() && !PC.In.CursorOnUIs(m_cotationH,m_cotationW)) { m_isModifyingW = m_isModifyingH = false; } } }
public void Clear() { _selectedPoint = null; _selectedPointIndex = -1; _selectedEdge = null; _selectedEdgeIndex = -1; _polygon.Clear (); }
// Use this for initialization void Start() { _iosShadows = GameObject.Find("iosShadows"); if(_backgroundImg == null) Debug.LogError(DEBUGTAG+"Background Image"+PC.MISSING_REF); GameObject cameraGameObject = GameObject.Find ("PlanCamera"); _planCamera = cameraGameObject.GetComponent<Camera>(); _mainCamera = GameObject.Find ("mainCam"); _renderCamera = Camera.main; _polyDrawer = cameraGameObject.GetComponent <PolygonDrawer> (); _snapper = cameraGameObject.GetComponent <Snapper> (); _planTransformation = cameraGameObject.GetComponent <PlanTransformation> (); _planCamera.GetComponent<Camera>().enabled = false; _polyDrawer.enabled = false; _planTransformation.enabled = false; enabled = false; Point2 prevBgPoint = new Point2 (UnityEngine.Screen.width / 2 - 50, UnityEngine.Screen.height / 2); Point2 nextBgPoint = new Point2 (UnityEngine.Screen.width / 2 + 50, UnityEngine.Screen.height / 2); _backgroundEdge = new Edge2 (prevBgPoint, nextBgPoint); prevBgPoint.SetNextEdge (_backgroundEdge); nextBgPoint.SetPrevEdge (_backgroundEdge); }
public Polygon(PolygonRawData polygonRawData) { _closed = true; float area = 0; for (int i = 0; i < polygonRawData.Count; ++i) { Vector2 p1 = polygonRawData[i]; Vector2 p2 = polygonRawData[i + 1]; area += p1.x * p2.y - p2.x * p1.y; } if (area > 0) { polygonRawData.Reverse (); } //Debug.Log ("AREA " + area); Edge2 prevEdge = null; Point2 prevPt = null; Point2 currentPt = null; for (int i = 0; i < polygonRawData.Count - 1; ++i) { Vector2 rawPt = polygonRawData[i]; if (currentPt == null) { //currentPt = new Point2 (rawPt); currentPt = new Point2 (); currentPt.Set( rawPt.x, rawPt.y); } Point2 nextPt = new Point2 (polygonRawData[i + 1]); if (i == polygonRawData.Count - 2 && polygonRawData.Count > 2) { nextPt = _points[0].GetPrevEdge ().GetPrevPoint2 (); //nextPt = (Point2)_points[0].GetPrevEdge ().GetPrevPoint2 ().Clone(); //nextPt = new Point2(); nextPt.Set( _points[0].GetPrevEdge ().GetPrevPoint2 ().GetX(), _points[0].GetPrevEdge ().GetPrevPoint2 ().GetY()); } if (prevEdge == null) { if (prevPt == null) { //prevPt = new Point2 (polygonRawData[i - 1]); prevPt = new Point2 (); prevPt.Set( polygonRawData[i - 1].x, polygonRawData[i - 1].y); } prevEdge = new Edge2 (prevPt, currentPt); prevPt.SetNextEdge (prevEdge); } Edge2 nextEdge = new Edge2 (currentPt, nextPt); // if (i == polygonRawData.Count - 1) // { // nextEdge = _points[0].GetPrevEdge (); // } currentPt.SetEdges (prevEdge, nextEdge); _points.Add (currentPt); _edges.Add (nextEdge); if (i == polygonRawData.Count - 2 && polygonRawData.Count >= 2) { nextPt.SetPrevEdge (nextEdge); _edges.Add (nextPt.GetNextEdge ()); _points.Add (nextPt); } prevEdge = nextEdge; prevPt = currentPt; currentPt = nextPt; } if (_edges.Count == 2 && _points.Count == 2) { _points[0].SetPrevEdge (null); _points[1].SetNextEdge (null); _edges.RemoveAt (1); } UpdateBounds (); }
public void SetNextEdge(Edge2 nextEdge) { _nextEdge = nextEdge; Update (); }
protected void OnGUI() { // Get transformation matrix Matrix4x4 matrix = _planTransformation.GetMatrix (); GUI.depth = -10; // draw background image GUI.DrawTexture (_rectBackground, backgroundImage, ScaleMode.StretchToFill, false); // GUI.DrawTexture (_rectBackground, backgroundImage, ScaleMode.StretchToFill, false); if(_gridVisible) { ImgUtils.TileTextureWithOffset(backgroundImageGrid,_rectBackgroundInit, _rectBackground, ScaleMode.ScaleToFit, 0/*_offsetWidth*/,0/* _offsetHeight*/); } GUISkin bkup = GUI.skin; GUI.skin = skin; // draw current scale --> ex: 1 x 1 float scale = Mathf.Round ((1 / _planTransformation.GetScale ().x) * 100) / 100 ; // GUI.DrawTexture (new Rect (850+ _offsetWidth-20, 550+ _offsetHeight-20, 140, 140), labelBackgroundImage, ScaleMode.StretchToFill, true); // GUI.Label (new Rect (850+ _offsetWidth, 590 + _offsetHeight, 100, 20),/* scale.ToString () + " x " + */scale.ToString () + "m", "dimension label Main"); Function_PoolDesigner function = _gui.GetFunction (); // Dessin de l'image de fond chargé par l'utilisateur if (function.GetBackgroundImage () != null && function.IsBackgroundImageVisible () && _gui.GetCurrentMode () != PoolDesignerMode.BackgroundScale) { Rect bgRect = function.GetBackgroundRect (); // on applique les transformation du plan a l'image de fond Vector2 bgPt = new Vector2 (bgRect.x + _offsetWidth, bgRect.y + _offsetHeight); bgPt = matrix.MultiplyPoint (bgPt); bgRect.x = bgPt.x; bgRect.y = bgPt.y; bgRect.width = bgRect.width * _planTransformation.GetScale ().x; bgRect.height = bgRect.height * _planTransformation.GetScale ().x; GUI.DrawTexture (bgRect, function.GetBackgroundImage (), ScaleMode.ScaleToFit, false); } if (_maxDimensionVisible && _polygon.GetPoints ().Count > 0 && !(_cotationVisible && _canMove && PC.In.Click1Hold())) { // draw dimension square with the boundingBox Bounds polyBounds = _polygon.bounds; Vector2 dimensionPosition = new Vector2 ( polyBounds.center.x - polyBounds.extents.x + _offsetWidth, polyBounds.center.z - polyBounds.extents.z + _offsetHeight); dimensionPosition = matrix.MultiplyPoint (dimensionPosition); Vector2 dimensionSize = new Vector2 (polyBounds.size.x, polyBounds.size.z); float poolWidth = Mathf.Round (polyBounds.size.x) / 100; float poolHeight = Mathf.Round (polyBounds.size.z) / 100; if(m_newWidth != poolWidth.ToString() && !m_isModifyingW) m_newWidth = poolWidth.ToString(); if(m_newHeight != poolHeight.ToString() && !m_isModifyingH) m_newHeight = poolHeight.ToString(); dimensionSize = matrix.MultiplyVector (dimensionSize); Rect dimensionRect = new Rect (dimensionPosition.x - DIMENSION_OFFSET, dimensionPosition.y - DIMENSION_OFFSET , dimensionSize.x + DIMENSION_OFFSET + DIMENSION_OFFSET / 2, dimensionSize.y + DIMENSION_OFFSET + DIMENSION_OFFSET / 2); GUI.Label (dimensionRect, "", "dimensionSquare"); //Flèches m_cotationW.Set((dimensionRect.x + dimensionRect.width / 2) - 50,dimensionRect.y - 10,100,30); m_cotationH.Set(dimensionRect.x - 80,(dimensionRect.y + dimensionRect.height / 2) - 10,100,30); // if(m_cotationH.x < 100f) // plus besoin car plus de boutons gauche/droite // { // if(m_cotationH.yMax < Screen.height/2f && m_cotationH.yMax > Screen.height/2f - 25f) // m_cotationH.y = Screen.height/2f - 25f - 50f; // else if(m_cotationH.yMax > Screen.height/2f && m_cotationH.yMax < Screen.height/2f + 25f) // m_cotationH.y = Screen.height/2f + 25f + 20f; // else if(m_cotationH.y > Screen.height/2f && m_cotationH.y < Screen.height/2f + 25f) // m_cotationH.y = Screen.height/2f + 25f + 20f; // else if(m_cotationH.y < Screen.height/2f && m_cotationH.y > Screen.height/2f -25f) // m_cotationH.y = Screen.height/2f - 25f - 50f; // } //MODIFICATION DES COTES HEIGHT----------------------------------------------------------------- if(!m_isModifyingH) { GUI.BeginGroup(m_cotationH); if(GUI.Button(new Rect(0,0,30,30),"","changeSize") || UsefulFunctions.GUIOutlineButton/* GUI.Button*/(new Rect(30,0,70,30),poolHeight.ToString () + "m","txtout","txtin")) { m_isModifyingH = true; m_isModifyingW = false; #if UNITY_ANDROID || UNITY_IPHONE m_kb = TouchScreenKeyboard.Open(poolHeight.ToString(),TouchScreenKeyboardType.NumbersAndPunctuation); #endif } GUI.EndGroup(); } else { GUI.BeginGroup(m_cotationH); #if!(UNITY_ANDROID || UNITY_IPHONE) if(GUI.Button(new Rect(0,0,30,30),"","applySize")) { if(ChangeSize()) m_isModifyingH = false; else m_newHeight = ""; } GUI.SetNextControlName(c_uiCoteHeightName); // m_newHeight = GUI.TextField(new Rect(30,0,70,30),m_newHeight); m_newHeight = UsefulFunctions.GUIOutlineTextField(new Rect(30,0,70,30),m_newHeight,"txtout","txtin"); #else m_newHeight = m_kb.text; // GUI.Label(new Rect(30,0,70,30),m_newHeight,"dimension label"); UsefulFunctions.GUIOutlineLabel(new Rect(30,0,70,30),m_newHeight,"txtout","txtin"); if(m_kb.done) { if(m_kb.wasCanceled) { m_isModifyingH = false; m_newHeight = ""; } else { if(ChangeSize()) m_isModifyingH = false; else { m_newHeight = ""; m_isModifyingH = false; } } } #endif GUI.EndGroup(); if(GUI.GetNameOfFocusedControl() != c_uiCoteHeightName) GUI.FocusControl(c_uiCoteHeightName); } //MODIFICATION DES COTES Width---------------------------------------------------------------- if(!m_isModifyingW) { GUI.BeginGroup(m_cotationW); if(GUI.Button(new Rect(0,0,30,30),"","changeSize") || UsefulFunctions.GUIOutlineButton/* GUI.Button*/(new Rect(30,0,70,30),poolWidth.ToString () + "m", "txtout","txtin")) { m_isModifyingW = true; m_isModifyingH = false; #if UNITY_ANDROID || UNITY_IPHONE m_kb = TouchScreenKeyboard.Open(poolWidth.ToString(),TouchScreenKeyboardType.NumbersAndPunctuation); #endif } GUI.EndGroup(); } else { GUI.BeginGroup(m_cotationW); #if!(UNITY_ANDROID || UNITY_IPHONE) if(GUI.Button(new Rect(0,0,30,30),"","applySize")) { if(ChangeSize()) m_isModifyingW = false; else m_newWidth = ""; } GUI.SetNextControlName(c_uiCoteWidthName); // m_newWidth = GUI.TextField(new Rect(30,0,70,30),m_newWidth); m_newWidth = UsefulFunctions.GUIOutlineTextField(new Rect(30,0,70,30),m_newWidth,"txtout","txtin"); #else m_newWidth = m_kb.text; // GUI.Label(new Rect(30,0,70,30),m_newWidth,"dimension label"); UsefulFunctions.GUIOutlineLabel(new Rect(30,0,70,30),m_newWidth,"txtout","txtin"); if(m_kb.done) { if(m_kb.wasCanceled) { m_isModifyingW = false; m_newWidth = ""; } else { if(ChangeSize()) m_isModifyingW = false; else { m_newWidth = ""; m_isModifyingW = false; } } } #endif GUI.EndGroup(); if(GUI.GetNameOfFocusedControl() != c_uiCoteWidthName) GUI.FocusControl(c_uiCoteWidthName); } //GUI.Label (new Rect (dimensionRect.x + dimensionRect.width + 10, (dimensionRect.y + dimensionRect.height / 2) + 10, 40, 20), "", "dimension label"); //GUI.Label (new Rect ((dimensionRect.x + dimensionRect.width / 2) - 20, dimensionRect.y + dimensionRect.height + 10, 40, 20), "", "dimension label"); } // draw edges int edgeCounter = 0; foreach (Edge2 edge in _polygon.GetEdges ()) { if (edge.GetPrevPoint2 ().GetJunction () != JunctionType.Curved && edge.GetNextPoint2 ().GetJunction () != JunctionType.Curved) { EdgeDrawer.Draw (edge, matrix, 10, _offsetWidth, _offsetHeight); // draw simple edges } else { Point2 prevPoint = edge.GetPrevPoint2 (); Point2 prevEdgePoint = new Point2 (prevPoint); if (prevPoint.GetJunction () == JunctionType.Curved) { ArchedPoint2 aPoint = prevPoint as ArchedPoint2; prevEdgePoint.Set (aPoint.GetNextTangentPoint ()); Edge2 curvedEdge = new Edge2 (prevPoint, prevEdgePoint); Color bckColor = GUI.color; GUI.color = new Color (0.9f, 0.9f, 0.9f, 0.8f); EdgeDrawer.Draw (curvedEdge, matrix, 6, _offsetWidth, _offsetHeight); // draw edges before the curve GUI.color = bckColor; } Point2 nextPoint = edge.GetNextPoint2 (); Point2 nextEdgePoint = new Point2 (nextPoint); if (nextPoint.GetJunction () == JunctionType.Curved) { ArchedPoint2 aPoint = nextPoint as ArchedPoint2; nextEdgePoint.Set (aPoint.GetPrevTangentPoint ()); Edge2 curvedEdge = new Edge2 (nextEdgePoint, nextPoint); Color bckColor = GUI.color; GUI.color = new Color (0.9f, 0.9f, 0.9f, 0.8f); EdgeDrawer.Draw (curvedEdge, matrix, 6, _offsetWidth, _offsetHeight); // draw edges after the curve GUI.color = bckColor; } // draw edges between the curve Edge2 fillEdge = new Edge2 (prevEdgePoint, nextEdgePoint); EdgeDrawer.Draw (fillEdge, matrix, 10, _offsetWidth, _offsetHeight); } ++edgeCounter; } // draw point according its current state int pointCounter = 0; foreach (Point2 point in _polygon.GetPoints ()) { Vector2 position = point; position.Set(position.x+ _offsetWidth, position.y+ _offsetHeight); position = matrix.MultiplyPoint (position); if (pointCounter != _selectedPointIndex) { GUI.Box (new Rect (position.x - POINT_RADIUS / 2 , position.y - POINT_RADIUS / 2 , POINT_RADIUS, POINT_RADIUS), "", "point"); } else { if (_cotationVisible && _canMove && PC.In.Click1Hold()/*Input.GetMouseButton (0)*/) { // dessin des cote de chaque segment // ici segement precedent le sommet courant (sens anti-horaire) Edge2 prevEdge = point.GetPrevEdge (); if (prevEdge != null) { // on retrouve les deux sommets correspondant a chaque segment // en prenant en compte les sommets de type arc de cercle Point2 prevPt2 = prevEdge.GetPrevPoint2 (); Vector2 prevPt = prevPt2; prevPt.x = prevPt.x+_offsetWidth; prevPt.y = prevPt.y+_offsetHeight; if (prevPt2.GetJunction () == JunctionType.Curved) { ArchedPoint2 ap = prevPt2 as ArchedPoint2; prevPt = ap.GetNextTangentPoint (); prevPt.x = prevPt.x+_offsetWidth; prevPt.y = prevPt.y+_offsetHeight; } Vector2 nextPt = point; nextPt.x = nextPt.x+_offsetWidth; nextPt.y = nextPt.y+_offsetHeight; if (point.GetJunction () == JunctionType.Curved) { ArchedPoint2 ap = point as ArchedPoint2; nextPt = ap.GetPrevTangentPoint (); nextPt.x = nextPt.x+_offsetWidth; nextPt.y = nextPt.y+_offsetHeight; } // taille reel du segment float edgelabel = Mathf.Round (Vector2.Distance (nextPt, prevPt)) / 100; // on applique la matrice de transformation aux deux sommets prevPt = matrix.MultiplyPoint (prevPt); nextPt = matrix.MultiplyPoint (nextPt); // on cherche l'inclinaison a appliqué pour tracer la fleche et le label de dimension float angle = Vector2.Angle (nextPt - prevPt, Vector2.right); if (prevPt.y > nextPt.y) { angle = -angle; } Matrix4x4 m = GUI.matrix; GUIUtility.RotateAroundPivot (angle, prevPt); // taille du segment apres transformation matricielle float edgeLength = Vector2.Distance (nextPt, prevPt); Rect edgeRect = new Rect (prevPt.x - COTATION_OFFSET, prevPt.y, edgeLength + COTATION_OFFSET + COTATION_OFFSET, COTATION_HEIGHT); string style = "cotation"; float minusLabelY = 0; if (point.GetAngleType () == AngleType.Inside) { edgeRect = new Rect (prevPt.x - COTATION_OFFSET, prevPt.y - COTATION_HEIGHT, edgeLength + COTATION_OFFSET + COTATION_OFFSET, COTATION_HEIGHT); style = "reverse cotation"; minusLabelY = POINT_RADIUS + POINT_RADIUS; } GUI.Box (edgeRect, "", style); if (angle > -90 && angle <= 90) // ici le label est dans le bon sens { UsefulFunctions.GUIOutlineLabel/* GUI.Label */(new Rect ((prevPt.x + edgeLength / 2) - 20, prevPt.y + POINT_RADIUS - minusLabelY, 40, 20), edgelabel.ToString () + "m", "txtout","txtin"); } else { // le label est a l'envers, on applique une rotation // par rapport au sommet suivant le sommet courant (sens anti-horaire) // et d'angle 180 - angle mesuré GUI.matrix = m; GUIUtility.RotateAroundPivot (angle - 180, nextPt); UsefulFunctions.GUIOutlineLabel/* GUI.Label */(new Rect ((nextPt.x + edgeLength / 2) - 20, nextPt.y - POINT_RADIUS - 20 + minusLabelY, 40, 20), edgelabel.ToString () + "m", "txtout","txtin"); } GUI.matrix = m; } // meme chose pour le segment suivant Edge2 nextEdge = point.GetNextEdge (); if (nextEdge != null) { Vector2 prevPt = point; prevPt.x = prevPt.x+_offsetWidth; prevPt.y = prevPt.y+_offsetHeight; if (point.GetJunction () == JunctionType.Curved) { ArchedPoint2 ap = point as ArchedPoint2; prevPt = ap.GetNextTangentPoint (); prevPt.x = prevPt.x+_offsetWidth; prevPt.y = prevPt.y+_offsetHeight; } Point2 nextPt2 = nextEdge.GetNextPoint2 (); Vector2 nextPt = nextPt2; nextPt.x = nextPt.x+_offsetWidth; nextPt.y = nextPt.y+_offsetHeight; if (nextPt2.GetJunction () == JunctionType.Curved) { ArchedPoint2 ap = nextPt2 as ArchedPoint2; nextPt = ap.GetPrevTangentPoint (); nextPt.x = nextPt.x+_offsetWidth; nextPt.y = nextPt.y+_offsetHeight; } float edgelabel = Mathf.Round (Vector2.Distance (nextPt, prevPt)) / 100; prevPt = matrix.MultiplyPoint (prevPt); nextPt = matrix.MultiplyPoint (nextPt); float angle = Vector2.Angle (nextPt - prevPt, Vector2.right); if (prevPt.y > nextPt.y) { angle = -angle; } Matrix4x4 m = GUI.matrix; GUIUtility.RotateAroundPivot (angle, prevPt); float edgeLength = Vector2.Distance (nextPt, prevPt); Rect edgeRect = new Rect (prevPt.x - COTATION_OFFSET, prevPt.y, edgeLength + COTATION_OFFSET + COTATION_OFFSET, COTATION_HEIGHT); string style = "cotation"; float minusLabelY = 0; if (point.GetAngleType () == AngleType.Inside) { edgeRect = new Rect (prevPt.x - COTATION_OFFSET, prevPt.y - COTATION_HEIGHT, edgeLength + COTATION_OFFSET + COTATION_OFFSET, COTATION_HEIGHT); style = "reverse cotation"; minusLabelY = POINT_RADIUS + POINT_RADIUS; } GUI.Box (edgeRect, "", style); if (angle > -90 && angle <= 90) { UsefulFunctions.GUIOutlineLabel/* GUI.Label */(new Rect ((prevPt.x + edgeLength / 2) - 20, prevPt.y + POINT_RADIUS - minusLabelY, 40, 20), edgelabel.ToString () + "m", "txtout","txtin"); } else { GUI.matrix = m; GUIUtility.RotateAroundPivot (angle - 180, nextPt); UsefulFunctions.GUIOutlineLabel/* GUI.Label */(new Rect ((nextPt.x + edgeLength / 2) - 20, nextPt.y - POINT_RADIUS - 20 + minusLabelY, 40, 20), edgelabel.ToString () + "m", "txtout","txtin"); } GUI.matrix = m; } } // dessin du sommet courant if (_canMove && PC.In.Click1Hold() /*Input.GetMouseButton (0)*/) { GUI.Box (new Rect (position.x - POINT_RADIUS *2 / 2, position.y - POINT_RADIUS *2 / 2, POINT_RADIUS * 2, POINT_RADIUS * 2), "", "selected point up"); } else { GUI.Box (new Rect (position.x - POINT_RADIUS / 2, position.y - POINT_RADIUS / 2, POINT_RADIUS, POINT_RADIUS), "", "selected point"); } } // si arc de cercle dessin de l'arc de cercle if (point.GetJunction () == JunctionType.Curved) { ArchedPoint2 ap = point as ArchedPoint2; ArcDrawer.Draw (ap, matrix,_offsetWidth, _offsetHeight); } ++pointCounter; } GUI.skin = bkup; /*********************** DEBUG DRAW RECT FOR EDGE AND POINT SELECTION AND TRANSFORMED CURSOR POSITION ***********************/ /*float s = 1 / _planTransformation.GetScale ().x; float pr = POINT_RADIUS * s; foreach (Point2 point in _polygon.GetPoints ()) { Vector2 p = point; Rect pointRect = new Rect (p.x - pr / 2, p.y - pr / 2, pr, pr); GUI.Box (pointRect, ""); } GUI.Button (new Rect (_cursor.x - 4, _cursor.y - 4, 8, 8), ""); foreach (Edge2 edge in _polygon.GetEdges ()) { Vector2 prevPt = edge.GetPrevPoint2 (); Vector2 nextPt = edge.GetNextPoint2 (); float angle = Vector2.Angle (nextPt - prevPt, Vector2.right); if (prevPt.y > nextPt.y) { angle = -angle; } Matrix4x4 m = GUI.matrix; GUIUtility.RotateAroundPivot (angle, prevPt); Rect edgeRect = new Rect (prevPt.x + (pr / 2), prevPt.y - (pr / 2), edge.GetLength () - pr, pr); GUI.Box (edgeRect, ""); GUI.matrix = m; }*/ /********************************************************/ }
private static IEnumerable<Edge2> GetPolygonEdges(IEnumerable<Vector2> vectors) { var edges = new List<Edge2>(); var vectorsEnumerator = vectors.GetEnumerator(); vectorsEnumerator.MoveNext(); var firstPoint = vectorsEnumerator.Current; var point1 = firstPoint; var point2 = firstPoint; while (vectorsEnumerator.MoveNext()) { point1 = point2; point2 = vectorsEnumerator.Current; var edge = new Edge2(point1, point2); edges.Add(edge); } var lastEdge = new Edge2(point2, firstPoint); edges.Add(lastEdge); return edges; }
//Is a line intersecting with a plane? private void LinePlane() { Vector3 planeNormal = planeTrans.forward; Vector3 planePos = planeTrans.position; Vector3 line_p1 = t1_p1_trans.position; Vector3 line_p2 = t1_p2_trans.position; //2d space MyVector2 planeNormal_2d = planeNormal.ToMyVector2(); MyVector2 planePos_2d = planePos.ToMyVector2(); MyVector2 line_p1_2d = line_p1.ToMyVector2(); MyVector2 line_p2_2d = line_p2.ToMyVector2(); Plane2 plane = new Plane2(planePos_2d, planeNormal_2d); Edge2 line = new Edge2(line_p1_2d, line_p2_2d); bool isIntersecting = _Intersections.LinePlane(plane, line); //Debug //TestAlgorithmsHelpMethods.DrawPlane(planePos_2d, planeNormal_2d, Color.blue); ////Line //Gizmos.color = Color.white; //Gizmos.DrawWireSphere(line_p1, 0.1f); //Gizmos.DrawWireSphere(line_p2, 0.1f); //if (isIntersecting) //{ // Gizmos.color = Color.red; // MyVector2 intersectionPoint = Intersections.GetLinePlaneIntersectionPoint(planePos_2d, planeNormal_2d, line_p1_2d, line_p2_2d); // Gizmos.DrawWireSphere(intersectionPoint.ToVector3(), 0.2f); //} //Gizmos.DrawLine(line_p1, line_p2); //Display with mesh //Plane TestAlgorithmsHelpMethods.DisplayPlaneMesh(planePos_2d, planeNormal_2d, 0.5f, Color.blue); //Line TestAlgorithmsHelpMethods.DisplayLineMesh(line_p1_2d, line_p2_2d, 0.5f, Color.white); if (isIntersecting) { MyVector2 intersectionPoint = _Intersections.GetLinePlaneIntersectionPoint(plane, line); TestAlgorithmsHelpMethods.DisplayCircleMesh(intersectionPoint, 1f, 20, Color.red); } }
private HashSet <Edge2> LoadMap(string mapName) { TextAsset mapTextAsset = Resources.Load(mapName) as TextAsset; string[] mapLines = mapTextAsset.text.Split('\n'); string[] dimensions = mapLines[0].Split('x'); int mapWidth = int.Parse(dimensions[0]); int mapHeight = int.Parse(dimensions[1]); // Create a hash set of all edges. This is a quick way to get a set of all the edges // and ignore all duplicates in one swing. HashSet <Edge2> edgeSet = new HashSet <Edge2>(); // Start with adding the edges which make up the border // North and South for (int i = 0; i < mapWidth; i++) { Vector2 a = new Vector2(i, 0); Vector2 b = new Vector2(i + 1, 0); edgeSet.Add(new Edge2(a, b)); a = new Vector2(i, mapHeight); b = new Vector2(i + 1, mapHeight); edgeSet.Add(new Edge2(a, b)); } // West and East for (int i = 0; i < mapHeight; i++) { Vector2 a = new Vector2(0, i); Vector2 b = new Vector2(0, i + 1); edgeSet.Add(new Edge2(a, b)); a = new Vector2(mapWidth, i); b = new Vector2(mapWidth, i + 1); edgeSet.Add(new Edge2(a, b)); } // Get edges from all wall blocks for (int y = 0; y < mapHeight; y++) { int lineNum = mapHeight - y; for (int x = 0; x < mapWidth; x++) { if (mapLines[lineNum][x] == 'w') { // North edge Vector2 a = new Vector2(x, y + 1); Vector2 b = new Vector2(x + 1, y + 1); Edge2 edge = new Edge2(a, b); if (!edgeSet.Remove(edge)) { edgeSet.Add(edge); } // South edge a = new Vector2(x, y); b = new Vector2(x + 1, y); edge = new Edge2(a, b); if (!edgeSet.Remove(edge)) { edgeSet.Add(edge); } // West edge a = new Vector2(x, y); b = new Vector2(x, y + 1); edge = new Edge2(a, b); if (!edgeSet.Remove(edge)) { edgeSet.Add(edge); } // East edge a = new Vector2(x + 1, y); b = new Vector2(x + 1, y + 1); edge = new Edge2(a, b); if (!edgeSet.Remove(edge)) { edgeSet.Add(edge); } } } } return(edgeSet); }
// Use this for initialization void Start() { //NEW UI ---------------------------------------------- m_headerRect = new Rect(0,0,Screen.width,m_btnH); m_drawRect = new Rect(0,-m_drawMenus.Length* m_btnH,m_btnWL,m_drawMenus.Length* m_btnH); m_tmpDrawRect = new Rect(0,m_btnH,m_btnWL,m_btnH); // m_planRect = new Rect(m_btnW,-m_planMenus.Length* m_btnH,m_btnWL,m_planMenus.Length* m_btnH); m_planRect = new Rect(m_btnW,-m_planMenus.Length* m_btnH,m_btnWL,m_btnH); m_tmpPlanRect = new Rect(0,m_btnH,m_btnWL,m_btnH); m_paramRect = new Rect(2*m_btnW,-m_paramMenus.Length* m_btnH,m_btnWL*1.25f,m_paramMenus.Length* m_btnH); m_tmpParamRect = new Rect(0,m_btnH,m_btnWL*1.25f,m_btnH); m_mainView = new Rect(0,m_btnH,Screen.width,Screen.height-(2*m_btnH)); m_askRect = new Rect(Screen.width/3f,Screen.height/4f,Screen.width/3f,Screen.height/4f); //NEW UI ---------------------------------------------- if(_backgroundImg == null) Debug.LogError(DEBUGTAG+"Background Image"+PC.MISSING_REF); GameObject cameraGameObject = GameObject.Find ("PlanCamera"); _planCamera = cameraGameObject.GetComponent<Camera>(); _mainCamera = GameObject.Find ("mainCam"); _renderCamera = Camera.main; _polyDrawer = cameraGameObject.GetComponent <PolygonDrawer> (); _snapper = cameraGameObject.GetComponent <Snapper> (); _planTransformation = cameraGameObject.GetComponent <PlanTransformation> (); _planCamera.GetComponent<Camera>().enabled = false; _polyDrawer.enabled = false; _planTransformation.enabled = false; enabled = false; Point2 prevBgPoint = new Point2 (UnityEngine.Screen.width / 2 - 50, UnityEngine.Screen.height / 2); Point2 nextBgPoint = new Point2 (UnityEngine.Screen.width / 2 + 50, UnityEngine.Screen.height / 2); _backgroundEdge = new Edge2 (prevBgPoint, nextBgPoint); prevBgPoint.SetNextEdge (_backgroundEdge); nextBgPoint.SetPrevEdge (_backgroundEdge); }
public void DrawPolygonFilled(ITransformation transformation, IEnumerable<Vector2> vectors, ushort? colorOverride = null, byte? pixelOverride = null) { var transformedVectors = vectors .Select(transformation.Transform) .ToList(); var yMax = (int) System.Math.Ceiling(transformedVectors.Max(vector => vector.Y)); var yMin = (int) System.Math.Floor(transformedVectors.Min(vector => vector.Y)); var edges = GetPolygonEdges(transformedVectors); for (var scanlineY = yMin; scanlineY <= yMax; scanlineY++) { var yEdgeIntersections = edges .Where(edge => edge.IsYValueOnEdge(scanlineY)) .Select(edge => edge.GetPointFromY(scanlineY)) .ToList(); var xSortedIntersections = yEdgeIntersections.OrderBy(vector => vector.X).ToList(); var index1 = 0; var index2 = 1; while (index2 < xSortedIntersections.Count) { var point1 = xSortedIntersections[index1]; var point2 = xSortedIntersections[index2]; var line = new Edge2(point1, point2); var startX = point1.X; var endX = point2.X; for (var x = startX; x <= endX; x++) { var point = new Vector2(x, scanlineY); DrawPoint(Transformation.None, point, colorOverride, pixelOverride); } index1 += 2; index2 += 2; } } }
public void ResetSelection() { _selectedPointIndex = -1; _selectedPoint = null; _selectedEdgeIndex = -1; _selectedEdge = null; }
public void InsertPoint(Edge2 edge, Point2 point) { int edgeAndPointIndex = _edges.IndexOf (edge); if (edgeAndPointIndex < 0) return; Point2 nextPoint = edge.GetNextPoint2 (); Edge2 newEdge = new Edge2 (point, nextPoint); edge.SetNextPoint2 (point); point.SetEdges (edge, newEdge); nextPoint.SetPrevEdge (newEdge); _edges.Insert (edgeAndPointIndex + 1, newEdge); _points.Insert (edgeAndPointIndex + 1, point); Point2 prevPoint = edge.GetPrevPoint2 (); prevPoint.Update (false); point.Update (false); nextPoint.Update (false); UpdateBounds (); }
protected void FindIntersectedEdge() { _selectedEdgeIndexCandidate = -1; int edgeCounter = 0; float scale = 1 / _planTransformation.GetScale ().x; float pr = POINT_RADIUS * scale; // pour chaque edge on crée un rectangle de l'epaisseur POINT_RADIUS * currentScale // et de la longueur de l'edge. Puis on applique une transformation au curseur correspondant // a l'orientation de l'edge. Et on verifie que le curseur intersecte le rectangle. foreach (Edge2 edge in _polygon.GetEdges ()) { Point2 prevPoint = edge.GetPrevPoint2 (); Point2 prevEdgePoint = new Point2 (prevPoint); if (prevPoint.GetJunction () == JunctionType.Curved) { ArchedPoint2 aPoint = prevPoint as ArchedPoint2; prevEdgePoint.Set (aPoint.GetNextTangentPoint ()); } Point2 nextPoint = edge.GetNextPoint2 (); Point2 nextEdgePoint = new Point2 (nextPoint); if (nextPoint.GetJunction () == JunctionType.Curved) { ArchedPoint2 aPoint = nextPoint as ArchedPoint2; nextEdgePoint.Set (aPoint.GetPrevTangentPoint ()); } Edge2 transformedEdge = new Edge2 (prevEdgePoint, nextEdgePoint); Vector2 prevPt = transformedEdge.GetPrevPoint2 (); prevPt.Set(prevPt.x+_offsetWidth, prevPt.y+_offsetHeight); Vector2 nextPt = transformedEdge.GetNextPoint2 (); nextPt.Set(nextPt.x+_offsetWidth, nextPt.y+_offsetHeight); Vector3 translation = new Vector3 (prevPt.x, 0, prevPt.y); Matrix4x4 translationMatrix = Matrix4x4.TRS (translation, Quaternion.identity, Vector3.one); Vector3 edgeVector = new Vector3 (transformedEdge.ToVector2 ().x, 0, transformedEdge.ToVector2 ().y); Quaternion rotation = Quaternion.FromToRotation (edgeVector, Vector3.right); Matrix4x4 rotationMatrix = Matrix4x4.TRS (Vector3.zero, rotation, Vector3.one); Matrix4x4 edgeMatrix = translationMatrix * rotationMatrix * translationMatrix.inverse; Vector3 transformedCursor3 = edgeMatrix.MultiplyPoint (new Vector3 (_cursor.x, 0, _cursor.y)); Vector2 transformedCursor = new Vector2 (transformedCursor3.x, transformedCursor3.z); Rect edgeRect = new Rect (prevPt.x + (pr / 2), prevPt.y - (pr / 2), transformedEdge.GetLength () - pr, pr); if (edgeRect.Contains (transformedCursor)) { _selectedEdgeIndexCandidate = edgeCounter; // Debug.Log ("EDGE " + edgeCounter); } ++edgeCounter; } }
public void AddNewEdgeFromFaceSplit(Edge2 e) { Edges.Add(e); m_FinalFaceCreator.AddEdge(e); }
public void AddPoint(Point2 point) { if (_points.Count > 0) { Point2 lastPoint = _points[_points.Count - 1]; Edge2 edge = new Edge2 (lastPoint, point); _edges.Add (edge); lastPoint.SetNextEdge (edge); point.SetPrevEdge (edge); } _points.Add (point); point.Update (); UpdateBounds (); }
public void SetEdges(Edge2 prevEdge, Edge2 nextEdge) { _prevEdge = prevEdge; _nextEdge = nextEdge; Update (); }
// ferme le polygon public void Close() { Point2 firstPoint = _points[0]; Point2 lastPoint = _points[_points.Count - 1]; Edge2 edge = new Edge2 (lastPoint, firstPoint); _edges.Add (edge); firstPoint.SetPrevEdge (edge); lastPoint.SetNextEdge (edge); _closed = true; //Debug.Log ("AREA " + GetArea ()); if (GetArea () > 0) { //Debug.Log ("Reverse Polygon"); _points.Reverse (); _edges.Reverse (); for (int i = 0; i < _points.Count; ++i) { Point2 currentPoint = _points[i]; Point2 nextPoint = _points[i + 1]; Edge2 prevEdge = _edges[i - 1]; Edge2 currentEdge = _edges[i]; currentEdge.SetPrevPoint2 (currentPoint); currentEdge.SetNextPoint2 (nextPoint); currentPoint.SetPrevEdge (prevEdge); currentPoint.SetNextEdge (currentEdge); } } UpdateBounds (); }
public void SetPrevEdge(Edge2 prevEdge) { _prevEdge = prevEdge; Update (); }
private bool IsNewlyFormedEdge(Edge2 e) { return(e.EdgeP1 != null); }