ijprest / keyboard-layout-editor

Web application to enable the design & editing of keyboard layouts
http://www.keyboard-layout-editor.com/
Other
1.3k stars 241 forks source link

Rotation: X/Y coordinates displayed wrong #284

Open ursaw opened 4 years ago

ursaw commented 4 years ago

Using builtin Ergodox. When clicking on an rotated keys in a row the X,Y coordinates looks odd:

I assume that X and Y should be displayed in global (unrotated, unmoved) coordiante system.

But the display in this example is somehow a mix of global and local (rotated, moved) coordinate system. Looks like it is adding [rx, ry] (global) to [delta_x, delta_y] (local) which is wrong.

First key Second key
image image
adamws commented 3 years ago

Coordinates notion for rotated keys is perhaps counterintuitive but it actually makes sense. This is how I imagine this: all keys share default coordinate system (red) untill they are not rotated. Each rotated key have own coordinate system but it's origin is not always (0,0) and can be defined. In ergodox example all of these rotated keys are rotated by 30° and rotation origin is equal (6.5,4.25) (green coordinate system). X/Y for these keys are in this coordinate system (and that is why X is incremented by 1 and Y stays the same for key pair you mentioned). image

ursaw commented 3 years ago

Hi, thanks for your comment. This is how I understand it as well, the problem is that the X and Y values are somehow useless, because they are a mix of all introduced coordinate systems. If you are interested in the global absolute positions, which you will need f.e. for plotting you have to trace the full chain of coordinate changes. The displayed coordinate in the above example is not very help full.

Therefore I would like to suggest to display the absolute coordinates (red in your example) next to the kle/chain/local coordinates.

Another solution would be more proper documentation, which I surely could contribute

But I must admit that this would be not so interesting for the majority of keyboard layouts, because most dont have rotations and multiple coordinate systems. But ergo boards have :-)

I was facing thins problem when trying to implement rotations for ai03-2725/another-keyboard-builder#13

adamws commented 3 years ago

If you are interested in the global absolute positions, which you will need f.e. for plotting you have to trace the full chain of coordinate changes. The displayed coordinate in the above example is not very help full.

Although absolute position in not explicit, it can be easily calculated: rotating (x, y) by angle around reference point (rotation_x, rotation_y) will get you what you want.

See this: https://stackoverflow.com/a/34374437