1
$\begingroup$

I wonder if there is a way to extract vertex coordinates from polygon or SierpinskiCurve which are obtained by using the Graphics command? For example Graphics[SierpinskiCurve[2]], which produce: enter image description here

I know I can right click at those images, choose get coordinates, and check the coordinate one by one by moving the cursor to each vertex. But I wonder if there is a better way to do this? I would like to just get a list of vertex coordinates instead of clicking at each vertex one by one.

$\endgroup$
5
  • 1
    $\begingroup$ SierpinskiCurve[2] /. Line[x_] -> x gives vertex coordinates. Also check DataRange option. $\endgroup$ Commented Apr 28, 2017 at 3:38
  • $\begingroup$ Hi Anjan, is DataRange option only gives us the range of the coordinates? How to get the point coordinates of SierpinskiCurve[2]? $\endgroup$
    – Lila
    Commented Apr 28, 2017 at 3:41
  • 1
    $\begingroup$ Does First@SierpinskiCurve[2] work? $\endgroup$
    – kglr
    Commented Apr 28, 2017 at 4:06
  • 1
    $\begingroup$ In general, given a plot named p of a set of lines, use p // InputForm to see the data on which the plot is based, and then use the appropriate Part command to extract the line endpoints. $\endgroup$
    – bbgodfrey
    Commented Apr 28, 2017 at 4:09
  • $\begingroup$ Hi kglr, Yes, First@SirspinskiCurve[2] work! =) Thanks a lot! Also thanks bbgidfrey 13 for the input. I really appreciate it. $\endgroup$
    – Lila
    Commented Apr 28, 2017 at 4:24

2 Answers 2

1
$\begingroup$

Thanks all =) Below is the result of using First@SierpinskiCurve[2]: enter image description here

$\endgroup$
1
$\begingroup$

In:

(*#1*)
Graphics[SierpinskiCurve[2]] // Part[#, 1, 1] & // Most
(*#2*)
Most @* First @@ Graphics[SierpinskiCurve[2]] 

Out:

{{0, 0}, {32, -32}, {96, -32}, {128, 
  0}, {160, -32}, {128, -64}, {128, -128}, {160, -160}, {224, -160}, \
{256, -128}, {256, -64}, {224, -32}, {256, 
  0}, {288, -32}, {352, -32}, {384, 
  0}, {416, -32}, {384, -64}, {384, -128}, {416, -160}, {384, -192}, \
{352, -160}, {288, -160}, {256, -192}, {256, -256}, {288, -288}, \
{352, -288}, {384, -256}, {416, -288}, {384, -320}, {384, -384}, \
{416, -416}, {384, -448}, {352, -416}, {288, -416}, {256, -448}, \
{224, -416}, {256, -384}, {256, -320}, {224, -288}, {160, -288}, \
{128, -320}, {128, -384}, {160, -416}, {128, -448}, {96, -416}, {32, \
-416}, {0, -448}, {-32, -416}, {0, -384}, {0, -320}, {-32, -288}, {0, \
-256}, {32, -288}, {96, -288}, {128, -256}, {128, -192}, {96, -160}, \
{32, -160}, {0, -192}, {-32, -160}, {0, -128}, {0, -64}, {-32, -32}}
$\endgroup$
1
  • 1
    $\begingroup$ Thanks you very much for your effort UnchartedWorks. Now I have several tricks in my sleeve to get the coordinate of vertices of polygon obtained by using Graphics command. $\endgroup$
    – Lila
    Commented Apr 28, 2017 at 18:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.