Find intercept point with three boundary conditions

1 view (last 30 days)
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 Comment
CamPe
CamPe on 6 Jul 2021
The coding that I have been using so far is the following, there I have the main line F(x)=mx+b, the semicircle and a perpendicular, where the perpendicular should be the same lenght as R (radius of the semicircle).
So what I want to do is to find an intersection point for the three lines (P=pl) by modifying R and r and making them the same.
%Main line
warning off; close all;clc;
SS=[2393.9 3733.3 4638.6];
NS=[1875.4 3080 4210.2];
c=polyfit(NS,SS,1); % Here 'c' contains the 'm' and 'b'
SS_est=polyval(c,NS);
plot(NS,SS,'*');
grid
title(['Line Equation is y = ',num2str(c(1)),'*x + ','(',num2str(c(2)),')']);
xlabel('Normal Stress(Pa)');
ylabel('Shear stress (Pa)');
hold on
plot(NS,SS_est);
m=c(1);
b=c(2);
xl = linspace(0,4500);
f = @(xl) m*xl+b;
figure(1)
plot(xl, f(xl))
grid
% Choose a point C along line AB at half distance
D(1) = range([NS(1),SS_est(1)])/2+min([NS(1),SS_est(1)]);
D(2) = m*D(1) + b;
% Get slope and y int of line perpendicular to AB at point C
perp = -1/m;
% Find the end points of the perpendicular line with length Clen*2
a = D(1)+ (1000*sqrt(1/(1+perp^2)))*[-1,1];
b = [D(2)+ (perp*sqrt(1/(1+perp^2))),0];
plot(a,b)
perpe=[a;b];
legend('Data','Fitted Curve','Location','northwest');
disp(['Line Equation is y = F(x) = ',num2str(c(1)),'*x + ','(',num2str(c(2)),')']);
T = table(NS',SS',SS_est',(SS-SS_est)','VariableNames',{'Frequency','Activation_Energy','Fit','Fit_Error_R'})
% Semi circle
th = linspace( -pi*2, -pi, R);
R = 2000; %Radius
x = R*cos(th) + R;
y = R*sin(th);
circ=[x;y];
plot(x,y); axis equal;
%Intersections
L1=[xl;f(xl)];
pl=InterX(perpe,L1);
P=InterX(circ,L1);
r= sum(sqrt(diff(pl).^2+diff(b).^2));

Sign in to comment.

Answers (1)

Nipun
Nipun on 31 May 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:
  1. The line: "y = mx + b"
  2. 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

Categories

Find more on Systems of Nonlinear Equations 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!