Skip to main content
added 31 characters in body
Source Link
Gareth Rees
  • 50.1k
  • 3
  • 130
  • 211

Here's an exaplanationexplanation of how you can derive the isometric coordinate transformation and its inverse. Let's take the forward transformation first. You start with Cartesian coordinates \$x, y\$ and you want isometric coordinates \$ix, iy\$.

enter image description here

Here's an exaplanation of how you can derive the isometric coordinate transformation and its inverse. Let's take the forward transformation first. You start with Cartesian coordinates \$x, y\$ and you want isometric coordinates \$ix, iy\$.

Here's an explanation of how you can derive the isometric coordinate transformation and its inverse. Let's take the forward transformation first. You start with Cartesian coordinates \$x, y\$ and you want isometric coordinates \$ix, iy\$.

enter image description here

explain the coordinate transformations
Source Link
Gareth Rees
  • 50.1k
  • 3
  • 130
  • 211

4. Isometric coordinates

Here's an exaplanation of how you can derive the isometric coordinate transformation and its inverse. Let's take the forward transformation first. You start with Cartesian coordinates \$x, y\$ and you want isometric coordinates \$ix, iy\$.

It's easiest to work this out if you introduce an intermediate set of coordinates: uniform isometric coordinates \$ux, uy\$ where the scale is the same in both dimensions (the diamonds are squares) and the height and width of each diamond is 1.

Now, the transformations are easy: to go from Cartesian coordinates to uniform isometric coordinates we use: $$ \eqalign{ ux &= {y + x \over 2} \cr uy &= {y - x \over 2} } $$ and then from uniform to plain isometric coordinates we use scale factors \$sx, sy\$: $$ \eqalign{ ix &= ux·sx \cr iy &= uy·sy } $$ Putting these together: $$ \eqalign{ ix &= (y + x){sx\over2} \cr iy &= (y - x){sy\over2} } $$ To reverse the transformation, treat these as simultaneous equations and solve for \$x\$ and \$y\$: $$ \eqalign{ x &= {ix\over sx} - {iy\over sy} \cr y &= {ix\over sx} + {iy\over sy}} $$

(These formulae aren't quite the same as the ones I used in the code above, but that's because your backwards block numbering scheme required me to swap \$x\$ and \$y\$, and because your size_x_sm is half of the scale factor \$sx\$.)

4. Isometric coordinates

Here's an exaplanation of how you can derive the isometric coordinate transformation and its inverse. Let's take the forward transformation first. You start with Cartesian coordinates \$x, y\$ and you want isometric coordinates \$ix, iy\$.

It's easiest to work this out if you introduce an intermediate set of coordinates: uniform isometric coordinates \$ux, uy\$ where the scale is the same in both dimensions (the diamonds are squares) and the height and width of each diamond is 1.

Now, the transformations are easy: to go from Cartesian coordinates to uniform isometric coordinates we use: $$ \eqalign{ ux &= {y + x \over 2} \cr uy &= {y - x \over 2} } $$ and then from uniform to plain isometric coordinates we use scale factors \$sx, sy\$: $$ \eqalign{ ix &= ux·sx \cr iy &= uy·sy } $$ Putting these together: $$ \eqalign{ ix &= (y + x){sx\over2} \cr iy &= (y - x){sy\over2} } $$ To reverse the transformation, treat these as simultaneous equations and solve for \$x\$ and \$y\$: $$ \eqalign{ x &= {ix\over sx} - {iy\over sy} \cr y &= {ix\over sx} + {iy\over sy}} $$

(These formulae aren't quite the same as the ones I used in the code above, but that's because your backwards block numbering scheme required me to swap \$x\$ and \$y\$, and because your size_x_sm is half of the scale factor \$sx\$.)

oops, bug
Source Link
Gareth Rees
  • 50.1k
  • 3
  • 130
  • 211
    n = self.draw_data.segments
    g = self.draw_data.block_to_game
    for x, y, z in itertools.product(range(n), repeat=3):
        i = self.draw_data.block_index(x, y, z)
        if self.C3DObject.grid_data[i] != '':
            square = [g(x, y, z),
                      g(x + 1, y, z),
                      g(x + 1, y + 1, z),
                      g(x, y + 1, z)]
    n = self.draw_data.segments
    g = self.draw_data.block_to_game
    for x, y, z in itertools.product(range(n), repeat=3):
        i = self.draw_data.block_index(x, y, z)
        if self.C3DObject.grid_data[i]:
            square = [g(x, y, z),
                      g(x + 1, y, z),
                      g(x + 1, y + 1, z),
                      g(x, y + 1, z)]
    n = self.draw_data.segments
    g = self.draw_data.block_to_game
    for x, y, z in itertools.product(range(n), repeat=3):
        i = self.draw_data.block_index(x, y, z)
        if self.C3DObject.grid_data[i] != '':
            square = [g(x, y, z),
                      g(x + 1, y, z),
                      g(x + 1, y + 1, z),
                      g(x, y + 1, z)]
deleted 78 characters in body
Source Link
Gareth Rees
  • 50.1k
  • 3
  • 130
  • 211
Loading
GridDrawData comments
Source Link
Gareth Rees
  • 50.1k
  • 3
  • 130
  • 211
Loading
better name
Source Link
Gareth Rees
  • 50.1k
  • 3
  • 130
  • 211
Loading
Source Link
Gareth Rees
  • 50.1k
  • 3
  • 130
  • 211
Loading