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

15 views (last 30 days)
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)];
  5 Comments
Ali Abdel Sater
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.
Thanks in advance!

Sign in to comment.

Answers (2)

John
John 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 Comments
Ali Abdel Sater
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!

Sign in to comment.


John D'Errico
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.
  1 Comment
Ali Abdel Sater
Ali Abdel Sater on 20 Dec 2022
Edited: Ali Abdel Sater on 20 Dec 2022
"If someone sees your question when you want an answer, and they know the answer, then you will get an answer quickly"
I will be holding on to this quote for personal reasons.
I'm not in a position to argue about Matlab, but I have the absolute authority to accept the answer to my own question, especially when it's right. Thank you for your very helpful contribution, but I would rather deam my answer as the right one in my case, since the given paremeters where to be replaced during the examination of the code. I by no means agree with the blind authority of unaccepting someone's answer when it surely is correct. Please reverse your actions and allow me to accept the correct answer, so that people facing the same problem have a better understanding of how circcirc works. If not, please go ahead and delete this thread/entire question.
Thank you for your time, John

Sign in to comment.

Categories

Find more on Characters and Strings in Help Center and File Exchange

Tags

Products

Community Treasure Hunt

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

Start Hunting!