//---------------------------------PRIVATES-------------------------------------// /** * Sets an end as vertex (starting point if none end were defined, ending point otherwise) * * @param vertex the vertex that is an segment end * @return false if all the ends were already defined, true otherwise */ private bool SetVertex(Vertex vertex) { //none end were defined - define starting point as VERTEX if (index == 0) { startVertex = vertex; startType = VERTEX; StartDist = line.ComputePointToPointDistance(vertex.GetPosition()); startPos = startVertex.GetPosition(); index++; return(true); } //starting point were defined - define ending point as VERTEX if (index == 1) { endVertex = vertex; endType = VERTEX; endDist = line.ComputePointToPointDistance(vertex.GetPosition()); endPos = endVertex.GetPosition(); index++; //defining middle based on the starting point //VERTEX-VERTEX-VERTEX if (startVertex.Equals(endVertex)) { middleType = VERTEX; } //VERTEX-EDGE-VERTEX else if (startType == VERTEX) { middleType = EDGE; } //the ending point distance should be smaller than starting point distance if (StartDist > endDist) { SwapEnds(); } return(true); } else { return(false); } }
public double GetArea() { //area = (a * c * sen(B))/2 Vector3 p1 = v1.GetPosition(); Vector3 p2 = v2.GetPosition(); Vector3 p3 = v3.GetPosition(); Vector3 xy = new Vector3(p2.x - p1.x, p2.y - p1.y, p2.z - p1.z); Vector3 xz = new Vector3(p3.x - p1.x, p3.y - p1.y, p3.z - p1.z); double a = (p1 - p2).Length; double c = (p1 - p3).Length; double B = Vector3.CalculateAngle(xy, xz); return((a * c * Math.Sin(B)) / 2d); }
/** * Sets an end as edge (starting point if none end were defined, ending point otherwise) * * @param vertex1 one of the vertices of the intercepted edge * @param vertex2 one of the vertices of the intercepted edge * @return false if all ends were already defined, true otherwise */ private bool SetEdge(Vertex vertex1, Vertex vertex2) { Vector3 point1 = vertex1.GetPosition(); Vector3 point2 = vertex2.GetPosition(); Vector3 edgeDirection = new Vector3(point2.x - point1.x, point2.y - point1.y, point2.z - point1.z); Line edgeLine = new Line(edgeDirection, point1); if (index == 0) { startVertex = vertex1; startType = EDGE; startPos = line.ComputeLineIntersection(edgeLine); StartDist = line.ComputePointToPointDistance(startPos); middleType = FACE; index++; return(true); } else if (index == 1) { endVertex = vertex1; endType = EDGE; endPos = line.ComputeLineIntersection(edgeLine); endDist = line.ComputePointToPointDistance(endPos); middleType = FACE; index++; //the ending point distance should be smaller than starting point distance if (StartDist > endDist) { SwapEnds(); } return(true); } else { return(false); } }