Find intersection between line and circle
9 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Kasper
el 27 de Abr. de 2011
Respondida: Anupama
el 20 de Mayo de 2020
Hi I currently work with a small project regarding particle behaviour in closed domains.
I want to create a function which takes start point, and start direction for a point. The domain is a circle. How do I calculate the two intersections with the circle?
I know how to do the calculations but I have trouble with the implementation.
px = -0.5; % start x-coordinate of point
py = -0.5; % start y-coordinate of point
rx = 1; % x-direction of vector with the above startcoordinates
ry = 2; % y ------ || ---------
I tried using symbolic toolbox but I can't convert it back to normal variables.
fsolve won't help because the representation of a circle is not a function. What to do?
Thanks in advance
Regards
1 comentario
Andrew Newell
el 27 de Abr. de 2011
Show me what you did using the symbolic toolbox and I'll show you how to convert it back to normal variables.
Respuesta aceptada
Teja Muppirala
el 27 de Abr. de 2011
You're pretty close. Except you don't want to solve
'x^2 + y^2 = 0'
You want to solve 'x^2 + y^2 = R^2'
-------------------------------
Try this:
R = sym('R');
x = sym('px + t*rx');
y = sym('py + t*ry');
c = x^2+y^2-R^2;
t_sol = solve(c);
x_sol = subs(x,'t',t_sol)
y_sol = subs(y,'t',t_sol)
Then x_sol gives you the x values, and y_sol has the y values of the solution.
2 comentarios
Andrew Newell
el 27 de Abr. de 2011
This is how it would look in a function. Note that once you define t as a symbol, combinations involving t are symbols too.
function [xi,yi] = solveIntersection(px,py,rx,ry,r)
syms t
x = px + t*rx;
y = py + t*ry;
c = x^2+y^2-r^2;
t_sol = solve(c);
xi = subs(x,'t',t_sol);
yi = subs(y,'t',t_sol);
Más respuestas (4)
Kasper
el 27 de Abr. de 2011
3 comentarios
Christopher Creutzig
el 28 de Abr. de 2011
Instead of copying the symbolic expression manually, you might want to try using matlabFunction(x_sol(1)) etc. At the very least, it will vectorize better/more correctly.
Anupama
el 20 de Mayo de 2020
find tthe point of intersections of a circle at (1,2) and radius 4 and a straight line 2x+3y =9 using graphical method.
0 comentarios
Ver también
Categorías
Más información sobre Conversion Between Symbolic and Numeric en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!