Suppose we have three points, a, b, c. b and c are linked to become a line. how to use R to calculate the distance from a to this line? Is there any function? Thanks a lot
相关问题
- R - Quantstart: Testing Strategy on Multiple Equit
- Using predict with svyglm
- Reshape matrix by rows
- Extract P-Values from Dunnett Test into a Table by
- split data frame into two by column value [duplica
相关文章
- How to convert summary output to a data frame?
- How to plot smoother curves in R
- Paste all possible diagonals of an n*n matrix or d
- ess-rdired: I get this error “no ESS process is as
- How to use doMC under Windows or alternative paral
- dyLimit for limited time in Dygraphs
- Saving state of Shiny app to be restored later
- How to insert pictures into each individual bar in
It has to be distinguished whether we are dealing with a two-dimensional or a three-dimensional case.
2D case
If the problem is two-dimensional, the position of the points
a
,b
andc
can be defined by pairs of numbers which represent the points'x
and they
coordinates. The following function can be used to calculate the distanced
of the pointa
from the line defined by the two pointsb
andc
:Here is an example showing how the function can be applied:
3D case
In three dimensions, the problem is slightly more complicated. We can use the following two functions:
The main function to calculate the distance can be called in the same way as in the previous example in two dimensions, with the sole difference that now the points are defined by three coordinates representing
x
,y
andz
, as shown in the example below:The equations used in this answer are described in various textbooks and can be found, e.g., here and here.