Hi yes the calculation itself is quite straightforward, all you need to know is the width of the machine:
public PVector asNativeCoords(float cartX, float cartY)
{
float distA = dist(0,0,cartX, cartY);
float distB = dist(getWidth(),0,cartX, cartY);
PVector pgCoords = new PVector(distA, distB);
return pgCoords;
}
public PVector asCartesianCoords(PVector pgCoords)
{
float calcX = int((pow(getWidth(), 2) - pow(pgCoords.y, 2) + pow(pgCoords.x, 2)) / (getWidth()*2));
float calcY = int(sqrt(pow(pgCoords.x,2)-pow(calcX,2)));
PVector vect = new PVector(calcX, calcY);
return vect;
}
https://github.com/euphy/polargraphcontroller/blob/master/Machine.pde#L314-L329
It's made a bit complicated by having to convert units around (steps to mm to pixels etc) which gets a bit messy.
Polargraphlib was intended to do exactly that, be a general-purpose library that could be plugged into a processing sketch and would automatically "draw" lines as the app drew them. Never really got moving. Rolling back into java after being a free man (using Python) made me too sad.
|