Getting XY coordinates of the segments of a rule

Post questions on how to use or achieve an effect in Inkscape.
antecessor
Posts: 8
Joined: Mon Nov 24, 2014 7:10 pm

Getting XY coordinates of the segments of a rule

Postby antecessor » Wed Oct 07, 2015 8:16 am

I have a curved line and because I wanted it to be divided in segments of equal distances, I used a Rule effect.
Pantallazo.png
Sorry, it's in Spanish, but hope you know what I mean with Rule (I don't know if rule is correct English name)
Pantallazo.png (28.91 KiB) Viewed 2227 times


I divided that line in 80 segments, and as you sure know, those divisions are not nodes. You can see the line and its segments here:
Pantallazo-1.png
Pantallazo-1.png (16.8 KiB) Viewed 2227 times


How can I get the XY coordinates of all the segments where they cross the line?

I was using the XML editor and find a huge amount of numbers. I was playing with no succed.

Is there any possibility to export them in .csv, .txt or whatever other format easily. It would be very important for my scientific work.

Thanks

Lazur
Posts: 4580
Joined: Tue Jun 14, 2016 10:38 am

Re: Getting XY coordinates of the segments of a rule

Postby Lazur » Wed Oct 07, 2015 8:53 am

Hi.

Maybe try the add nodes extension instead, then apply the lpe -by converting object to path, Ctrl+Shift+C-, set segments linear and you can copy from the xml editor the coordinate values. (If there are no group transformations applied.)

But at first, in the preferences (Shift+Ctrl+P) set absolute coordinates for path data at svg output settings and restart inkscape.

A related topic, but there should be alot more.

v1nce
Posts: 679
Joined: Wed Jan 13, 2010 4:36 am

Re: Getting XY coordinates of the segments of a rule

Postby v1nce » Wed Oct 07, 2015 9:10 am

This post was edited (it was missing the totalLength of the path)

Not an inkscape solution but javascript got methods for dealing with (svg)path.
getPointAtLength() returns the point located somewhere on the path (start=0; end=1)

save this and open it in chrome/ff and look at the console (F12 or ctrl j)

<html>
<svg id="svg" width="100" height="100">
<path id="thepath" d="M10 10L90 90" />
</svg>
<script>
var mypath = document.getElementById("thepath");
var numOfseg = 80;
var totalLength = mypath.getTotalLength();
for (var i=0;i<=numOfseg;i++)
{
var point = mypath.getPointAtLength( totalLength i/numOfseg);
console.log("x"+point.x + "y" + point.y)
}
</script>
</html>
Last edited by v1nce on Thu Oct 08, 2015 5:02 am, edited 1 time in total.

antecessor
Posts: 8
Joined: Mon Nov 24, 2014 7:10 pm

Re: Getting XY coordinates of the segments of a rule

Postby antecessor » Wed Oct 07, 2015 9:51 pm

Thanks to both for your quick answers.

However, I still don't get the results, due to I cannot follow exactly your reasonings.

I would like you to try to get those coordinates and tell me which have been step by step the steps you follow. I attach here the original .svg file.

test.svg
(18.72 KiB) Downloaded 96 times


It is a very important issue in order to start publishing some methodology in international journals.

Hope you can get some time to get the coordinates of the 80 points that divide the line.

Thanks in advance for your enormous help.

Mario

v1nce
Posts: 679
Joined: Wed Jan 13, 2010 4:36 am

Re: Getting XY coordinates of the segments of a rule

Postby v1nce » Thu Oct 08, 2015 5:00 am

paste the following html into your favorite text editor.
save it (foo.html)
run it into your favorite browser.
it will return the coordinates in the textarea

if you want to run it against another dataset (=path) copy/paste the d property of this path into the script (save and rerun)

In inkscape : select your shape ; launch the xml editor (shift ctrl x) ; make sure that in the xml editor the selected item is of type path ; look for the property "d" of this path ; copy this value ; replace the d value of the following script with your new value ; run the modified script

<html>

<svg id="svg" width="100" height="100">
<path id="thepath"
d="M 32.520148,378.72209 C 33.399843,376.2354 34.756263,373.05641 35.534326,371.65765 36.312425,370.25889 37.116715,367.92433 37.321662,366.46974 37.526609,365.01515 38.143624,363.23491 38.692776,362.51365 39.241918,361.79239 40.04065,360.31215 40.467628,359.22423 40.894615,358.1363 42.56635,354.57583 44.182508,351.31205 45.79872,348.04829 47.288331,344.82082 47.492826,344.13993 47.697321,343.45903 49.280799,340.29613 51.011712,337.11126 52.742624,333.92639 54.418604,330.54153 54.736085,329.58935 55.053612,328.63717 55.755444,327.34947 56.295778,326.7278 56.836112,326.10613 57.590753,324.62198 57.972798,323.42969 58.354798,322.23739 59.367917,320.45715 60.224195,319.4736 61.080428,318.49004 62.696863,315.42915 63.816277,312.67163 64.935692,309.9141 66.698117,306.35362 67.732758,304.75946 69.782103,301.60192 70.506812,300.44626 71.986343,297.97631 73.639265,295.21694 78.444396,289.12041 82.051398,285.20622 83.943764,283.15269 85.976063,280.71921 86.567621,279.79849 89.495216,275.24189 96.385907,269.88452 107.15108,263.79525 111.40634,261.38828 116.2036,257.70229 117.67286,255.71079 118.43827,254.67335 119.70883,253.18834 120.49638,252.41076 122.39733,250.53379 128.9124,242.22341 131.73565,238.07427 136.48431,231.09557 146.06143,224.06598 151.87299,223.29351 153.23072,223.11304 155.28291,222.68713 156.43343,222.34704 158.21765,221.81962 158.95389,221.91305 161.43926,222.98222 163.7947,223.99551 165.2352,224.20807 168.95502,224.09125 172.0078,223.99538 174.56873,224.26031 176.56296,224.87829 180.51909,226.10425 188.68567,230.03804 189.6255,231.17045 190.0335,231.66206 190.66675,232.06428 191.03278,232.06428 192.0668,232.06428 197.71527,236.39601 205.86314,243.43744 209.95482,246.97351 215.27564,251.13828 217.68723,252.69245 227.17827,258.80915 230.28282,260.68635 233.46329,262.23152 234.39579,262.68458 235.92172,263.85628 236.85422,264.83532 237.78673,265.81436 240.59708,267.57515 243.09946,268.74818 245.60179,269.92122 249.03513,271.75006 250.72906,272.81226 258.80978,277.87945 262.04062,278.56284 269.42788,276.7675 275.37064,275.32322 274.86584,275.32446 279.62708,276.74242 282.85927,277.70501 284.31954,278.58904 288.16535,281.91148 290.71696,284.11581 293.51796,286.44896 294.38984,287.09624 295.26167,287.74352 296.69942,289.4504 297.58477,290.88931 298.47017,292.32821 299.85494,294.1659 300.66211,294.97305 301.46924,295.78021 302.12966,296.97344 302.12966,297.62468 302.12966,299.08427 303.6601,302.14354 304.39028,302.14354 304.68516,302.14354 305.35208,302.97008 305.87239,303.9803 306.39264,304.99051 307.80667,306.77891 309.01456,307.95452 311.51594,310.38893 313.42757,313.2917 313.43064,314.66025 313.43181,315.17231 314.16774,317.07971 315.06602,318.89892 315.9643,320.71812 317.21514,323.85963 317.84572,325.88006 319.6813,331.76162 321.91927,336.69785 323.96491,339.37694 325.01063,340.74645 325.86619,342.49939 325.86619,343.27237 325.86619,344.04534 326.70627,345.85258 327.73305,347.28847 328.75978,348.72435 330.0496,351.04361 330.59925,352.44237 331.14894,353.84113 332.55514,356.00284 333.72415,357.24619 334.89316,358.48953 336.84593,360.99845 338.06364,362.82158 339.28135,364.64472 340.85356,366.99717 341.55748,368.04927 343.91394,371.57142 346.16638,370.18512 347.67146,364.28632 348.76339,360.00672 350.14462,357.10438 351.80319,355.60441 352.45796,355.01228 352.99364,354.33113 352.99364,354.09075 352.99364,353.30798 356.98024,346.93839 358.11014,345.91584 358.71527,345.36821 359.21035,344.55939 359.21035,344.11845 359.21035,343.67751 360.10442,342.38173 361.19716,341.23897 364.94731,337.31711 368.25283,333.51176 368.25283,333.11635 368.25283,332.51954 373.80872,325.83487 375.91118,323.90202 377.29816,322.62693 378.12994,320.99712 379.26595,317.3286 380.7486,312.54057 380.88559,312.33852 386.69769,306.36943 389.95434,303.02476 393.30382,299.37829 394.14088,298.26614 396.31673,295.37537 398.93095,293.18332 403.1268,290.73141 405.14119,289.55427 407.55916,287.94339 408.50007,287.15167 409.44094,286.35995 411.12059,285.33205 412.23259,284.86743 413.34458,284.40281 415.79347,282.5684 417.67462,280.79098 419.55573,279.01355 421.95615,276.92349 423.00878,276.1464 424.06147,275.36931 426.22321,273.48911 427.8126,271.96819 429.40205,270.44724 431.57645,268.83452 432.64464,268.38434 433.71278,267.93417 435.3945,266.94974 436.38176,266.19673 437.36902,265.44371 439.41972,264.4067 440.9389,263.89225 442.45809,263.3778 444.93763,262.10973 446.44898,261.07431 447.96031,260.03889 449.47985,259.19173 449.82568,259.19173 450.17146,259.19173 451.8596,257.80593 453.57705,256.11216 460.42655,249.35704 464.49204,245.62801 465.00724,245.62801 465.579,245.62801 469.06384,242.22227 472.03252,238.76217 473.00559,237.62806 474.44068,236.28148 475.22163,235.76977 476.00263,235.25805 477.62255,232.9178 478.82144,230.56923 480.32096,227.63182 482.05332,225.32103 484.37186,223.16542 487.6938,220.07699 489.81204,217.56099 492.58701,213.40761 497.49661,206.05926 504.96517,199.06042 511.32059,195.85222 515.25086,193.86822 522.41332,192.76179 528.19179,193.24601 533.87902,193.72257 542.58732,196.19983 545.4154,198.14561 546.77828,199.08327 548.06977,199.85043 548.28544,199.85043 548.91977,199.85043 557.77213,204.37416 558.70446,205.17472 559.17386,205.57779 561.46531,207.00412 563.79656,208.34436 566.12784,209.68459 569.17968,211.70725 570.57843,212.83915 571.97721,213.97106 574.64754,215.76042 576.51255,216.81549 581.69562,219.74764 593.78908,227.95324 596.01041,230.04508 597.09836,231.06957 598.75141,232.30672 599.68392,232.79431 600.61642,233.28189 601.935,234.27079 602.61409,234.99188 605.30862,237.85315 606.67218,239.08436 611.83476,243.31761 619.84473,249.88564 643.14359,273.2644 651.31,282.92826 653.28004,285.25952 656.33052,288.7188 658.08888,290.61556 659.84719,292.5123 662.30312,295.74581 663.54647,297.80113 664.78982,299.85646 666.37153,301.84026 667.06133,302.2096 667.75118,302.57894 669.45565,304.55898 670.849,306.6097 672.24235,308.66043 674.40287,311.60989 675.65011,313.16407 676.89739,314.71825 680.81382,319.80578 684.35336,324.46971 687.89291,329.13364 691.22498,333.31149 691.75794,333.75384 692.29095,334.19618 693.83613,336.2296 695.19173,338.27255 696.54729,340.31549 699.45215,344.5302 701.64698,347.63854 703.84177,350.7469 705.98688,354.05306 706.41377,354.98557 706.84071,355.91807 707.75269,357.18264 708.44038,357.7957 709.48994,358.73135 713.95037,365.17678 724.63207,381.1931 725.59144,382.63156 726.79946,384.15752 727.31656,384.58413 727.8337,385.01074 728.25676,385.66074 728.25676,386.02859 M 35.819764,379.88937 29.220532,377.55481 M 40.646308,367.75747 33.793825,366.32797 M 45.309283,357.01578 38.981709,354.02216 M 50.829785,345.1949 44.17915,343.01109 M 56.359029,334.43086 50.097486,331.30148 M 61.866127,323.27714 55.727247,319.91348 M 67.930738,311.96772 61.555391,309.07723 M 73.998927,301.41543 68.021739,297.77219 M 81.105297,291.62964 75.715428,287.16317 M 89.51761,281.68202 83.631616,277.89321 M 97.684801,273.91879 93.559983,268.26319 M 107.99214,267.34403 104.50998,261.27159 M 118.94398,259.51591 114.05862,254.50261 M 127.44506,249.6201 121.97043,245.25794 M 135.08565,239.39548 129.42705,235.27477 M 143.28962,231.31621 139.11639,225.69623 M 153.05015,226.65744 151.94301,219.74554 M 164.15572,227.42024 165.18629,220.49652 M 176.04453,228.39028 178.3004,221.76374 M 186.72886,233.35017 190.45977,227.42731 M 196.66225,240.27235 201.07431,234.83785 M 206.28761,248.37662 210.74865,242.98226 M 216.68987,256.21317 220.47813,250.32682 M 227.50156,262.98848 231.04255,256.95016 M 237.9016,269.91475 241.54718,263.93899 M 248.98276,275.84833 252.69507,269.9138 M 262.16201,281.13334 262.59018,274.14644 M 274.90062,279.18292 274.68698,272.18619 M 284.09768,283.06299 288.50157,277.62188 M 293.20686,290.83496 298.51631,286.2732 M 299.10813,300.20201 305.7466,297.9815 M 307.41078,311.32475 312.56558,306.58892 M 312.41905,321.50137 318.81187,318.64973 M 316.75655,333.22447 323.23543,330.57415 M 322.39118,343.60187 329.29371,342.43779 M 328.48863,355.99721 334.50388,352.41717 M 336.13619,366.23709 341.95657,362.34823 M 350.29373,367.67362 343.71984,365.26864 M 354.75898,357.60877 349.69897,352.77181 M 362.21998,346.1628 355.88897,343.17644 M 369.59215,337.19318 364.23014,332.6933 M 377.2797,327.48806 372.18101,322.69188 M 383.60726,315.4401 377.18326,312.65942 M 391.0523,306.89329 385.98467,302.06429 M 399.34859,297.69909 394.59911,292.55687 M 409.38845,290.86508 405.34004,285.15453 M 420.06269,283.34979 415.2586,278.25856 M 429.57922,275.11302 424.81016,269.98895 M 439.28475,268.48355 435.81309,262.40509 M 450.39595,262.73716 447.05144,256.58783 M 460.67867,254.07738 455.83009,249.0285 M 470.2271,245.83898 465.31443,240.85242 M 479.36139,236.38561 473.71862,232.24325 M 486.07593,226.38446 481.11624,221.44468 M 494.76687,216.42963 489.00051,212.46111 M 502.281,207.11297 497.31061,202.18395 M 511.39691,199.79994 507.83948,193.77129 M 521.95,196.79341 521.30843,189.82288 M 533.3995,197.62311 534.90974,190.78797 M 544.00211,201.41516 547.88,195.58747 M 555.44334,207.27119 558.8741,201.16956 M 565.91321,213.79363 569.81078,207.97909 M 576.52329,220.88323 580.15402,214.89843 M 586.91388,227.6715 590.88365,221.906 M 597.06204,235.30324 600.87753,229.43451 M 606.24573,243.23039 610.76227,237.88241 M 615.6317,251.39194 620.4079,246.27452 M 624.65186,260.07372 629.56526,255.08789 M 633.51108,268.96495 638.51374,264.06869 M 642.18294,278.01368 647.29814,273.2351 M 650.48301,287.34015 655.77001,282.75238 M 658.54643,296.6949 664.15893,292.51161 M 666.48078,306.59239 671.91919,302.18516 M 673.95672,316.66982 679.47494,312.36292 M 681.60734,326.64092 687.18264,322.40819 M 689.64302,336.6037 694.97718,332.07085 M 696.68535,346.65484 702.43253,342.65862 M 703.37793,356.74746 709.63303,353.60521 M 711.06589,367.31122 716.83809,363.35121 M 718.10844,377.73043 723.92413,373.83457 M 724.75676,386.02859 731.75676,386.02859"
/>
</svg>
<textarea id="result"></textarea>
<script>
var mypath = document.getElementById("thepath");
var numOfseg = 80;
numOfseg = parseInt(window.prompt("how many segments ?", numOfseg));

