public static void DibujarCirculo(Circulo circulo) { int x0 = circulo.Centro.GetXEntero(); int y0 = circulo.Centro.GetYEntero(); int radius = (int)circulo.Radio; int f = 1 - radius; int ddF_x = 1; int ddF_y = -2 * radius; int x = 0; int y = radius; Gl.glVertex2d(x0, y0 + radius); Gl.glVertex2d(x0, y0 - radius); Gl.glVertex2d(x0 + radius, y0); Gl.glVertex2d(x0 - radius, y0); while (x < y) { // ddF_x == 2 * x + 1; // ddF_y == -2 * y; // f == x*x + y*y - radius*radius + 2*x - y + 1; if (f >= 0) { y--; ddF_y += 2; f += ddF_y; } x++; ddF_x += 2; f += ddF_x; Gl.glVertex2d(x0 + x, y0 + y); Gl.glVertex2d(x0 - x, y0 + y); Gl.glVertex2d(x0 + x, y0 - y); Gl.glVertex2d(x0 - x, y0 - y); Gl.glVertex2d(x0 + y, y0 + x); Gl.glVertex2d(x0 - y, y0 + x); Gl.glVertex2d(x0 + y, y0 - x); Gl.glVertex2d(x0 - y, y0 - x); } }
public static IList ObtenerPuntosEquidistantesCirculo(Circulo circulo, int cantidadPuntos) { if (!(cantidadPuntos % 2 == 0)) throw new InvalidOperationException("Solo se pueden obtener cantidades pares de vértices"); // Vector donde se van a poner todos los puntos IList puntos = new ArrayList(); int x0 = circulo.Centro.GetXEntero(); int y0 = circulo.Centro.GetYEntero(); double radius = circulo.Radio; double f = 1 - radius; int ddF_x = 1; double ddF_y = -2 * radius; int x = 0; double y = radius; puntos.Add(new PuntoFlotante(x0, y0 + radius, circulo.Centro)); puntos.Add(new PuntoFlotante(x0, y0 - radius, circulo.Centro)); puntos.Add(new PuntoFlotante(x0 + radius, y0, circulo.Centro)); puntos.Add(new PuntoFlotante(x0 - radius, y0, circulo.Centro)); while (x < y) { // ddF_x == 2 * x + 1; // ddF_y == -2 * y; // f == x*x + y*y - radius*radius + 2*x - y + 1; if (f >= 0) { y--; ddF_y += 2; f += ddF_y; } x++; ddF_x += 2; f += ddF_x; puntos.Add(new PuntoFlotante(x0 + x, y0 + y, circulo.Centro)); puntos.Add(new PuntoFlotante(x0 - x, y0 + y, circulo.Centro)); puntos.Add(new PuntoFlotante(x0 + x, y0 - y, circulo.Centro)); puntos.Add(new PuntoFlotante(x0 - x, y0 - y, circulo.Centro)); puntos.Add(new PuntoFlotante(x0 + y, y0 + x, circulo.Centro)); puntos.Add(new PuntoFlotante(x0 - y, y0 + x, circulo.Centro)); puntos.Add(new PuntoFlotante(x0 + y, y0 - x, circulo.Centro)); puntos.Add(new PuntoFlotante(x0 - y, y0 - x, circulo.Centro)); } CollectionUtils.Sort(puntos, new ComparadorPuntosCirculo()); int cantidadTotalPuntos = puntos.Count; int cantidadSaltoPuntos = cantidadTotalPuntos / cantidadPuntos; int indice; IList retorno = new ArrayList(); int i; for (i = 0; i <= cantidadPuntos; i++) { indice = (i == 0) ? 0 : (i*cantidadSaltoPuntos) - 1; retorno.Add(puntos[indice]); } return retorno; }