0
\$\begingroup\$
Coordenadas: X:140 Y:279
Coor Isometricas:128/69
X: 2  Y: 1.
CoordenadasConversas: 69:214.

CoordenadasConversas should be equal to Coordenadas.

CoordenadasConversas does not work. The function I use is CoordenadaAIsometrico() - see below.

I applied the formula to convert from isometric to Cartesian, but it does not seem to work.

float cartesianX = (2.0f * isometricY + isometricX) * 0.5f;
float cartesianY = (2.0f * isometricY - isometricX) * 0.5f;

function Isometrico(){

    ctx.save();

    ctx.translate(0, 300);

    ctx.scale(1, 0.5);

    var radianes=-45 * Math.PI /180;

    ctx.rotate(radianes);
}

function CorIsometrico(xI,yI){

    yI=yI-300;

    yI=yI*2;
    var angle = ((-45 * Math.PI /180) * -1)
    var x2 = xI;

    var y2 = yI;
    var cos = Math.cos(angle);
    var sin = Math.sin(angle);

    var xI2 = Math.floor(x2 * cos - y2 * sin);
    var yI2 = Math.floor(x2 * sin + y2 * cos);

    console.log("Coor Isometricas:" + xI2  + "/"+  + yI2 );

    CoordenadaAIsometrico(xI2,yI2);
}

function CoordenadaAIsometrico(Xc,Yc){

    var Xcc = (2 * Yc + Xc) * 0.5;

    var Ycc = (2 * Yc - Xc) * 0.5;

    //Xc=Xc-50;
    //Yc=Yc+300;

    console.log("CoordenadasConversas: " + Xcc + ":" +  Ycc);
} 

\$\endgroup\$
2
  • 2
    \$\begingroup\$ This seems very similar to your previous question. If you're still solving the same issue, I'd recommend editing your original question to update it with your progress / clarifications, rather than posting a near-duplicate. \$\endgroup\$
    – DMGregory
    May 22, 2019 at 10:41
  • \$\begingroup\$ It is not the same. Before I was able to get the isometric coordinates by clicking with the mouse to find out which cell I'm pressing. Now it is to reverse that in order to apply a search algorithm and be able to move a character for each cell. Before Cartesian to isometric coordinates, now from isometric to Cartesian. \$\endgroup\$
    – Albert
    May 22, 2019 at 14:01

1 Answer 1

1
\$\begingroup\$

enter image description here

Thanks. The answer was to reverse your formula:

function IsometricoACartesiano(xI5,yI5){
    var angle2 = ((45 * Math.PI /180) * -1);
    var x22 = xI5;
    var y22 = yI5;
    var cos = Math.cos(angle2);
    var sin = Math.sin(angle2);

    var xI2 = Math.floor(x22 * cos - y22 * sin);
    var yI2 = Math.floor(x22 * sin + y22 * cos);
    yI2=yI2/2;
    yI2=yI2+300;
    console.log("U: " + xI2 + "/" + yI2 );
    context.restore();
    context.drawImage(habbo, xI2, yI2,ancho,alto);
  }
\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .