using System; using System.Numerics; public class Test { static float LinearFormula(float x, Vector2 a, Vector2 b) { float slope = (b.Y - a.Y) / (b.X - a.X); float dx = x - a.X; float dy = slope * dx; return dy + a.Y; } static float CossineFormula(float x) { return Math.Abs(x) - (float) Math.Cos(x * 3); } static float MyFormula(float x, Vector2 a, Vector2 b) { return CossineFormula(x) - LinearFormula(x, a, b); } static Vector2 FindIntersection(Vector2 a, Vector2 b) { float x1 = 2; float x2 = 3; for (int i = 0; i < 100; i++) { float d = (x2 + x1) / 2; if (d == x1 || d == x2) break; float v3 = MyFormula(d, a, b); if (v3 > 0) { x2 = d; } else { x1 = d; } } return new Vector2(x1, CossineFormula(x1)); } public static void Main() { Console.WriteLine(FindIntersection(new Vector2(0, 4), new Vector2(1, 3))); } }