Hello, I wonder how to 'cut' or erase some parts of a image/circle that i've done in PIL.
Let say that I have two circles that intersects with eachother, I know the two points where they intersect and now I want to cut/erase the circle thats left.
Let me show you a image how I want it to look like, that I made in paint:
I really hope you understand and if not, tell me! /flaerpen
3 3006
I have a possible answer. Instead of writing a ellipse/circle you write an Chord(?). but how do I use my points with the chordfunction in PIL?
from http://www.pythonware.com/library/pi.../imagedraw.htm
chord
draw.chord(xy, start, end, options)
Same as arc, but connects the end points with a straight line.
The outline option gives the colour to use for the chord outline. The fill option gives the colour to use for the chord interior.
EDIT: Or maybe this is not the solution, because if there is more than one intersection with another circle how do you do that?
I now know (i think) that i'll use the chordfunction, but have to ask how to calculate the start and end angle in a general formula.
I made a picture so it can be easier to show you what I really want:
Is there anyone who can help me to create a general forumula for the two green lines?
/flaerpen
bvdet 2,851
Expert Mod 2GB
I now know (i think) that i'll use the chordfunction, but have to ask how to calculate the start and end angle in a general formula.
I made a picture so it can be easier to show you what I really want:
Is there anyone who can help me to create a general forumula for the two green lines?
/flaerpen
flaerpen  This class will calculate the angles in radians with respect to circle 1 center point and the circle intersection points:  class CircleCircleIntersection(object):

def __init__(self, p1, p2, r1, r2):

'''

Given circle center points p1 and p2 and circle radii r1 and r2

Calculate intersection points of circles

This only works in the XY plane at the present time

'''

self.p1 = p1

self.p2 = p2

self.r1 = r1

self.r2 = r2

self.d = p1.dist(p2)

if self.d > r1+r2:

self.Pa = None

self.Pb = None

elif self.d < abs(r1r2):

self.Pa = None

self.Pb = None

else:

self.a = (r1**2r2**2+self.d**2)/(2*self.d)

self.b = self.dself.a

self.P0 = polarPt(p1, p2, self.a, p1)

self.h = (r1**2self.a**2)**0.5

self.intPts()


def intPts(self):

self.Pa = Point()

self.Pb = Point()

self.Pa.x = self.P0.x + (self.h * (self.p2.y  self.p1.y) / self.d)

self.Pb.x = self.P0.x  (self.h * (self.p2.y  self.p1.y) / self.d)

self.Pa.y = self.P0.y  (self.h * (self.p2.x  self.p1.x) / self.d)

self.Pb.y = self.P0.y + (self.h * (self.p2.x  self.p1.x) / self.d)

self.theta0 = math.atan2(self.p2.y+self.p1.y, self.p2.x+self.p1.x)

self.theta1 = self.theta0  math.atan2(self.h, self.a)

self.theta2 = self.theta0 + math.atan2(self.h, self.a)
Here is function 'polarPt':  def polarPt (p1, p2, d, p3=False):

'''

Calculate the vector p1>p2

Translate distance 'd' parallel to vector p1>p2 from point 'p3'

Return the new point

'p3' defaults to 'p2'

>>> polarPt(p1,p2,10,p3)

Point(4.651484, 24.128709, 8.825742)

>>> polarPt(p1,p2,10)

Point(10.651484, 19.128709, 7.825742)

>>>

'''

return (p3 or p2)+(p2p1).uv()*d
You will need a point object with 'x' and 'y' attributes, a unit vector (uv()) method, a distance (dist()) method, and +  * overloads. The angles calculated are counterclockwise.  >>> a = CircleCircleIntersection(Point(), Point(2,5.5,0), 3.5, 3.0)

>>> a.theta0

1.9195673303788037

>>> a.theta1

1.5052297601267781

>>> a.theta2

2.3339049006308294

>>> a.h

1.4090427459286017

>>> a.a

3.2038412164378536

>>> a.P0

Point(1.094891, 3.010949, 0.000000)

>>> a.Pa

Point(0.229319, 3.492479, 0.000000)

>>> a.Pb

Point(2.419100, 2.529418, 0.000000)

>>>
I used Paul Bourke's website for reference. LINK Sign in to post your reply or Sign up for a free account.
Similar topics
by: Brian Basquille 
last post by:
I have an image drawn on my form using GDI+ like so:
// image of puck is loaded and drawn
Image imagePuck = Image.FromFile("Puck.png");
g.DrawImage(imagePuck, puck_x, puck_y, 36, 36);
The...

by: chump1708 
last post by:
Can anyone give me an idea for drawing a circle without making use of
any floating point computations?
Thanks
Prasad

by: Matt Haggard 
last post by:
I'm using PIL (Python Imaging Library) to generate button images.
They consist of a left end image, a middle, repeating image and a
right side image.... anyway, that's not important
I'm using a...

by: Christopher Ireland 
last post by:
Hello!
Using the definition for en ellipse (http://en.wikipedia.org/wiki/Ellipse) I
can draw an arc of points. However, the end points of this arc do not
coincide with the end points of an arc...

by: surbhi bhargava 
last post by:
hello
i m a student of bioinformatics. i am having problem in C /C++ coding in computer graphics.
i want to know the code for drawing a line,circle,ellipse in computer graphics using C language...

by: Tem 
last post by:
I need to draw a black circle using WPF and generate an image file.
I used the following but it resulted in a blank file. I cannot figure out
what is wrong with it.
Thanks,
Tem
...

by: Slickuser 
last post by:
How do I automatic move the X & Y to create a ellipse function as
below, DrawCircle?
Or there any sample source code out there?
I want it move down by user input. How can I achieve this?...

by: PankajGaur 
last post by:
Hi,
I need to create a Ellipse shaped user control which have folloiwng
attributes:
1) The edges are smooth
2) The control shuld only be selected when click on the ellipse shape & not
when...

by: =?Utf8?B?UGFua2FqR2F1cg==?= 
last post by:
Hi,
I need to create a Ellipse shaped user control which have folloiwng
attributes:
1) The edges are smooth
2) The control shuld only be selected when click on the ellipse shape & not
when...

by: abbasky 
last post by:
### Vandf component communication method one: data sharing
Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...

by: fareedcanada 
last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...

by: davi5007 
last post by:
Hi,
Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...

by: DolphinDB 
last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation.
Take...

by: DolphinDB 
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion highfrequency records to 61 million...

by: Aftab Ahmad 
last post by:
Hello Experts!
I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...

by: Aftab Ahmad 
last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below.
Dim IE As Object
Set IE =...

by: ryjfgjl 
last post by:
ExcelToDatabase: batch import excel into database automatically...

by: isladogs 
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
 