Borrar filtros
Borrar filtros

Finding coordinates of point(s) that are specific distance(s) away on a slanted straight line

3 visualizaciones (últimos 30 días)
Hello, I am a physician trying to locate points of interest on medical images. My problem boils down to the following:
I have an image with 7 points of interest that I need to identify on my image. The 7 points lie in a slanted straight line like so:
I could take advantage of image properties to find the coordinates of point A and C. d1, d2, and d3 are all known values. What script should I run to find the coordinates of the 2 crosses d1 distance from A? And similarly, how do I find the coordinates for B, and the 2 coordinates d3 distance from that?
Thank you so much for your help!
  1 comentario
Star Strider
Star Strider el 20 de Ag. de 2016
Do you have any recommendations for radiology text or reference books relevant to both clinical and technical perspectives? (I’d appreciate Author-Title-ISBN so I know I’m getting the correct ones.) I’ve been looking for a while, but haven’t found any that seem to cover what I want. You’re the perfect person to ask!

Iniciar sesión para comentar.

Respuesta aceptada

Star Strider
Star Strider el 20 de Ag. de 2016
Not a function, but a short bit of code:
A = [5 10]; % Create Data
C = [7 15]; % Create Data
d1 = 2.1;
d2 = 3.8;
d3 = 1.5;
x = [A(1); C(1)]; % Define Independent Variables
y = [A(2); C(2)]; % Define Dependent Variables
P = [ones(size(x(:))) x(:)]\y(:); % Calculate Intercept, Slope For Line
phi = atan2(diff(y), diff(x)); % Slope Angle (rad)
LineDist = @(V,d,phi) [V(1)+d*cos(phi) V(2)+d*sin(phi); V(1)-d*cos(phi) V(2)-d*sin(phi)];
d1X = LineDist(A,d1,phi); % ‘d1’ Coordinates
B = LineDist(C,d2,phi); % ‘B’ Coordinates
d3X = LineDist(B(1,:),d3,phi); % ‘d3’ Coordinates
xv = linspace(min(x)-3, max(x)+3); % X-Vector For Plot
yv = [ones(size(xv(:))) xv(:)]*P; % Y-Vector For Plot
figure(1)
plot(xv, yv)
hold on
plot(x, y, 'ok', 'MarkerFaceColor','k')
plot(d1X(1,1), d1X(1,2), 'xr')
plot(d1X(2,1), d1X(2,2), 'xr')
plot(B(1,1), B(1,2), 'xk')
plot(d3X(1,1), d3X(1,2), 'xr')
plot(d3X(2,1), d3X(2,2), 'xr')
hold off
grid
text(A(1)+0.1,A(2), 'A', 'HorizontalAlignment','left')
text(B(1,1)+0.1,B(1,2), 'B', 'HorizontalAlignment','left')
text(C(1)+0.1,C(2), 'C', 'HorizontalAlignment','left')
text(d1X(:,1)+0.1,d1X(:,2), 'd1', 'HorizontalAlignment','left')
text(d3X(:,1)+0.1,d3X(:,2), 'd3', 'HorizontalAlignment','left')
The plot:
Board-Certified Internist here, with M.Sc. in Biomedical Engineering!
  8 comentarios
Image Analyst
Image Analyst el 20 de Ag. de 2016
"a line orthogonal to a given line (in a plane) has a slope (not the angle of the slope) that is the negative of that of the given line" <== it's slope is actually -1/slope, the negative inverse.
Star Strider
Star Strider el 20 de Ag. de 2016
The ‘phi±(pi/2)’ idea works. It’s necessary to use axis equal on the plot to see it correctly.
Adding the off-line distance ‘d4’ and calculating the perpendicular line at ‘C’ as the ‘PrpC’ coordinate matrix (plotted in green here), the complete code becomes:
A = [5 10]; % Create Data
C = [7 15]; % Create Data
d1 = 2.1;
d2 = 3.8;
d3 = 1.5;
x = [A(1); C(1)]; % Define Independent Variables
y = [A(2); C(2)]; % Define Dependent Variables
P = [ones(size(x(:))) x(:)]\y(:); % Calculate Intercept, Slope For Line
phi = atan2(diff(y), diff(x)); % Slope Angle (rad)
LineDist = @(V,d,phi) [V(1)+d*cos(phi) V(2)+d*sin(phi); V(1)-d*cos(phi) V(2)-d*sin(phi)];
d1X = LineDist(A,d1,phi); % ‘d1’ Coordinates
B = LineDist(C,d2,phi); % ‘B’ Coordinates
d3X = LineDist(B(1,:),d3,phi); % ‘d3’ Coordinates
d4 = 5;
PrpC = LineDist(C,d4,phi+pi/2);
xv = linspace(min(x)-3, max(x)+3); % X-Vector For Plot
yv = [ones(size(xv(:))) xv(:)]*P; % Y-Vector For Plot
figure(1)
plot(xv, yv)
hold on
plot(x, y, 'ok', 'MarkerFaceColor','k')
plot(d1X(1,1), d1X(1,2), 'xr')
plot(d1X(2,1), d1X(2,2), 'xr')
plot(B(1,1), B(1,2), 'xk')
plot(d3X(1,1), d3X(1,2), 'xr')
plot(d3X(2,1), d3X(2,2), 'xr')
plot(PrpC(:,1)', PrpC(:,2)', 'p-g')
hold off
grid
text(A(1)+0.1,A(2), 'A', 'HorizontalAlignment','left')
text(B(1,1)+0.1,B(1,2), 'B', 'HorizontalAlignment','left')
text(C(1)+0.1,C(2), 'C', 'HorizontalAlignment','left')
text(d1X(:,1)+0.1,d1X(:,2), 'd1', 'HorizontalAlignment','left')
text(d3X(:,1)+0.1,d3X(:,2), 'd3', 'HorizontalAlignment','left')
text(PrpC(:,1)+0.1,PrpC(:,2), 'd4', 'VerticalAlignment','bottom')
axis equal
with the plot:

Iniciar sesión para comentar.

Más respuestas (1)

Image Analyst
Image Analyst el 20 de Ag. de 2016
Knowing points A and C, the equation of the line is
slope = (yc-ya) / (xc - xa);
y = slope * (x - xa) + ya;
To get the x for the left and right d1 point from A
angle = atan(slope);
xd1Left = xa - d1 * cos(angle);
xd1Right = xa + d1 * cos(angle);
To get point B from known point C
xb = xc + d2 * cos(angle);
To get the d3 points
xd3Left = xc + (d2-d3) * cos(angle);
xd3Right = xc + (d2+d3) * cos(angle);
To get the y values for any of those x values, plug them in for x in the formula for the line:
y = slope * (x - xa) + ya;

Categorías

Más información sobre Voronoi Diagram en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by