Find intercept point with three boundary conditions
Mostra commenti meno recenti
Hi,
Im trying to find a point in a straight line given by an equation F(x)=mx+b, with the following boundary conditions:
-is a tangent of a semicircle
-The semicircle has a center on the horizontal axis
-the semicircle goes thru the origin (x=0, y=0)
Initially I was plotting the line and then start modifying the radius manually of the semicircle until I found one intersection point using InterX, but I think it might exist a way to avoid the manual modification.
1 Commento
CamPe
il 6 Lug 2021
Risposte (1)
Nipun
il 31 Mag 2024
Hi CamPe,
I understand that you want to find a point on a straight line given by "F(x) = mx + b" that is tangent to a semicircle centered on the horizontal axis and passing through the origin. Here is a way to calculate this point without manual modification:
First, let's set up the equations:
- The line: "y = mx + b"
- The semicircle: "(x - h)^2 + y^2 = r^2", where the center is "(h, 0)" and it passes through the origin, implying "h = r".
To find the tangent point, we need to solve the system of equations where the distance from the center of the semicircle to the line is equal to the radius "r".
Here's the MATLAB code to solve this:
% Define the line parameters
m = ...; % Slope of the line
b = ...; % y-intercept of the line
% Define the semicircle center and radius (initial guess)
r_initial = ...; % Initial guess for the radius of the semicircle
% Function to calculate the distance from center to the line
distance_to_line = @(r) abs(m * r + b) / sqrt(m^2 + 1) - r;
% Use fsolve to find the radius where the distance equals the radius
opts = optimoptions('fsolve', 'Display', 'iter', 'TolX', 1e-10);
r_solution = fsolve(distance_to_line, r_initial, opts);
% Calculate the center of the semicircle
h = r_solution;
% Tangent point coordinates
x_tangent = h;
y_tangent = m * h + b;
% Display the results
disp(['Tangent point: (', num2str(x_tangent), ', ', num2str(y_tangent), ')']);
disp(['Radius of the semicircle: ', num2str(r_solution)]);
In this script:
- distance_to_line function calculates the difference between the distance from the center of the semicircle to the line and the radius "r".
- fsolve is used to find the radius "r" where this difference is zero, indicating tangency.
You can refer to the MathWorks documentation for more details on fsolve: https://www.mathworks.com/help/optim/ug/fsolve.html
Hope this helps.
Regards,
Nipun
Categorie
Scopri di più su Programming in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!