/// <summary> /// vypocita uhly definovane obloukem, uhly jsou v radianech /// </summary> /// <param name="start">pocatecni uhel oblouku</param> /// <param name="angle">uhel sevreny pocatecnim a koncovym bodem oblouky, zaporny uhel - oblouk je ve smeru hodinovych rucicek</param> /// <returns>pokud je objekt empty vrati false</returns> public Circle2D?GetAngles(out double start, out double angle) { Circle2D c = Circle2D; start = angle = 0; if (c.IsEmpty) { return(null); } Vector b = Begin.Minus(c.Center); double ab = Vector.AngleBetween(new Vector(1, 0), b); double a = Vector.AngleBetween(b, End.Minus(c.Center)); if (ab < 0) { ab = 360 + ab; } if (a < 0) { a = 360 + a; } if (Clockwise) { a -= 360; } start = Funcs2D.Radian(ab); angle = Funcs2D.Radian(a); return(c); }
/// <summary> /// vrati tri body na oblouku /// </summary> /// <param name="k2">relativni delkova souradnice druheho bodu</param> /// <returns>vrati pole bodu ret[0] = zacatek, ret[1] = bod na oblouku podle k2, ret[2] = konec</returns> public Point[] ThreePoints(double k2 = 0.5) { if (IsEmpty) { return(null); } var ret = new Point[3]; ret[0] = Begin; Circle2D c = Circle2D; Vector b = Begin.Minus(c.Center); double ab = Vector.AngleBetween(new Vector(1, 0), b); double a = Vector.AngleBetween(b, End.Minus(c.Center)); if (ab < 0) { ab = 360 + ab; } if (a < 0) { a = 360 + a; } if (Clockwise) { a -= 360; } a = ab + (a * k2); ret[1] = c.PointOn(Funcs2D.Radian(a)); ret[2] = End; return(ret); }
/// <summary> /// oblouk zadany stredem , pocatecnim bodem a vektorem ne kterem lezi kocovy bod /// </summary> /// <param name="center">stred</param> /// <param name="pt">pocatecni bod</param> /// <param name="vector">vektor na kterem lezi koncovy bod</param> /// <param name="shortangle">true = kratky oblouk (mezi nulou az 180 stupni), false = dlouhy oblouk (doplnek do 360 stupnu)</param> public Arc2D(Point center, Point pt, Vector vector, bool shortangle = true) { Radius = Funcs2D.Distance(center, pt); Begin = pt; double a = Funcs2D.Radian(Vector.AngleBetween(new Vector(1, 0), vector)); End = Circle2D.PointOn(center, Radius, a); if (!shortangle) { Radius *= -1; } a = Vector.AngleBetween(pt.Minus(center), vector); Clockwise = !(a > 0 && shortangle || a < 0 && !shortangle); }
/// <summary> /// oblouk zadany stredem , pocatecnim bodem a uhlem /// </summary> /// <param name="center">stred</param> /// <param name="pt">pocatecni bod</param> /// <param name="angle">uhel v radianech , smer podle znamenka ( - = clockwise)</param> public Arc2D(Point center, Point pt, double angle) { Radius = Funcs2D.Distance(center, pt); Begin = pt; if (Math.Abs(angle) > Math.PI * 2) { angle = angle % (Math.PI * 2); } Clockwise = angle < 0; double a = Funcs2D.Radian(Vector.AngleBetween(new Vector(1, 0), pt.Minus(center))); a += angle; End = Circle2D.PointOn(center, Radius, a); if (Math.Abs(angle) > Math.PI) { Radius *= -1; } }