Vector Projection

Share:

Description

Vector Projection information, such as angle and distances between points

Usage

1
vecproj(P1, P2)

Arguments

P1

Point 1

P2

Point 2

Details

The distances returned are the legs of right right triangles where the cosine of the angle is used to get the projection distance of the opposite side on the specified direction. See the example for an illustration.

Value

cang=cang, angrad=angrad, angdeg=angdeg, dis1=d1, dis2=d2

cang

cosine of angle between points

angrad

angle, radians

angdeg

angle, degrees

dis1

distance

dis2

distance

Author(s)

Jonathan M. Lees<jonathan.lees@unc.edu>

See Also

perpproj

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
P1 = c(2, 3)
P2 = c(5, 2)


I = vecproj(P1, P2)


plot(c(0, P1[1], P2[1]), c(0, P1[2], P2[2]), asp=1, ann=FALSE)

arrows(0, 0, P1[1],  P1[2], length=.1)
arrows(0, 0,  P2[1],  P2[2], length=.1)

text(P1[1],  P1[2], "Point 1", pos=3)
text(P2[1],  P2[2], "Point 2", pos=3)

j1 = atan2(P1[2], P1[1])*180/pi
j2 = atan2(P2[2], P2[1])*180/pi

L1 = vlength(P1)
L2 = vlength(P2)

A = GEOmap::darc(L1*.2, j1, j2, 0, 0, n=1)

lines(A)
an = length(A$x)
arrows(A$x[an-1] , A$y[an-1] ,A$x[an] , A$y[an] ,  length=.08 )

text(A$x[an/2] , A$y[an/2], labels=format(I$angdeg, digits=4)  , pos=4)


 V1 = c( 0,P1[1], 0,  P1[2])
   V2 = c( 0,P2[1], 0,  P2[2])
  

    PP = perpproj( V1, V2, add=FALSE  )

arrows(P1[1],P1[2],PP$P2[1], PP$P2[2],  length=.07, lty=2, col='red') 
arrows(P2[1],P2[2],PP$P1[1], PP$P1[2],  length=.07, lty=2, col='blue') 

 labelLine( c(0, 0) , PP$P2 , lab="dis1", dinch = .25, aty=1,
acol='blue', above=FALSE  )


 labelLine( c(0, 0) , PP$P1 , lab="dis2", dinch = .25, aty=1,
acol='blue'  )

Want to suggest features or report bugs for rdrr.io? Use the GitHub issue tracker.