public IMask GetQuarterFadedCircle(int radius, float fade, IInterpolation interpolation) { if (radius < 0 || fade > 1 || fade < 0) { throw new ArgumentException(); } int fadeBegin = (int)(radius * (1 - fade)); var brushmask = new Mask(new Vector2(radius, radius)); for (int y = 0; y < radius; y++) { var li = (int)JryMath.Sqrt(radius * radius - (radius - y) * (radius - y)); for (int x = 0; x < li; x++) { var yCor = radius - y; float val = 1; var dis = JryMath.Sqrt(x * x + yCor * yCor); if (dis > fadeBegin) { val = interpolation.Interpolate(1, 0, (dis - fadeBegin) / (radius - fadeBegin)); } brushmask[x, yCor - 1] = val; } } return(brushmask); }
public Vector2 getParabalaeIntersection(Parabola left, Parabola right, double directixY) { if (left == null || right == null || left.Site == right.Site) { throw new Exception("NoIntersectoinFound"); } double denominator1 = 2.0f * (left.Site.Y - directixY); //#warning quickfix if (denominator1 == 0) { denominator1 = 0.000001; } double a1 = 1.0f / denominator1; double b1 = -2.0f * left.Site.X / denominator1; double c1 = ((left.Site.X * left.Site.X) + (left.Site.Y * left.Site.Y) - (directixY * directixY)) / denominator1; //y + dp / 4 + px * px / dp double denominator2 = 2.0f * (right.Site.Y - directixY); //#warning quickfix if (denominator2 == 0) { denominator2 = 0.000001; } double a2 = 1.0f / denominator2; double b2 = -2.0f * right.Site.X / denominator2; double c2 = ((right.Site.X * right.Site.X) + (right.Site.Y * right.Site.Y) - (directixY * directixY)) / denominator2; double a = a1 - a2; double b = b1 - b2; double c = c1 - c2; double x1 = 0, x2 = 0; if (a == 0)// 0 = bx +c { x1 = -c / b; x2 = x1; } else //0 = ax^2 + bx + c { double disc = b * b - 4 * a * c; if (disc < 0)// when everything is ok. this case become imposible { throw new InvalidOperationException("Negative discriminant root not found in real domain"); } x1 = (-b + JryMath.Sqrt(disc)) / (2 * a); x2 = (-b - JryMath.Sqrt(disc)) / (2 * a); } double x; if (left.Site.Y < right.Site.Y) { x = JryMath.Max(x1, x2); } else { x = JryMath.Min(x1, x2); } double y; // i have chosen to use left parabola to get Y coor; y = a1 * x * x + b1 * x + c1; return(new Vector2((float)x, (float)y)); }