Author Topic: Using Autohotkey to draw a line derivate using freehand tool  (Read 5110 times)

November 16, 2016, 03:04:38 PM
Read 5110 times

Grobe

  • IC Mentor

  • Offline
  • ******
  • User of useful programs

  • 33
  • Gender
    Male

    Male
  • Personal Text
    Can you resist my finger?
Hi folks.

Since Inkscape isn't a math program, I thaught of using Autohotkey to read the pixels along a line and calculate the derivated function and draw this using  :pfh:

Basically I got it to work (the ahk script that performs mouse movement and drawing works as expected).

The problem is - The  :pfh: tool cannot draw lines that has a smoothness of zeero. So instead of a rugged curve form, peaks does transform into small loops instead.
That was entirely my fault because I first expected  :pfh:to act similar to simple pen tool of MS paint, but as you can see I was wrong in that assumption.

I did spend some hours to get the script working, and I have an idea that if I skip some pixels (calculate average) I can overcome this problem, but will end up with a smoother curve (doesn't handle short peaks) and I really doesn't want to spend time for a solution that doesn't work good enough.

Question I hope being answered - How can I (or actually it is my script that does all click and mouse movements) draw a line where I move the mouse pointer one pixel to right each time and preventing the curve being any smooth.
At some time I might find time to write something funny at the signature line - for now I just gave the finger som resistance.

November 27, 2016, 04:00:03 PM
Reply #1

Grobe

  • IC Mentor

  • Offline
  • ******
  • User of useful programs

  • 33
  • Gender
    Male

    Male
  • Personal Text
    Can you resist my finger?
Update.

I've being working out the issue by finding the middle point of a line (at Y direction) by looking at the color shading for each pixel. That is resolved by now. However I still haven't figured out a proper way of drawing (automatic plotting) of a curve bu controlling mouse input.

The best result so far seems to be adding a lot of copies of small dots - at least it resembles a line more properly than last time.
Maybee I will manage Autohotkey to draw a line between dots when zoomed - to get to the final goal of makin an actual line.

There is some other problems too I should resolve. One is that by inserting points and pasting small copies by automatic mouse movements - I get error by lenghts of individual pixels - so when a dot is to be inserted at position (300, 260.25) - it will be rounded to the nearest pixel value.

Can I set up Inkscape so that key combinations Alt+Up and Alt+Down moves any selected object by one tenth pixel length for any zoom level?
At some time I might find time to write something funny at the signature line - for now I just gave the finger som resistance.

November 27, 2016, 08:42:52 PM
Reply #2

brynn

  • Administrator

  • Offline
  • ******

  • 3,941
  • Gender
    Female

    Female
    • Inkscape Community
Hi Grobe,
To be honest, I don't even understand what you're talking about.  But for the question about setting steps for the arrow keys, that is definitely possible.  I'm not sure about Alt Up or Alt Down, but maybe.  In Inkscape Preferences > Interface > Key Shortcuts, you can set custom key shortcuts.  The reason I'm not sure about Alt is because it's what I think is called a modifier key (in Inkscape at least - not sure about otherwise).  But you should be able to figure it out in from this manual info:  http://tavmjong.free.fr/INKSCAPE/MANUAL/html/Transforms.html#Transforms-Keyboard

For setting the step distance, it's Inkscape Preferences > Behavior > Steps.  Those fields offer 4 decimal points (which I'm actually surprised about) so that should easily allow for 0.1 px distance.

Quote (selected)
There is some other problems too I should resolve. One is that by inserting points and pasting small copies by automatic mouse movements - I get error by lenghts of individual pixels - so when a dot is to be inserted at position (300, 260.25) - it will be rounded to the nearest pixel value.

Since I don't understand what you're doing, I'm not sure if you're saying that's a problem with your script, or with Inkscape.  But I think there is a way to set additional decimal points globally in Inkscape.  Let's see if I can find.....  mmfff, I can't seem to find it now.  But I know it's there because I've experimented with changing it.

If it's an Inkscape problem, maybe someone else knows where that option can be found.

Good luck  :)
  • Inkscape version 0.92.3
  • Windows 7 Pro, 64-bit
