It is currently Tue Apr 30, 2024 8:34 am


All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 17 posts ] 
Author Message
 Post subject: Drawing arc path using Python.
PostPosted: Tue Sep 27, 2016 10:51 am  (#1) 
Offline
GimpChat Member
User avatar

Joined: Jan 13, 2011
Posts: 2249
Location: Poland
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 3125 times ]

_________________
Image

Slava
Ukraini!
Share on Facebook Share on Twitter Share on Orkut Share on Digg Share on MySpace Share on Delicious Share on Technorati
Top
 Post subject: Re: Drawing arc path using Python.
PostPosted: Tue Sep 27, 2016 11:46 am  (#2) 
Offline
Script Coder
User avatar

Joined: Oct 25, 2010
Posts: 4739
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).

_________________
Image


Top
 Post subject: Re: Drawing arc path using Python.
PostPosted: Tue Sep 27, 2016 2:10 pm  (#3) 
Offline
GimpChat Member
User avatar

Joined: Jan 13, 2011
Posts: 2249
Location: Poland
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).

_________________
Image

Slava
Ukraini!


Top
 Post subject: Re: Drawing arc path using Python.
PostPosted: Tue Sep 27, 2016 2:42 pm  (#4) 
Offline
Script Coder
User avatar

Joined: May 07, 2014
Posts: 3975
Location: Canada
try this one
Attachment:
arc_example.zip [1.33 KiB]
Downloaded 163 times

reference source: how to create circle with bezier curves

_________________
TinT


Top
 Post subject: Re: Drawing arc path using Python.
PostPosted: Tue Sep 27, 2016 2:52 pm  (#5) 
Offline
Script Coder
User avatar

Joined: Oct 25, 2010
Posts: 4739
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.

_________________
Image


Top
 Post subject: Re: Drawing arc path using Python.
PostPosted: Tue Sep 27, 2016 2:55 pm  (#6) 
Offline
Script Coder
User avatar

Joined: Oct 25, 2010
Posts: 4739
PPS:

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

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

_________________
Image


Top
 Post subject: Re: Drawing arc path using Python.
PostPosted: Tue Sep 27, 2016 2:59 pm  (#7) 
Offline
Script Coder
User avatar

Joined: Oct 25, 2010
Posts: 4739
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.

_________________
Image


Top
 Post subject: Re: Drawing arc path using Python.
PostPosted: Tue Sep 27, 2016 3:54 pm  (#8) 
Offline
Script Coder
User avatar

Joined: May 07, 2014
Posts: 3975
Location: Canada
i didn't scroll that far :hehe I guess that is a better constant with formula of how they got it and all.

_________________
TinT


Top
 Post subject: Re: Drawing arc path using Python.
PostPosted: Tue Sep 27, 2016 4:33 pm  (#9) 
Offline
GimpChat Member
User avatar

Joined: Jan 13, 2011
Posts: 2249
Location: Poland
@ 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 3013 times ]
Example coeur.png
Example coeur.png [ 4.64 KiB | Viewed 3013 times ]

_________________
Image

Slava
Ukraini!
Top
 Post subject: Re: Drawing arc path using Python.
PostPosted: Tue Sep 27, 2016 5:23 pm  (#10) 
Offline
Script Coder
User avatar

Joined: May 07, 2014
Posts: 3975
Location: Canada
oh that bottom part of the heart looks trickier than my script provided.

_________________
TinT


Top
 Post subject: Re: Drawing arc path using Python.
PostPosted: Wed Sep 28, 2016 10:43 pm  (#11) 
Offline
GimpChat Member

Joined: May 12, 2015
Posts: 4694
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!


Top
 Post subject: Re: Drawing arc path using Python.
PostPosted: Wed Sep 28, 2016 11:51 pm  (#12) 
Offline
Script Coder
User avatar

Joined: May 07, 2014
Posts: 3975
Location: Canada
or this shape Pat
Attachment:
heart_05.png
heart_05.png [ 23.24 KiB | Viewed 931 times ]

_________________
TinT


Top
 Post subject: Re: Drawing arc path using Python.
PostPosted: Thu Sep 29, 2016 2:45 am  (#13) 
Offline
GimpChat Member
User avatar

Joined: Jan 13, 2011
Posts: 2249
Location: Poland
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 924 times ]

_________________
Image

Slava
Ukraini!
Top
 Post subject: Re: Drawing arc path using Python.
PostPosted: Thu Sep 29, 2016 6:47 am  (#14) 
Offline
Script Coder
User avatar

Joined: Oct 25, 2010
Posts: 4739
See the "tangents to circle" options in ofn-path-to-shape :)

_________________
Image


Top
 Post subject: Re: Drawing arc path using Python.
PostPosted: Thu Sep 29, 2016 11:29 am  (#15) 
Offline
Script Coder
User avatar

Joined: May 07, 2014
Posts: 3975
Location: Canada
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

_________________
TinT


Top
 Post subject: Re: Drawing arc path using Python.
PostPosted: Thu Sep 29, 2016 2:04 pm  (#16) 
Offline
Global Moderator
User avatar

Joined: Oct 06, 2010
Posts: 4050
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).

_________________
"In order to attain the impossible, one must attempt the absurd."
~ Miguel de Cervantes


Top
 Post subject: Re: Drawing arc path using Python.
PostPosted: Thu Sep 29, 2016 2:06 pm  (#17) 
Offline
Script Coder
User avatar

Joined: May 07, 2014
Posts: 3975
Location: Canada
mahvin, we all intend things to be funny, no harm in trying. :hehe

_________________
TinT


Top
Post new topic Reply to topic  [ 17 posts ] 

All times are UTC - 5 hours [ DST ]


   Similar Topics   Replies 
No new posts Attachment(s) i struggle with the option to copy the path - the path where a file i

3

No new posts Convert GIMP plugin from Python 2 to Python 3

4

No new posts Attachment(s) Path copy rotate shift plus + Path copy rotate shift walk Play

79

No new posts Difference between "Python-Fu" and "Python" plugin

6

No new posts Attachment(s) Drawing - Style P

10



* Login  



Powered by phpBB3 © phpBB Group