public void SerializationTest() { //45 degre var rhoIntervalCount = 4; var conventer = new Accumulator(4, 4, rhoIntervalCount, 4); var pointF = new PolarPointF() { Rho = 1.22173048, // 70 degre Theta = 4 }; var indexes = conventer.GetAccumulatorIndex(pointF); Assert.AreEqual(2, indexes[0]); Assert.AreEqual(3, indexes[1]); //rho // [0] = 0 - 22,5 // [1] = 22,5 - 67,5 // [2] = 67,5 - 112,5 // [3] = 112,5 - 157,5 // [4] = 157,5 - 180 //theta // [0] = -2.828 - -0.0707 // [1] = -0.707 - 1,141 // [2] = 1,141 - 3,535 // [3] = 3.535 - 5.656 }
private void MoveOverAccumulatorHandler(System.Drawing.Point point) { Stopwatch watch = new Stopwatch(); watch.Start(); Debug.WriteLine("{{X=" + point.X + ", Y=" + point.Y + ", Value=" + _accumulator[point.X, point.Y] + "}}"); var line = _accumulator.GetLineFromIndex(new List <int>() { point.X, point.Y }); var minLine = new PolarPointF() { Rho = line.Rho - _accumulator.RhoDelta / 2, Theta = line.Theta - _accumulator.ThetaDelta / 2, }; var maxLine = new PolarPointF() { Rho = line.Rho + _accumulator.RhoDelta / 2, Theta = line.Theta + _accumulator.ThetaDelta / 2, }; Debug.WriteLine("Minimum: " + minLine); Debug.WriteLine("maximum: " + maxLine); using (Bitmap clone = (Bitmap)Image.FromFile(ImagePath)) { using (var graphics = Graphics.FromImage(clone)) { var tempLine1 = new PolarPointF() { Rho = line.Rho, Theta = minLine.Theta }; var tempLine2 = new PolarPointF() { Rho = line.Rho, Theta = maxLine.Theta }; DrawPolarLine(tempLine1, graphics, new Pen(Color.Chartreuse, 1)); DrawPolarLine(tempLine2, graphics, new Pen(Color.Green, 1)); DrawPolarLine(line, graphics, new Pen(Color.Red, 2)); } Source = clone; } watch.Stop(); Console.WriteLine("move: Measured time: " + watch.Elapsed.TotalMilliseconds + " ms."); }
private static void DrawPolarLine(PolarPointF line, Graphics graphics, Pen pen) { var a = Math.Cos(line.Rho); var b = Math.Sin(line.Rho); var x0 = a * (line.Theta); var y0 = b * (line.Theta); int x1 = (int)(x0 + 1000 * (-b)); int y1 = (int)(y0 + 1000 * (a)); int x2 = (int)(x0 - 1000 * (-b)); int y2 = (int)(y0 - 1000 * (a)); graphics.DrawLine(pen, x1, y1, x2, y2); }
public static PolarPointF GetPolarLineFromCartesianPoints(Tuple <Point, Point> pair) { var dx = pair.Item1.X - pair.Item2.X; var dy = pair.Item1.Y - pair.Item2.Y; var rho = Math.Atan2(dy, dx) - (Math.PI / 2); rho %= Math.PI; var theta = pair.Item1.X * Math.Cos(rho) + pair.Item1.Y * Math.Sin(rho); if (theta < 0) { rho += Math.PI; theta = -theta; } var line = new PolarPointF() { Rho = rho, Theta = theta }; return(line); }
public void PolarPointRhoModuloTest() { var pointF = new PolarPointF(-1, 0); Assert.AreEqual(pointF.Rho, -1 + Math.PI, 0.00001); }