You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
Finding the coordinates of a point given the gradient, distance and one set of coordinates
6 views (last 30 days)
Show older comments
Hi im trying to find the coordinates of a point given the gradient (m), distance (s) and one set of coordinates (x1,y1). I have a simultaneous equation that needs solving but cannot seem to find the numerical answers i have calulated by hand in MATLAB.
m = y2-y1/x2-x1 and s = sqrt((x2-x1)^2 + (y2-y1)^2)
given that:
m = 0.4
x1 = 10
y1 = 4
s = 15
and solving to find x2 and y2.
Accepted Answer
Torsten
on 27 Jun 2022
Edited: Torsten
on 27 Jun 2022
m = 0.4;
x1 = 10;
y1 = 4;
s = 15;
z = [x1 y1] + s/sqrt(1+m^2)*[1 m];
x2 = z(1)
y2 = z(2)
13 Comments
Torsten
on 27 Jun 2022
The direction from [x1 y1] to [x2 y2] is given by +/-[1 m] because m is the slope of the line connecting the two points. If you normalize the direction to be a vector with norm 1, you can directly multiply it by s to get the connecting line between [x1 y1] and [x2 y2]. And the vector +/-[1 m] normalized to be of norm 1 is +/-[1 m]/sqrt(m^2+1).
A second point that might have to be considered is thus
z = [x1 y1] - s/sqrt(1+m^2)*[1 m]:
m = 0.4;
x1 = 10;
y1 = 4;
s = 15;
z1 = [x1 y1] + s/sqrt(1+m^2)*[1 m];
z2 = [x1 y1] - s/sqrt(1+m^2)*[1 m];
m1 = (z1(2)-y1)/(z1(1)-x1)
m1 = 0.4000
s1 = sqrt((z1(1)-x1)^2+(z1(2)-y1)^2)
s1 = 15.0000
m2 = (z2(2)-y1)/(z2(1)-x1)
m2 = 0.4000
s1 = sqrt((z2(1)-x1)^2+(z2(2)-y1)^2)
s1 = 15.0000
Adil Saeed
on 29 Jun 2022
Following on from this, I have furthered my code to encorpate the coordinates as a matrix array to cater for more coordinates working together as one, rather than doing it all individually (hope this made sense) i.e.
x0 = 0;
y0 = 0;
x1 = [1;2;3;4;5];
y1 = [6;7;8;9;10];
so the coordinate pairs are: (1,6) (2,7) (3,8) (4,9) (5,10)
m = [y1(1)/x1(1); y1(2)/x1(2); y1(3)/x1(3); y1(4)/x1(4); y1(5)/x1(5)];
I know this maths is not technically correct as you cannot divide matrices however i found this way useful in order to find the gradients as a 5x1.
d = sqrt((x1-x0).^2 + (y1-y0).^2);
This was used to find the distance between the points.
Now the confusions sets in when finding the new coordinates as a 5x2 matrix if this is possible to be broken into 2 5x1 matrices for x2 and y2. Hope this all made sense.
Thanks
Adil Saeed
on 29 Jun 2022
so (x0,y0) is the origin and the source for this code. m and s should change for each pair depending on the coordinate pair. so if we analyse the first pair of coordinates (1,6) this should give m to be 6 and the distance s as 6.0828. for the coordinates (2,7) this should give m to be 3.5 and s to be 7.28 as so on...
i represented this as a matrix and m and s (or d) should equal:
m = [6;3.5;2.666;2.25;2];
d = [6.0828;7.28;8.5440;9.8489;11.1803];
now based on this i want the new coordinates for each of the pairs all represented in a matrix (5x2) of x2 and y2.
Torsten
on 29 Jun 2022
So you want the point (x2, y2) which is d = sqrt((x0-x1)^2+(y0-y1)^2) apart from (x1, y1) and lies on the line connecting (x0,y0) and (x1,y1) ?
x0 = 0;
y0 = 0;
x1 = [1;2;3;4;5];
y1 = [6;7;8;9;10];
m = (y1-y0)./(x1-x0)
m = 5×1
6.0000
3.5000
2.6667
2.2500
2.0000
d = sqrt((x1-x0).^2+(y1-y0).^2)
d = 5×1
6.0828
7.2801
8.5440
9.8489
11.1803
z = [-x0+2*x1,-y0+2*y1]
z = 5×2
2 12
4 14
6 16
8 18
10 20
Adil Saeed
on 30 Jun 2022
Apologies for the confusion on my part. So the distance between (x0,y0) to (x1,y1) is determined by d = sqrt((x1-x0).^2+(y1-y0).^2). However the distance between (x1,y1) to (x2,y2) is already pre determined by s = vt (conditions i have set in place), where s = 10 m. This is the distance between (x1,y1) and (x2,y2). Again its like the orginal message where i have the simultaneous equation of:
m = y2-y1/x2-x1 and s = sqrt((x2-x1)^2 + (y2-y1)^2) solving for (x2,y2).
But this time need to consider the equation as a matrix rather than one coordinate.
I hope this makes it more clear.
Torsten
on 30 Jun 2022
So you don't need (x0,y0) and you are given (x1,y1) in matrix form and s and m in vector form and you want to determine the two points (x21,y21) and (x22,y22) that have distance s from (x1,y1) with slope m ?
Adil Saeed
on 30 Jun 2022
pretty much yes, but want all 5 points within a matrix:
(x2(1),y2(1)), (x2(2),y2(2)), (x2(3),y2(3)), (x2(4),y2(4)), (x2(5),y2(5))
and to be a 5x2 matrix, based on their own gradient m in a 5x1 matrix. the gradient is determined by
m = y1(i)-y0/x1(i)-x0
from (x0,y0) and (x1(i),y1(i)), as each new coordinate will be on the same coresponding gradient. The distance between (for the new coordinate (x2(i),y2(i)) will be of a distance 10 m away.
Adil Saeed
on 30 Jun 2022
i have just calculated the new coordinates individually if they were not in a matrix, therefore the matrix should be:
[2.6,15.86; 4.74,16.61; 6.51,17.36; 8.06,18.13; 9.47, 18.94]
I have also attached my full code
x0 = 0;
y0 = 0;
Sr = [x0 y0]; %Source coordinates
SL = 220; %Source Level dB re 1uPa @ 1m (made up need to find example)
a = 0.25; %Attenuation (made up need to find example)
IL = 180; %Impact Level (made up need to find example)
%z1 = [randi([-10 10],1,5); randi([-10 10],1,5)];
%z1 = z1'
%x1 = z1(1:5,1);
%y1 = z1(1:5,2);
x1 = [1;2;3;4;5];
y1 = [6;7;8;9;10];
d = sqrt((x1-x0).^2+(y1-y0).^2); %Pythagoras Theorem for distance between the 2 (Source and Reciever) points
m = (y1-y0)./(x1-x0); %Gradient between the points
r1 = d;
v = 2; %harbor porpoises swim between 0.5 - 4.2 m/s
t =5; %seconds
s = v*t; %metres
z2 = [x1 y1] + s/sqrt(1+m.^2).*[1 m]; %New coordinates for new positions 5s later at a speed of 1.5m/s
x2 = z2(1);
y2 = z2(2);
r2 = d + s; %distance from source to new receive position
Torsten
on 30 Jun 2022
v = 2; %harbor porpoises swim between 0.5 - 4.2 m/s
t = 5; %seconds
s = v*t; %metres
x0 = 0;
y0 = 0;
x1 = [1;2;3;4;5];
y1 = [6;7;8;9;10];
d = sqrt((x1-x0).^2+(y1-y0).^2); %Pythagoras Theorem for distance between the 2 (Source and Reciever) points
m = (y1-y0)./(x1-x0); %Gradient between the points
z1 = [x1,y1] + diag(s./sqrt(1+m.^2))*[ones(size(x1)),m]
z1 = 5×2
2.6440 15.8639
4.7472 16.6152
6.5112 17.3633
8.0614 18.1381
9.4721 18.9443
z2 = [x1,y1] - diag(s./sqrt(1+m.^2))*[ones(size(x1)),m]
z2 = 5×2
-0.6440 -3.8639
-0.7472 -2.6152
-0.5112 -1.3633
-0.0614 -0.1381
0.5279 1.0557
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)