# Isometric

## Isometric vector projections

Use this class to convert any vector to its relative isometric vector and vice versa.

## Usage

```* Creating a 2d tile based isometric map
* getting a destination point in a 2d isometric game
* convert user inputs ( mouseclicks, etc.)
```

Access the methods in a static way.

```using UnityEngine;
using System.Collections;

public class Foo{

public void bar() {
player.transform.position = Isometric.twoDToIso(Vector3.zero);
}```

## C# - Isometric.cs

```using UnityEngine;
using System.Collections;

/// <summary>
/// Class for isometric transitions
/// Author Marvin Neurath
/// version 21.11.2014
/// </summary>
public class Isometric {

public static Vector3 NORTH =new Vector3(1, .5f, 0);
public static Vector3 WEST = new Vector3(-1, .5f, 0);
public static Vector3 SOUTH = new Vector3(-1, -.5f, 0);
public static Vector3 EAST = new Vector3(1, -.5f, 0);

/// <summary>
/// Converts a 2d view(e.g. top-view) to isometric view
/// </summary>
/// <param name="pt">input vector</param>
/// <returns>transformed vector</returns>
public static Vector2 twoDToIso(Vector2 pt) {
var tempPt = new Vector2(0, 0);
tempPt.x = (pt.x - pt.y);
tempPt.y = (pt.x + pt.y) / 2;
return tempPt;
}
/// <summary>
/// </summary>
/// <param name="x"></param>
/// <param name="y"></param>
/// <returns></returns>
public static Vector2 twoDToIso(int x, int y) {
var tempPt = new Vector2(0, 0);
tempPt.x = (float)(x - y);
tempPt.y = (float)(x + y) / 2;
return tempPt;
}

/// <summary>
/// Converts a vector from isometric view into a 2d view
/// </summary>
/// <param name="pt"></param>
/// <returns></returns>
public static Vector2 isoTo2D(Vector2 pt) {
var tempPt = new Vector2(0, 0);
tempPt.x = (pt.x - pt.y);
tempPt.x = (2 * pt.y + pt.x) / 2;
tempPt.y = (2 * pt.y - pt.x) / 2;
return tempPt;
}

/// <summary>
/// </summary>
/// <param name="x"></param>
/// <param name="y"></param>
/// <returns></returns>
internal static Vector3 isoTo2D(int x, int y) {
var tempPt = new Vector2(0, 0);
tempPt.x = (float)(2 * y + x) / 2;
tempPt.y = (float)(2 * y - x) / 2;
return tempPt;
}
}```