Good day, ladies and gentlemen, today we are looking live at problem number 8 18. It is the circle to D. Class. And needless to say it is a long one. It is a big one. Okay, so I'm just gonna yeah it's big. So let's just begin by saying Ok so what the problem basically asked us for is to create the circle to D. Classes. Creation of the class on the class is a bunch of private data fields. There's three private data fields. We have to create the set methods for each one. Um and classes supposed to construct a circle object which has center um X I guess here it should say um X. Um Why? Uh and uh Y equals zero. So it should initialize with X equals zero, Y equals zero and radius I guess zero. Um And the respective getting set methods uh and then we're supposed to create a bunch of methods to get area which of course gets its area. Um Prince Prince the area get parameter which which Prince the perimeter. And then these other ones contain point contained circle and overlaps. And we'll get into those in just a second. Now, I just want to talk a little bit about the questions that I actually had some problems with and it's really these contained points contains circle and overlaps. So the basic idea, I guess if you let me let me scroll down here a bit. So if you have a point here, so we'll just say we have this point here, okay? And you know, you just have to forgive me because I'm really not very good at drawing but um if we have a circle here, so we have a circle like this going around the sky and this circle of course has the radius here of our so it has a radius and I'll call this the radius big are okay now this is our circle object. So this is our this and I guess you'd say in some sense this is our circle object. This is sort of like a pickerel representation of our circle. Ob. So we'll just call this C. one which is a circle object. Okay? Now we have out here um so we have out here some other point here, we'll call this point why here? Okay? And it we'll just say there's another circle here and of course has this point at the center and I'm sorry that my my circles aren't beautiful, but I try my best here and this guy has another radius which is a little R No, I got to admit this whole conversation is pretty important. So please forgive me for going on about it, but it's kind of important. So this guy here is my c. two. Okay, this is c. two. we'll call it circle object, circle object. Uh huh. Two. Okay. Now the first thing that you should be. So the first question of course is how can we tell if there is any overlap? Well that's a good question. How can you tell that? Because um certainly when we uh let me see here if I okay, so if I grab this object will just take it over here for now and you look and uh we obviously have our little point. Why here? So why is the center here? And you'll see that if we draw a line, so if we draw a line from extra wise we just draw a line through wire. Yes. Okay. Um now obviously this this line um has some distance and we'll call that distance D. So the line from X to Y. Has some distance D. So dear. Um is D. Oops, okay, the uh is equal to the distance from and I'm just going to call it Big X. Two Big Y. To avoid the the concerns with the coordinates versus the guy itself. Okay, so um this distance here, the distance between the points has the distance uh X. Distance from X to Y. And now what we're concerned with is when so you can watch this little circle. If you draw it as it crosses this point here, as it crosses the the outer perimeter of the circle, it goes from having no overlap and all the answers being false to having overlap. You know that once it crosses there it has some overlap and then slowly bit by bit if if if this is my center again. So So this whoops wrong one. So. Okay. Yeah, this guy. Okay. Yeah, if this were my center here, obviously, sorry, it didn't work out very well, but that's my center, obviously. Now the center is contained in it and then at a certain point the whole circle becomes, becomes contained in there. So the main problem I had with doing this is first off trying to find conditions that guaranteed that the um, the one circle is contained in the other and to do this, basically, I did some, you know, I'm not, I'm not going to explain the algae run everything behind it, but I have to admit that this was a big problem to me. And as you'll see in the the forthcoming solution, um, I did basically what I did is I ended up doing some algebraic manipulations to find the equations that I needed. And then once I found those, then, um, then everything else was, you know, okay. But it it's quite involved problem trying to figure out what the conditions are and they end up being pretty simple but I I still needed to justify them. So because this problem so involved, I'm just gonna cut to the chase and show you the program I wrote. And then I'll show you the test program and work you through the steps of the the program itself and then the test program. And then we'll just glance at the results. Finally we'll go over the uml diagram and that will be it for this one. So okay so here we go. Um this is the circle to be. And first off because I'm using square roots and stuff, I had to import math So I did that but now I created this class two D. And of course like I said here these guys are my um So Class two d. So when I do it I have to first define the initialize er method and of course whenever you do that you self. And because it's said to initialize X. Y. And the radius to zero initially um I set that X two B zero, Y. Zero and radius to be zero. And now these are private methods, so use the underscore as such, so I set myself underscore X to be X and so on and so forth. Um And now get X. Now that these are the assessor methods. Again, now the assessor methods, all they're doing is they're returning their respective variable, the respective values and because their their their private they cannot be seen from the outside. I so you Doing the assessor meth methods allows 1 to see it. Um And then the mutate er method. Again, the mutate er methods. All they're doing is they're allowing you to input new values in for the X to Y and the radius. So this allows you to mutate the original object. Well, okay. Um so moving on now we get to the methods he asked for and these are now not just get assessor mutate or message uh to get area, of course is just returning the area and now this is where we start needing to use math because we the math module because we need this math pi number and all I'm returning of course, is the the corresponding area here. I'm returning the perimeter of course for the perimeter and now we get to a little bit more interesting one which is this contained point. So contains point of course, just you just input some point X and Y into the function and then it mm it returns true. If the distance here, the distance from the point to the center is less than the radius of the circle, you return true and false. Otherwise, if we go to the diagram, I mean really it's pretty clear what's happening. Basically. I have some, you know, point out here, you know, some point here which is a. B. And I'm just looking at the distance from the point to here. So I'm just looking at I'm just calculating that distance and if it's less than a little r, r big r then I'm good if it's not so fault. Okay, now contains here is taking another circle objects. So to um to do contains you actually have to calculate, you have to create a second circle object and then you and I will show you how to do it in just a moment when we when we do the implementation of it, but you just taken another circle object and then you use the get methods of the the circle object and the gap methods of the given object. So my current myself object and you do the calculations and what I've done here is basically I first calculate the distance uh and I say well if the distance, if the distance if this distance distance plus the radius of my current circle, so um sorry this this distance I calculate here plus the distance of my um input circle. In other words my other the other circle I created if that is less than my current distance or the radius of the big circle, then I returned true, otherwise I return false um to to show this what this is doing is um so remember the distance here, so this distance here is D okay and this distances are so this is our so basically what the the calculation there is saying that um the it's asking uh if B. Plus Little R. Is or I'm sorry? Um Yeah yeah yeah D. Plus little R. Is less than big are basically you can think of big are as being something like this, and I'm actually thinking this is incorrect. Let me just check here. Something's not right about that. Um Sorry um Sorry? Um Uh that was not to write one. Oh I see, I'm I apologize, I'm sorry. Uh This one is the overlaps. Oh okay. Or this one's that contains I'm sorry this one's that contains module, that's why, because I knew this wasn't the right calculation. Um Yeah, so the the point here is that um what you're uh this picture is getting messy now, I'm sorry. So if we maybe we go down a little further and so I have the circle here, I have that circle there which has radius big are um and then I have another circle um like this guy here and the two centers will be here here. This is why. And assist X. So if I draw the line between it, I draw the line between X and Y. This has just this is distance. The and this is distance are so D. Plus R. D. Plus little R. Is um the distance from this point here. So D. Plus R. Is the distance from here to the what would be the farthest point away from X. So D. Plus R. Is the farthest point away from X. Within this circle. So D plus are is furthest point uh in circle in a circle C. Two from center X. Or big X. Of circle? Uh C. One oh this point is the furthest away. So if um and D. Plus are is that distance from here to there? So if this is um if this is less than big are then this circles would be contained in this circle would be contained in there. And that's what this that's what this calculation is after. And you have to remember how to do it because um yeah because here we have to use the gut method um on both circles, this one's for the circle, you're inputting the circle to d. And this one's for the the current circle. Um And finally and then you return true. If it's less than finally on the last one then um the overlaps. The overlaps condition is pretty much is similar to the other one basically overlap. I'm really looking at compared to the other one. I'm really just looking at, whoops. Sorry, what I'm looking at is this point here. So if I if I draw that line again, so if I draw this line again here passes through the center, sorry, it's supposed to be a straight line, it passes through the center here and just focusing on this point here, which is on the vector from X. Y. Um And as soon as this point is less than our from X, then there's overlap. So that's that's pretty much what this this equation here. Um This final one does, is it try basically, I found a way to calculate that and if that's less than I'm not going to go into it. But if that's less than if the distance is less than big hour plus little are then I return true and it's false otherwise. Okay. So as you can see this is actually quite a law, it is actually quite involved problem. Um But you know, we'll just run it and finally what I want and the fine and the next step is then to look at the the test program. Now the test program in itself is kind of interesting because I'm doing something here that there is a little different than what I did in previous videos in this one. I actually read in The coordinates, X. Y. and Radius in one line. And then so I just took the input of X. Y. And radius for both circles. Some the question um asked you know of course to prepare two circles. So I'm just in putting the two circles with the corresponding X. Y. And radius. Um And then what I what I do is um basically so I create this longer string which is my string one. Um comma my string too. So I'm taking the original strings here creating a longer string. And then what I do is I I just. Uh huh. You know I I split this string because these numbers are split by comma. So I have X. One Y. One radius. And I split this string by the comma. So that's one becomes the the terms before the first comma. Why one string becomes the terms before the second comma. And then radius string one becomes the turns it for the third one, so on and so forth. You have the 4th 1/5 1. And then you're done. So that's what I'm doing here. And then of course I'm creating my circle which is the circle to the object created by the of course I need to use floats. So I just use the float of these strings because they're turned. If you do this you're just turning it into to a number element. Now or I guess a string element. But by using float it becomes a number. Um And then basically I go through and then I actually apply it here. So again let's just look at the resultant. Okay? And if I print out, so I go five, 5.5 and 10, this is the example from the book again. So this is nine, 1.3 and 10. And that's the print out that I get. So the area of the circle, of course history under 14 point blah blah blah perimeter. Both circles apparently had very close to the same or the same radio. Yeah, they had the same radius, so they have the same area and perimeter. And you can see um see one contains C. Two, but it does not contain all of C. Two contains the center of C. Two, but not all of C. Two and their overlaps. Okay so let's um uh let's uh let's let's go let's move on to the uml diagram here. Okay so the so the uml diagram um let's see. Okay let's just go to the bottom here. So the ml diagram again um And this is I hope by now you guys have kind of become accustomed to what this is supposed to be I guess or how to do this. So this is circle uh uh Two D. Okay and again it has the variables. The private variables X. Y. Radius. No these are all private variables. Sorry private data fields. I call them variables. I get used to the term. I'm a mathematician by trade so I'm used to thinking them as variables but the proper languages data fields here and of course they just reflect the the properties, you know the properties of the circle object were they of the circle object? Cervical mm object I guess reflect isn't really the right term they represent or carry I guess they give the circle I guess is probably a better word. Okay. Um And they're all private. So now we have the circle uh two D. And it has um X equals to zero and it's a float Y equals to zero. It's also a float and radius equals to zero and it's a float again. The the equal zero just means that it initialize is it Or it's If you don't if you don't give a value two x. Um In the when you when you set it up when you find a circle object then you know then then it will set a zero. Um So in particular what I mean is I can go like this let me see I can go um C equals to circle um radius equals to two and sure oh sorry I did that wrong. C equals to circle um To the Radius Radius Radius Equals two, one. And and then you can get um Or I should say c. one got get get X. And what, sorry? It's C dot get tax is what I mean and the X coordinate of the circle is zero, you know, so on and so forth. So it's so funny but that's what the initializing at zero does is it um gives it gives the gives the sort of the initial value or something the term. Um Okay so um and then we have the the get an assessor methods for the private variable. So we have gets X. And of course this is just float. It's all it does is give you the value as I showed you get why? Again it's a float and get radius and it's just a float. Um And then the assessor or the mutate er which is set X. And X. Which is a float. And it returns non none. Okay. Set why and why float and returns none. And then um sat radius, radius radi us I guess something like that can't even spell radius and then rad and of course none. And and like I said these are just the mutate er which which allows you to mutate the initial object. Um And finally we have the Gatch area and it returns afloat. Just just calculates the area of the given object. Jet rim immature again returned the float and then contains point and this is of X. Float and why afloat. Um Again it just it returns a boolean true or false statement whether the points in the circle or not and then contains um which Mick circle To D. or two d. That's a circle objects, Circle object and this returns bullying um whether whether the circles contained in these in your object or not and finally overlap, overlap and that again um Circle two on the object circle object circle circle object and again it returns of the land. You know again it returns true or false whether circles continue their or not. Okay so that that's the that's the idea. I mean this is necessarily an involved problem. It's a lot of different things. It's very nice problem but it's very involved. So I hope maybe I help you a little bit. I don't know but hopefully I did and you know thank you very much and have a nice day.