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

7 次查看(过去 30 天)
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 个评论
Image Analyst
Image Analyst 2022-12-20
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
Ali Abdel Sater 2022-12-20
编辑:Ali Abdel Sater 2022-12-20
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!

请先登录,再进行评论。

回答(2 个)

Fifteen12
Fifteen12 2022-12-8
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 个评论
Fifteen12
Fifteen12 2022-12-9
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
Ali Abdel Sater 2022-12-9
everytime i use circcirc, the error comes out of nowhere. I don't understand what is wrong with my circcirc!

请先登录,再进行评论。


John D'Errico
John D'Errico 2022-12-16
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 个评论
Ali Abdel Sater
Ali Abdel Sater 2022-12-20
编辑:Ali Abdel Sater 2022-12-20
"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

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

标签

产品

Community Treasure Hunt

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

Start Hunting!

Translated by