Inkscape Tutorials (and manuals)                      Inkscape Community Gallery                        Inkscape for Cutting Design                     



"Be ashamed to die until you have won some victory for humanity" - Horace Mann                       

November 28, 2016, 10:34:14 AM
Reply #3

Moini

  • IC Mentor

  • Offline
  • ******

  • 1,568
    • VektorRascheln
There are also a couple of extensions that allow to plot curves - would those be an option?

November 28, 2016, 01:38:15 PM
Reply #4

Grobe

  • IC Mentor

  • Offline
  • ******
  • User of useful programs

  • 33
  • Gender
    Male

    Male
  • Personal Text
    Can you resist my finger?
Yes - that is interresting if the extension somehow allow manually entered vaslues.

Honestly the best approach for drawing an intregral or a derivate of a curve would be using Inkscape itself. But that isn't possible today.
There is other tools that is perfectly fit for the task, such as Geogebra - but input have to be a fuction of x.
At some time I might find time to write something funny at the signature line - for now I just gave the finger som resistance.

November 28, 2016, 02:05:39 PM
Reply #5

Moini

  • IC Mentor

  • Offline
  • ******

  • 1,568
    • VektorRascheln
Mmh. Okay, I think in that case that extension still needs to be written...
Are the points connected by straight lines or do you do some smoothing?

November 29, 2016, 08:30:51 AM
Reply #6

Grobe

  • IC Mentor

  • Offline
  • ******
  • User of useful programs

  • 33
  • Gender
    Male

    Male
  • Personal Text
    Can you resist my finger?
The script I wrote is made so that it calculate the pixel values difference from complete white, so it does smooted lines just well. Therefore it hit the (visually) center of line every time.

When I write/draw the function, i do not need smoothing - i can use Inkscape for that afterwards if I wish.
At some time I might find time to write something funny at the signature line - for now I just gave the finger som resistance.

November 29, 2016, 09:01:55 AM
Reply #7

Moini

  • IC Mentor

  • Offline
  • ******

  • 1,568
    • VektorRascheln
So basically, you have a set of x/y values and want Inkscape to plot that by drawing a straight line from point to point? Did I understand that correctly?

November 29, 2016, 11:01:38 AM
Reply #8

Grobe

  • IC Mentor

  • Offline
  • ******
  • User of useful programs

  • 33
  • Gender
    Male

    Male
  • Personal Text
    Can you resist my finger?
So basically, you have a set of x/y values and want Inkscape to plot that by drawing a straight line from point to point? Did I understand that correctly?
Excactly what I want  :nod:

I think it would work out if I could just enter the coordinates in XML editor - but those coordinates isn't given in same coordinate set? Have a line with 3 nodes by cords (0.00,0.00 80.00,80.00 120.00,240.00) in px - reads very different in xml editor:
m 240,932.362204724 -160,40 -80,79.999999996

And when path is reversed it gives:
m 0,1052.36220472 80,-79.999999996 160,-40

So there is obviously some transformations going on here from Inkscape coordinate system to the visible pixel coordinat on canvas.
At some time I might find time to write something funny at the signature line - for now I just gave the finger som resistance.

November 29, 2016, 11:39:51 AM
Reply #9

Moini

  • IC Mentor

  • Offline
  • ******

  • 1,568
    • VektorRascheln
The coordinate system is reversed in the XML, origin is left upper corner, in contrast to left bottom corner in Inkscape - you need to subtract the y values from the page height (but you may still experience issues caused by transforms or unit conversions).

It's not so hard to make an extension that does this, I think I have all the pieces available already (or maybe it even exists, would need to look around a bit first). What do you need it for?

November 29, 2016, 03:32:25 PM
Reply #10

Moini

  • IC Mentor

  • Offline
  • ******

  • 1,568
    • VektorRascheln
Found one, and it's really rich in features and appears to work very well (tested on Linux Mint 18):
https://inkscape.org/en/~fsmMLK/%E2%98%85cartesianplotdata2d

github, install instructions (really important): https://github.com/fsmMLK/inkscapeCartesianPlotData2D
github, necessary module, with instructions about deactivating LaTeX: https://github.com/fsmMLK/inkscapeMadeEasy