Post all Gimp scripts and script writing questions here
Tue Sep 27, 2016 10:51 am
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.
Tue Sep 27, 2016 11:46 am
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).
Tue Sep 27, 2016 2:10 pm
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).
Tue Sep 27, 2016 2:52 pm
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
- Code:
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.
Tue Sep 27, 2016 2:59 pm
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.
Tue Sep 27, 2016 3:54 pm
i didn't scroll that far
I guess that is a better constant with formula of how they got it and all.
Tue Sep 27, 2016 4:33 pm
@ 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).
Tue Sep 27, 2016 5:23 pm
oh that bottom part of the heart looks trickier than my script provided.
Wed Sep 28, 2016 10:43 pm
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!
Wed Sep 28, 2016 11:51 pm
or this shape Pat
- heart_05.png (23.24 KiB) Viewed 1064 times
Thu Sep 29, 2016 2:45 am
This heart has a classic look - if You wrote code?
One more parameter - the dependence of H
For me, a long way to learn.
Thu Sep 29, 2016 6:47 am
See the "tangents to circle" options in ofn-path-to-shape
Thu Sep 29, 2016 11:29 am
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
Thu Sep 29, 2016 2:04 pm
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).
Thu Sep 29, 2016 2:06 pm
mahvin, we all intend things to be funny, no harm in trying.
Powered by phpBB © phpBB Group.
phpBB Mobile / SEO by Artodia.