# I'm writing a code to find the intersection points of two circles.

8 views (last 30 days)
Ali Abdel Sater on 8 Dec 2022
Edited: Ali Abdel Sater on 20 Dec 2022
The circirc function is giving me assert problems, so is the assert function.
I will not link the whole question, since that would be defeating the purpose of actually working on the code and learning.
The question will get more complicated deep through, but the starting point is finding the points of intesection of two circles of variable centers and radii.
PS. I'm a uni student and MATLAB is not fun at all for me. The code might look terribly hideous and I apologize for that. Can someone give tips to start enjoying MATLAB more and have a faster and more effective way of learning all its functionalities. Thanks in advance.
PPS. This code is due to next week and I would really appreciate a quick reply! Thanks again <3
Here is the code:
%DEFINE INPUT PARAMETERS%
syms x y
A = [x y];
B = [x y];
C = [x y];
D = [x y];
AB = norm(A-B);
CD = norm(C-D);
AC = norm(A-C);
%ASSUMPTIONS%
assume(x, 'real');
assume(y, 'real');
assume(AB > 0 );
assume(CD > 0 );
assume(AC > 0 );
%FINDING INTERSECTION%
assert(AB > 0 && CD > 0); %what is happening here?%
[xint, yint] = circcirc(A(1),A(2),AB,C(1),C(2),CD);
%Error using assert
Assertion failed.
Error in problem_geogebra1 (line 61)
assert(AB > 0 && CD > 0);%
E = [xint(1), yint(1)];
F = [xint(2), yint(2)];
Image Analyst on 20 Dec 2022
Can you show a diagram? It might help. And why can't you just set the two equations equal to each other?
(x-xc1)^2 + (y-yc1)^2 = r1^2
(x-xc2)^2 + (y-yc2)^2 = r2^2
Two equations, two unknowns
Ali Abdel Sater on 20 Dec 2022
Edited: Ali Abdel Sater on 20 Dec 2022
Sorry, Image Analyst, the question has been solved and the code has been submitted already. I aced the homework!
Please reffer to the older comments on this thread. The inputs where defined for circcirc, and I accidentally redefined them.
Please take a deep look at this thread, some moderation issues have to be resolved.

Fifteen12 on 8 Dec 2022
You can find the documentation for assert here: https://www.mathworks.com/help/sltest/ref/assert.html
Assert stops your simulation if the expression passed to it is false. In this case, the expression is making sure that the line AB and the line CD are both positive. I am curious how it failed, to my knowledge norm should always return a positive number, though perhaps we're just missing some pieces of the problem (as you stated) where AB and CD were adjusted.
As for enjoying MATLAB, the thrill is in the journey. Just like with learning a new language, the first couple of steps are the most frustrating while you learn the basics. Don't give up just because it's hard at the start!
##### 3 CommentsShow 1 older commentHide 1 older comment
Fifteen12 on 9 Dec 2022
I'm actually not sure what your question is, are you having trouble understanding assert? Or with an error being thrown by assert?
Ali Abdel Sater on 9 Dec 2022
everytime i use circcirc, the error comes out of nowhere. I don't understand what is wrong with my circcirc!

John D'Errico on 16 Dec 2022
You had a problem in the use of syms here, causing an error.
syms x y
A = [x y];
B = [x y];
C = [x y];
D = [x y];
AB = norm(A-B);
CD = norm(C-D);
AC = norm(A-C);
%ASSUMPTIONS%
assume(x, 'real');
assume(y, 'real');
assume(AB > 0 );
Warning: Ignored assumptions on constants.
assume(CD > 0 );
Warning: Ignored assumptions on constants.
assume(AC > 0 );
Warning: Ignored assumptions on constants.
The warnings are just warnings, but they tell something useful, IF you look at them carefully and you think about the value of those variables.
What is AB here? CD?
AB
AB =
0
CD
CD =
0
Do you see they are identically zero? Now, let me perform two sets of asserts...
%FINDING INTERSECTION%
assert(AB >= 0 && CD >= 0); %what is happening here?%
No error is generated.
assert(AB > 0 && CD > 0); %what is happening here?%
Error using assert
Assertion failed.
So AB and CD are both identically zero. That means the assertion must fail, because you were asserting these parameters must be POSITIVE. Had you allowed zero in the assertion, it would not have caused an assertion failure.
As far as receiving an answer in a more timely way, we are not paid to answer questions immediately. We are here by choice, and are not paid at all. If someone sees your question when you want an answer, and they know the answer, then you will get an answer quickly. Sorry, but that is how a volunteer forum works. And if you post a question at an inopportune time when maybe nobody is awake or those who could answer are having dinner, then you get an answer when someone is able to answer and not before.
Ali Abdel Sater on 20 Dec 2022
Edited: Ali Abdel Sater on 20 Dec 2022
I will be holding on to this quote for personal reasons.
Thank you for your time, John

### Categories

Find more on Logical in Help Center and File Exchange

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!