var totalLength = mypath.getTotalLength();
var coords ="";
for (var i=0;i<=numOfseg;i++)
{
var point = mypath.getPointAtLength(totalLength * i/numOfseg);
coords+= ("x:"+point.x + " ;y:" + point.y + "\n");
}
var result = document.getElementById("result");
result.value = coords;
</script>
</html>

Lazur
Posts: 4580
Joined: Tue Jun 14, 2016 10:38 am

Re: Getting XY coordinates of the segments of a rule

Postby Lazur » Thu Oct 08, 2015 6:49 am

antecessor wrote:However, I still don't get the results, due to I cannot follow exactly your reasonings.



Thinking it over again, using some sort of coding wizardry would work better.
Like on your example, the path would first need to be rephrased to nodes in even distances
-convert object to path, Ctrl+Shift+C,
select all nodes, add new node in segment
then connect the nodes in the middle of the ruler marks.

testexp.svg
(14.88 KiB) Downloaded 77 times



Tried my suggested method and it leads only to X coordinates right, not so sure why -probably because the coordinate system is flipped? Or some transformations caused by resizing the page? Who knows.

antecessor
Posts: 8
Joined: Mon Nov 24, 2014 7:10 pm

Re: Getting XY coordinates of the segments of a rule

Postby antecessor » Thu Oct 08, 2015 7:37 am

v1nce. Thanks for your answer. I copied/pasted all the code between <html></html> in your last post. Saved it in txt format and opened it on ff. It worked fine as a small window appeared telling there were 80 segments and giving coordinates for 81 nodes. It was nice so far.

However when I copied those coordinates into LibreOffice Calc, and tried to do an scatterplot with those values, I guess something is not working well. I see the nodes appearing to be mirrored compared to the original one, and they are not equally distributed. I would expect to find them approximately at the same distance one from the other, which actually is not the case. What's wrong?

Check the scatterplot here.
Pantallazo.png
Pantallazo.png (18.67 KiB) Viewed 2139 times

antecessor
Posts: 8
Joined: Mon Nov 24, 2014 7:10 pm

Re: Getting XY coordinates of the segments of a rule

Postby antecessor » Thu Oct 08, 2015 8:00 am

Lazur URH. I opened your attatch svg file and copied the values of the XML editor into LibreOffice Calc. The only way to vertically flip the coordinates is multiplying all the Y values by (-1). You can see the result here:
Pantallazo-2.png
Pantallazo-2.png (17.85 KiB) Viewed 2135 times


Thanks!! But I still would like to know the script of v1nce. Knowing two ways to get the same results is always positive and constructive for other users!

User avatar
brynn
Posts: 9973
Joined: Wed Sep 26, 2007 4:34 pm
Location: western USA
Contact:

Re: Getting XY coordinates of the segments of a rule

Postby brynn » Thu Oct 08, 2015 8:18 am

Did you find the extension in this topic? viewtopic.php?f=5&t=8826

styxlawyer
Posts: 38
Joined: Tue Aug 11, 2015 5:53 am

Re: Getting XY coordinates of the segments of a rule

Postby styxlawyer » Fri Oct 09, 2015 12:37 am

The SVG format is for web-based graphics, so the origin is in the top-left corner, whereas Libre Office Calc has its origin in the bottom-left corner. That's why your graphs appear to be upside-down.

Pinklemas Twoad
Posts: 1
Joined: Sun Jan 07, 2018 5:09 am

Re: Getting XY coordinates of the segments of a rule

Postby Pinklemas Twoad » Sun Jan 07, 2018 6:16 am

Adding a bit of information to help (very) new Inkscape users follow the OP, who wrote:

I used a Rule effect.


which refers to a "Path Effect."

The English version's name, with a salute to the OP for a good guess, for the effect is "Ruler" and is accessible, after selecting the desired path, from the menu:
Path->Path Effect Editor (Shift+Ctrl+7)

Note that "Ruler" is on the pull-down list.

Here's a screenshot, including my guess (from the word ambidextrous) that the Spanish "Ambos" translates to "Both." :^)
PEeditor.png
PEeditor.png (37.22 KiB) Viewed 675 times


I had read elsewhere on the web that getPointAtLength(totalLength * i/numOfseg) does not typically result in equal-length segments when used with curves, so I was not shocked by v1nce's result. Lazur's however is of great interest to me (I want to use a CNC to cut along curves, and it's easier--with my low expertise--to think of issuing straight-line G-code commands rather than of fitting arcs).

However the brevity of the comment made it difficult for me to follow:
-convert object to path, Ctrl+Shift+C,
select all nodes, add new node in segment
then connect the nodes in the middle of the ruler marks.


I selected the path to be divided and did the Ctrl+Shift+C [Path->Object-to-Path].
I selected all the nodes.
I had trouble with the next step: a visit to Help did not find "add new node in segment", but I tried:
Extensions->Modify Path->Add Nodes
choosing the Division Method of "Number of segments" and setting that to '3'. (The Help example showed that '3' would put a node on each end and one in the middle.)

I was confused when I at first expected the "hash marks" created by the Ruler path effect to be a set of new independent objects: instead they remained an effect on the original object. My expectation was that when I did an Edit->Select All, and applied the Add Nodes extension, the hashmarks would be subdivided as well.

As I'm not sure what was meant by "add new node in segment," I also don't know how to proceed to "connect the nodes in the middle of the ruler marks."

But I hope what I was able to find helps someone (even me when I come back to this site from a future search!).


Return to “Help with using Inkscape”

Who is online

Users browsing this forum: No registered users and 8 guests