Finding coordinates of a point from bisector of two lines

I have two points, P1 and P2. Starting from M1 (middle point among P1 and the origin), I want to know the coordinates of the point Q1 as shown in the picture.
How can I do this?

 Accepted Answer

Sure!
Fortunately, I kept the code ...
clear
close all
xq = [-1000 0 -200 -1000 -1000];
yq = [-450 0 -1000 -1000 -450];
a21 = atan2d(-450, -1000);
a23 = atan2d(-1000, -200);
a123 = a21 - a23;
ab = a123/2 + a23;
lineb = 1200*[cosd(ab); sind(ab)];
slopeb = lineb(2)/lineb(1);
len12 = hypot(-450, -1000);
xpt = interp1([0 -1000], [0 -450], -500);
ypt = interp1([0 -450], [0 -1000], xpt);
B = [0 1; lineb(2) 1] \ [0; lineb(1)];
slope_orth = -B(1);
intcpt_orth = ypt-slope_orth*xpt;
slope23 = -1000/-200;
xint = intcpt_orth/(slope23-slope_orth);
yint = slope_orth*xint+intcpt_orth;
figure
plot(xq, yq, DisplayName='Quadrilateral')
hold on
plot([0 lineb(1)], [0 lineb(2)],'-r', DisplayName='Bisector')
scatter(xint, yint, 25, 'red','filled', 's', DisplayName='Q1')
plot([0 -600], [0 -600]*slope_orth+intcpt_orth, '-m', DisplayName='Orthogonal Line')
hold off
text(xint+50, yint,"Q1 ("+xint+","+yint+")", Horiz='left', Vert='middle', FontWeight='bold')
axis('equal','padded')
legend(Location='NW')
As a general rule, I delete my answers if they are not accepted.
.

5 Comments

Dear @Star Strider, can you please replace your answer?
please, can you use the coordinates that I written in the question?
My pleasure!
I thought I did. I did not originally enlarge the image to see the exact coordinates.
This time, I did. Using them changes the result.
Try this --
clear
close all
xq = [-1000 0 -166 -1000 -1000];
yq = [-548 0 -1000 -1000 -548];
a21 = atan2d(-548, -1000);
a23 = atan2d(-1000, -166);
a123 = a21 - a23;
ab = a123/2 + a23;
lineb = 1200*[cosd(ab); sind(ab)];
slopeb = lineb(2)/lineb(1);
len12 = hypot(-548, -1000);
ypt = interp1([xq(2) xq(1)], [yq(2) yq(1)], -500);
xpt = interp1([0 yq(1)], [0 xq(1)], ypt);
B = [0 1; lineb(2) 1] \ [0; lineb(1)];
slope_orth = -B(1);
intcpt_orth = ypt-slope_orth*xpt;
slope23 = yq(3)/xq(3);
xint = intcpt_orth/(slope23-slope_orth);
yint = slope_orth*xint+intcpt_orth;
figure
plot(xq, yq, DisplayName='Quadrilateral')
hold on
plot([0 lineb(1)], [0 lineb(2)],'-r', DisplayName='Bisector')
scatter(xint, yint, 25, 'red','filled', 's', DisplayName='Q1')
plot([0 -600], [0 -600]*slope_orth+intcpt_orth, '-m', DisplayName='Orthogonal Line')
hold off
text(xq(1), yq(1), sprintf('P1 (%d, %d)',xq(1), yq(1)), Horiz='left', Vert='top')
text(xq(3), yq(3), sprintf('P2 (%d, %d)',xq(3), yq(3)), Horiz='left', Vert='top')
text(xpt, ypt, sprintf('M1 (%d, %d)',xpt,ypt), Horiz='left', Vert='bottom')
text(xint+50, yint,"Q1 ("+xint+","+yint+")", Horiz='left', Vert='middle', FontWeight='bold')
axis('equal','padded')
legend(Location='NW')
grid
I added labels and coordinates for all the identified points. I also made subtle tweaks to my code, however the code itself, except for the changed coordinates, is the original. (I used degrees rather than radians here so that a visual check on the results would be easier to interpret.) I did not calculate the intersection of the bisector and the line connecting 'M1' and 'Q1'. I could add it if that information is desired.
.
@Star Strider it works very well! if you want to add further information feel free to update your code
Thank you.
I'll delete it again, since as I noted prevously, I usually delete my answers if they are not accepted.
It will remain posted if you accept it, not otherwise.

Sign in to comment.

More Answers (1)

Categories

Find more on Simulink in Help Center and File Exchange

Products

Release

R2022a

Tags

Community Treasure Hunt

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

Start Hunting!