# How to find the projection of vectors from corrdinates?

3 views (last 30 days)
Karl Bridggie on 14 Sep 2022
Commented: Karl Bridggie on 15 Sep 2022
Hi,
If I have the corrdinates of two vectors (not the elements of the vectors) in 2D plane
v1: from (1, 2) to (9, 10)
v2: from (9, 10) to (6, 14)
is there a way to get the projection of v1 on v2?
Thanks a lot for your help!
##### 2 CommentsShowHide 1 older comment
Karl Bridggie on 14 Sep 2022
Thanks Dyuman! I know how to do it in maths, and I think I should use the dot function in MATLAB. If the vectors are u and v, then I need to do something like this:
dot(u,v) / dot(v,v) * v;
My problem is I don't know how to convert the vectors in corrdinate format (as v1 and v2 in the question) to the format that is suitable for the dot function.

Sign in to comment.

### Accepted Answer

Dyuman Joshi on 14 Sep 2022
Proceed the same way as you would on pen and paper. You can use points to define the vector -
%[x-coordinate y-coordinate]
p1=[1 2];
p2=[9 10];
p3=[9 10];
p4=[6 14];
%defining vectors
v1=p2-p1;
v2=p4-p3;
%Therefore, projection of v1 on v2 is
projv1_v2=dot(v1,v2)/dot(v2,v2)*v2
projv1_v2 = 1×2
-0.9600 1.2800
##### 1 CommentShowHide None
Karl Bridggie on 15 Sep 2022
Thank you @Dyuman Joshi! I didn't know we could define the vectors that way.

Sign in to comment.

### Categories

Find more on Linear Algebra in Help Center and File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by