GIMP Chat
http://gimpchat.com/

Drawing arc path using Python.
http://gimpchat.com/viewtopic.php?f=9&t=14638
Page 1 of 1

Author:  MareroQ [ Tue Sep 27, 2016 10:51 am ]
Post subject:  Drawing arc path using Python.

I want to draw a heart using Python.

It consists of eight arcs.
What will be the code to draw the path of the arc AB?
Data: the radius (r) and point A (x1, y2) and B (x2, y1).

Please piece of code or clue.

Attachments:
Draw Heart.png
Draw Heart.png [ 24.11 KiB | Viewed 3240 times ]

Author:  ofnuts [ Tue Sep 27, 2016 11:46 am ]
Post subject:  Re: Drawing arc path using Python.

Get my ofn-path-to-shape script, it's in there somewhere. Basically you create two horizontal/vertical tangents, and the best approximation to a circle is when the distance of the tangent handle to the anchor is radius*kappa, where "kappa" is a constant (kappa=4*(math.sqrt(2)-1)/3).

But if you want a heart that looks good, you'll have to do a bit more math and look into tangent circles of different diameters. Nothing earth-shattering... There may even be a simple construction using path-to-shape (and mirror-path, because I'm lazy).

Author:  MareroQ [ Tue Sep 27, 2016 2:10 pm ]
Post subject:  Re: Drawing arc path using Python.

Thank You Ofnuts for the quick reply.

Ofn-path-to-shape.py - this 838 lines of code.
It's too hard - for a beginner to learn about creating shapes paths in Python.
The heart is the only example of using a bow to create assorted figures (through symmetry, rotation and flip - the problem is the arc).

Author:  trandoductin [ Tue Sep 27, 2016 2:42 pm ]
Post subject:  Re: Drawing arc path using Python.

try this one
Attachment:
arc_example.zip [1.33 KiB]
Downloaded 165 times

reference source: how to create circle with bezier curves

Author:  ofnuts [ Tue Sep 27, 2016 2:52 pm ]
Post subject:  Re: Drawing arc path using Python.

MareroQ wrote:
Thank You Ofnuts for the quick reply.

Ofn-path-to-shape.py - this 838 lines of code.
It's too hard - for a beginner to learn about creating shapes paths in Python.
The heart is the only example of using a bow to create assorted figures (through symmetry, rotation and flip - the problem is the arc).

You didn't really search, did you? Of course this code constructs a full circle with an arbitrary orientation of its four control points

def pointAtRhoThetaFromOrigin(origin,rho,theta):
    xo,yo=origin
    x=xo+rho*math.cos(theta)
    y=yo+rho*math.sin(theta)
    return (x,y)

def circleTriplet(center,rho,theta):
    '''
    One anchor and its two handles to create a circle approximation
    (four needed for a full circle)
    '''
    anchor=pointAtRhoThetaFromOrigin(center,rho,theta)
    bwdHandle=pointAtRhoThetaFromOrigin(anchor,rho*kappa,theta-math.pi/2)
    fwdHandle=pointAtRhoThetaFromOrigin(anchor,rho*kappa,theta+math.pi/2)
    return [bwdHandle,anchor,fwdHandle]

def circleFromRadius(p1,p2):
    rho=distance(p1,p2)
    theta=angle(p1,p2)
    points=[]
    for i in range(4):
        triplet=circleTriplet(p1,rho,theta+(i*math.pi/2))
        points.extend(triplet)
    return points,True


Besides, neither you nor Disnasset are beginners. This is more high school math than code, and the last time I did math seriously was about 35 yeas ago. You just have to believe in yourself and dive.

PS: Current O-P-2-S is 861 lines, so you must have an old version.

Author:  ofnuts [ Tue Sep 27, 2016 2:55 pm ]
Post subject:  Re: Drawing arc path using Python.

PPS:

http://serge.mehl.free.fr/anx/coeur.html

And "6ème" is for kids 11-12 years.

Author:  ofnuts [ Tue Sep 27, 2016 2:59 pm ]
Post subject:  Re: Drawing arc path using Python.

trandoductin wrote:
try this one
Attachment:
arc_example.zip

reference source: how to create circle with bezier curves


By the way, I have never seen a convincing proof that this is the best fit to the circle. IIRC it just makes sure that the middle point of the arc is on the circle. Hmmm. Following one comment leads to a better proof with a slightly different constant (that you used in your code). Good to know.

Author:  trandoductin [ Tue Sep 27, 2016 3:54 pm ]
Post subject:  Re: Drawing arc path using Python.

i didn't scroll that far :hehe I guess that is a better constant with formula of how they got it and all.

Author:  MareroQ [ Tue Sep 27, 2016 4:33 pm ]
Post subject:  Re: Drawing arc path using Python.

@ Trandoductin
Your code works very well. Thank you very much.

@ Ofnuts
Thank you very much for pointing out the code and example (perhaps the most beautiful heart and simple dependencies).

Attachments:
Arc by TT.png
Arc by TT.png [ 7.11 KiB | Viewed 3128 times ]
Example coeur.png
Example coeur.png [ 4.64 KiB | Viewed 3128 times ]

Author:  trandoductin [ Tue Sep 27, 2016 5:23 pm ]
Post subject:  Re: Drawing arc path using Python.

oh that bottom part of the heart looks trickier than my script provided.

Author:  Pat625 [ Wed Sep 28, 2016 10:43 pm ]
Post subject:  Re: Drawing arc path using Python.

I don't know anything about the math involved re making the perfect heart but after seeing that last diagram, I will definitely remember that the next time I have to draw a heart. Very nifty!

Author:  trandoductin [ Wed Sep 28, 2016 11:51 pm ]
Post subject:  Re: Drawing arc path using Python.

or this shape Pat
Attachment:
heart_05.png
heart_05.png [ 23.24 KiB | Viewed 1055 times ]

Author:  MareroQ [ Thu Sep 29, 2016 2:45 am ]
Post subject:  Re: Drawing arc path using Python.

This heart has a classic look - if You wrote code?
One more parameter - the dependence of H
For me, a long way to learn. :oops:

Attachments:
h-ard h-eart.png
h-ard h-eart.png [ 19.15 KiB | Viewed 1048 times ]

Author:  ofnuts [ Thu Sep 29, 2016 6:47 am ]
Post subject:  Re: Drawing arc path using Python.

See the "tangents to circle" options in ofn-path-to-shape :)

Author:  trandoductin [ Thu Sep 29, 2016 11:29 am ]
Post subject:  Re: Drawing arc path using Python.

oh man you guys are advanced...i just did it by using snap to guides and snap to active path.
wouldn't know how to do it in code with more research :hehe

Author:  mahvin [ Thu Sep 29, 2016 2:04 pm ]
Post subject:  Re: Drawing arc path using Python.

For me, I would simplify the math using a triangle as the start point. Good ole trig and a set of compass points. (This is intended to be funny, and I realize it might not get the desired result).

Author:  trandoductin [ Thu Sep 29, 2016 2:06 pm ]
Post subject:  Re: Drawing arc path using Python.

mahvin, we all intend things to be funny, no harm in trying. :hehe

Page 1 of 1 All times are UTC - 5 hours [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/