La curva cardioide es llamada así por su parecido razonable a un corazón.
Su ecuación polar es r = a * (1 + cosA). Sus ecuaciones paramétricas son: x = a * (1 + cosA); y = A.
Como siempre, la representación se realiza con JavaScript
Para representar la espiral usando JavaScript usaremos los siguientes valores: el contenedor de los ejes es
400x400
(pxs); el origen es el punto
(200,200)
y cada unidad es de
30 pxs. El diferencial es
PI/40.
Utilizaremos la fórmula: r = a * (1 + cos(A + b*PI/2)), donde r es la distancia al origen y
A es el ángulo de giro (varía entre 0 y 2PI); a y b son constantes.
Haga click en las cardioides de la lista que toman distintos valores para las constantes a y b.
Esta es una página que implementa las funciones
dibujaCurvaCardioide(a),
dibujaPunto(m, n,txt)
y
ejes_cartesianos(origenX, origenY, pixelunid). El código *.css no es trivial y debería modificarse con sumo cuidado.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta name="generator" content="PSPad editor, www.pspad.com">
<title>
CURVA CARDIOIDE
</title>
<style type="text/css">
a{ text-decoration:none;}
DIV.contenedorejes { background-color : black; width: 400; height : 400;clear : left; position : relative; left : 0px; top : 0px;}
DIV.ejeX{ width : 2px; height : 3px; clear : left; position : absolute; font-size : 0px; background-color : white; }
DIV.ejeXcompleto{ clear : left; position : absolute; font-size : 0px; background-color : white; }
DIV.ejeY{ width : 3px; height : 2px; clear : left; position : absolute; font-size : 0px; background-color : white; }
DIV.ejeYcompleto{ clear : left; position : absolute; font-size : 0px; background-color : white; }
DIV.punto{ width : 3px; height : 3px; clear : left; position : absolute; font-size : 0px; background-color : blue; }
DIV.texto{ clear : left; position : absolute; font-size : 11px; color :red; }
</style>
<script type="text/javascript">
// ancho y alto del contenedor
var ancho = 400;
var alto = 400;
var x0 = 0;
var y0 = 0;
var unid_long;
var diferencial = Math.PI/40;
if(navigator.appVersion.indexOf("MSIE") != -1) var IE = true;
function ejes_cartesianos(origenX,origenY,pixelunid){
document.getElementById('contenedorejes').innerHTML = "";
// origenes de coordenadas
x0 = origenX;
y0 = origenY;
// longitud unidades
unid_long = pixelunid;
// numero de unidades eje x+
var num_unids_x_p = (ancho-x0)/unid_long;
// numero de unidades eje x-
var num_unids_x_n = x0/unid_long;
// numero unidades eje y+
var num_unids_y_p = y0/unid_long;
// numero unidades eje y-
var num_unids_y_n = (alto-y0)/unid_long;
// EJES
// EJE X completo
x = 0;
y = y0;
punto= document.createElement("div");
if(IE) punto.setAttribute("className","ejeXcompleto");
else punto.setAttribute("class","ejeXcompleto");
punto.style.left = x + "px";
punto.style.top = y + "px";
punto.style.width = ancho + "px";
punto.style.height = 1 + "px";
document.getElementById('contenedorejes').appendChild(punto);
// eje x divisiones
// eje x +
for(i=0;i<=num_unids_x_p;i++){
x = x0 + i*unid_long;
y = y0;
punto= document.createElement("div");
if(IE) punto.setAttribute("className","ejeX");
else punto.setAttribute("class","ejeX");
punto.style.left = x + "px";
punto.style.top = y + "px";
document.getElementById('contenedorejes').appendChild(punto);
}
// eje x-
for(i=0;i<=num_unids_x_n;i++){
x = x0 - i*unid_long;
y = y0;
punto= document.createElement("div");
if(IE) punto.setAttribute("className","ejeX");
else punto.setAttribute("class","ejeX");
punto.style.left = x + "px";
punto.style.top = y + "px";
document.getElementById('contenedorejes').appendChild(punto);
}
// EJE Y
// EJE Y completo
x = x0;
y = 0;
punto= document.createElement("div");
if(IE) punto.setAttribute("className","ejeXcompleto");
else punto.setAttribute("class","ejeXcompleto");
punto.style.left = x + "px";
punto.style.top = y + "px";
punto.style.width = 1 + "px";
punto.style.height = alto + "px";
document.getElementById('contenedorejes').appendChild(punto);
// eje y divisiones
// eje y+
for(i=0;i<=num_unids_y_p;i++){
x = x0;
y = y0 - i*unid_long;
punto= document.createElement("div");
if(IE) punto.setAttribute("className","ejeY");
else punto.setAttribute("class","ejeY");
punto.style.left = x + "px";
punto.style.top = y + "px";
document.getElementById('contenedorejes').appendChild(punto);
}
// eje y-
for(i=0;i<=num_unids_y_n;i++){
x = x0;
y = y0 + i*unid_long;
punto= document.createElement("div");
if(IE) punto.setAttribute("className","ejeY");
else punto.setAttribute("class","ejeY");
punto.style.left = x + "px";
punto.style.top = y + "px";
document.getElementById('contenedorejes').appendChild(punto);
}
}
function dibujaPunto(m,n,txt){
var xP = parseFloat(m);
var yP = parseFloat(-n);
x = x0 + xP*unid_long;
y = y0 + yP*unid_long;
punto= document.createElement("div");
if(IE) punto.setAttribute("className","punto");
else punto.setAttribute("class","punto");
punto.style.left = x + "px";
punto.style.top = y + "px";
document.getElementById('contenedorejes').appendChild(punto);
if(txt!= ""){
// el texto que acompaña a los puntos
var texto = txt;
textoPunto = document.createTextNode(texto);
divTexto = document.createElement("div");
if(IE) divTexto.setAttribute("className","texto");
else divTexto.setAttribute("class","texto");
divTexto.style.left = (x+3) + "px";
divTexto.style.top = (y+6) + "px";
divTexto.appendChild(textoPunto);
document.getElementById('contenedorejes').appendChild(divTexto);
}
}
function dibujaCurvaCardioide(a,b){
init();
for (i=0;i<=2*Math.PI; i += diferencial){
r = a*(1+Math.cos(i+b*Math.PI/2));
x = r*Math.cos(i);
y = r*Math.sin(i);
dibujaPunto(x,y,"");
}
}
function init(){
ejes_cartesianos(200,200,30);
dibujaPunto(0,0,'O');
}
</script>
</head>
<body onload="init()" style="left:10px;top:0px;">
<table width="100%">
<tr>
<td>
<p style="font-size:12px">
<a href="javascript:dibujaCurvaCardioide(1,0)">Cardioide <b>a=1</b> y <b>b=0</b></a>
<a href="javascript:dibujaCurvaCardioide(1,1)">Cardioide <b>a=1</b> y <b>b=1</b></a>
<a href="javascript:dibujaCurvaCardioide(1,2)">Cardioide <b>a=1</b> y <b>b=2</b></a>
<a href="javascript:dibujaCurvaCardioide(1,3)">Cardioide <b>a=1</b> y <b>b=3</b></a>
<a href="javascript:dibujaCurvaCardioide(2,0)">Cardioide <b>a=2</b> y <b>b=0</b></a>
<a href="javascript:dibujaCurvaCardioide(2,1)">Cardioide <b>a=2</b> y <b>b=1</b></a>
<a href="javascript:dibujaCurvaCardioide(2,2)">Cardioide <b>a=2</b> y <b>b=2</b></a>
<a href="javascript:dibujaCurvaCardioide(2,3)">Cardioide <b>a=2</b> y <b>b=3</b></a>
</p>
</td>
<td>
<div id="contenedorejes" class="contenedorejes">
</div>
</td>
</tr>
</table>
</body>
</html>