private List<KeyValuePair<Segment, double>> CalcSidesHypotenuseUnknown(RightTriangle tri, Angle knownAngle, double knownAngleVal, Segment knownSide, double sideVal) { List<KeyValuePair<Segment, double>> pairs = new List<KeyValuePair<Segment, double>>(); Segment hypotenuse = tri.GetHypotenuse(); Segment oppSideOfAngle = tri.GetOppositeSide(knownAngle); Segment adjacent = knownAngle.OtherRay(hypotenuse); if (oppSideOfAngle.StructurallyEquals(knownSide)) { double adjVal = sideVal / Math.Tan(Angle.toRadians(knownAngleVal)); pairs.Add(new KeyValuePair<Segment, double>(adjacent, adjVal)); pairs.Add(new KeyValuePair<Segment, double>(hypotenuse, Math.Sqrt(sideVal * sideVal + adjVal * adjVal))); } else if (adjacent.StructurallyEquals(knownSide)) { double oppVal = sideVal * Math.Tan(Angle.toRadians(knownAngleVal)); pairs.Add(new KeyValuePair<Segment, double>(oppSideOfAngle, oppVal)); pairs.Add(new KeyValuePair<Segment, double>(hypotenuse, Math.Sqrt(sideVal * sideVal + oppVal * oppVal))); } return pairs; }
// // Is the given angle directly exterior to this triangle? // // The triangle must share a side with the angle, the non-shared side must extend the adjacent side public bool HasExteriorAngle(Angle extAngle) { // Disallow any angle in this triangle (since it technically satisfies the requirements) if (HasAngle(extAngle)) return false; // Determine which angle in the triangle has the same vertex as the input angle Angle triangleAngle = GetAngleWithVertex(extAngle.GetVertex()); if (triangleAngle == null) return false; // Acquire the ray that is shared between the angle and the triangle Segment sharedSegment = triangleAngle.SharedRay(extAngle); if (sharedSegment == null) return false; // Acquire the other side of the triangle Segment otherTriangleSegment = triangleAngle.OtherRay(sharedSegment); if (otherTriangleSegment == null) return false; // Acquire the ray that is not shared Segment exteriorSegment = extAngle.OtherRay(sharedSegment); if (exteriorSegment == null) return false; // DISALLOW ALLOW // / / // / \ / \ // /TRI\ /TRI\ // /-----\ /-----\ // / \ // / \ // / \ return otherTriangleSegment.IsCollinearWith(exteriorSegment); }
// // // Given 1 side of a right triangle and an angle, calculate the other 2 sides. // // private List<KeyValuePair<Segment, double>> CalcSidesHypotenuseKnown(RightTriangle tri, Angle knownAngle, double knownAngleVal, Segment hypotenuse, double hypotVal) { List<KeyValuePair<Segment, double>> pairs = new List<KeyValuePair<Segment, double>>(); double oppSideLength = hypotVal * Math.Sin(Angle.toRadians(knownAngleVal)); pairs.Add(new KeyValuePair<Segment,double>(tri.GetOppositeSide(knownAngle), oppSideLength)); double adjSideLength = hypotVal * Math.Cos(Angle.toRadians(knownAngleVal)); pairs.Add(new KeyValuePair<Segment, double>(knownAngle.OtherRay(hypotenuse), adjSideLength)); return pairs; }