Primitivas Gráficas - Algoritmo de la Ecuación General para Circunferencias
Pre-requisitos:
Instalar OpenGL en Linux (si usas linux)
Instalar OpenGL en Windows (si usas windows)
Inicializar OpenGL en C++
Ecuación General de la circunferencia
$${({x}-{x}_{c})}^{2}+{({y}-{y}_{c})}^{2}={r}^{2}$$
Algoritmo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void circuGeneral(GLint xc, GLint yc, GLint r){ | |
int x; | |
double y1,y2; | |
for(x=xc-r;x<=xc+r ;x+=1){ | |
y1=yc+sqrt(r*r-((x-xc)*(x-xc))); | |
cout<<"y: "<<y1<<"\t"; | |
y2=yc-sqrt(r*r-((x-xc)*(x-xc))); | |
pintarPixel(x,roundf(y1)); | |
pintarPixel(x,roundf(y2)); | |
} | |
} |
Ejemplo
-Dibujar Circunferencia de centro (2,4) y radio 7$$x_c=2, y_c=4, r=7 $$
usando
$$y=y_c+\sqrt { r^2−(xc−x)^2}$$
usando
$$y=y_c-\sqrt { r^2−(xc−x)^2}$$
pintando los puntos calculados:
ver código completo aqui
Comentarios
Publicar un comentario