Reputation: 1091
I'm having surprisingly difficult time to figure out something which appears so simple. I have two known coordinates on a graph, (X1,Y1) and (X2,Y2). What I'm trying to identify are the coordinates for (X3,Y3).
I thought of using sin and cos but once I get here my brain stops working. I know that
sin O = y/R
cos O = x/R
so I thought of simply importing in the length of the line (in this case it was 2) and use the angles which are known. Seems very simple but for the life of me, my brain won't wrap around this.
The reason I need this is because I'm trying to print a line onto an image using poly2mask in matlab. The code has to work in the 2D space as I will be building movies using the line.
X1 = [134 134 135 147 153 153 167]
Y1 = [183 180 178 173 164 152 143]
X2 = [133 133 133 135 138 143 147]
Y2 = [203 200 197 189 185 173 163]
YZdist = 2;
for aa = 1:length(X2)
XYdis(aa) = sqrt((x2(aa)-x1(aa))^2 + (Y2(aa)-Y1(aa))^2);
X3(aa) = X1(aa) * tan(XYdis/YZdis);
Y3(aa) = Y1(aa) * tan(XYdis/YZdis);
end
polmask = poly2mask([Xdata X3],[Ydata Y3],50,50);
Upvotes: 2
Views: 347
Reputation: 13087
one approach would be to first construct a vector l
connection points (x1,y1)
and (x2,y2)
, rotate this vector 90 degrees clockwise and add it to the point (x2,y2)
.
Thus l=(x2-x1, y2-y1)
, its rotated version is l'=(y2-y1,x1-x2)
and therefore the point of interest P=(x2, y2) + f*(y2-y1,x1-x2)
, where f
is the desired scaling factor. If the lengths are supposed to be the same, then f=1
and thus P=(x2 + y2-y1, y2 + x1-x2)
.
Upvotes: 5