Group Abstract Group Abstract

Message Boards Message Boards

0
|
3.1K Views
|
3 Replies
|
0 Total Likes
View groups...
Share
Share this post:

How to optimize the formula calculation of distance from point to line?

Posted 4 years ago

Enter the coordinates of the point (m, n) and the straight line equation A x + B y + c == 0

pal = {m, n, A x + B y + c == 0}

Extract the Abscissa and ordinate values of a point respectively

xc = pal[[1]]

yc = pal[[2]]

pol = Apply[Subtract, pal, {1}]

Extract the coefficients before x, the coefficients before y and the constant term in the input linear equation, respectively.

xt = Coefficient[pol, x, 1][[3]]

yt = Coefficient[pol, y, 1][[3]]

ct = Coefficient[Coefficient[Coefficient[pol, x, 0], x, 0][[3]], y, 0]

The result of calculating the distance from the input point to the input line using the distance formula from point to line,Put the previously extracted value into the formula to get the distance value.

distance = Abs[xc xt + yc yt + ct]/Sqrt[xt^2 + yt^2]
POSTED BY: Lee Tao
3 Replies

There is no need to repost virtually identical questions.

POSTED BY: EDITORIAL BOARD
Posted 4 years ago
pal = {1, 2, a x - y + 4 == 0};

xc = pal[[1]];

yc = pal[[2]];

pol = Apply[Subtract, pal, {1}];

xt = Coefficient[pol, x, 1][[3]];

yt = Coefficient[pol, y, 1][[3]];

ct = Coefficient[Coefficient[Coefficient[pol, x, 0], x, 0][[3]], y, 0];

distance = Abs[xc xt + yc yt + ct]/Sqrt[xt^2 + yt^2]
POSTED BY: Lee Tao
Posted 4 years ago

How do I optimize this code?

The following is an example of the calculation.

The distance from a point (3,4) to a straight line 3 x - 2 y + 1 == 0

enter image description here

POSTED BY: Lee Tao
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard