Angle between two vectors in 3d (2024)

184 views (last 30 days)

Show older comments

developer on 20 Sep 2011

  • Link

    Direct link to this question

    https://www.mathworks.com/matlabcentral/answers/16243-angle-between-two-vectors-in-3d

  • Link

    Direct link to this question

    https://www.mathworks.com/matlabcentral/answers/16243-angle-between-two-vectors-in-3d

Commented: Bruno Luong on 1 Feb 2023

Accepted Answer: Jan

Hello,

I have two vectors in 3d and i want to find the angle between those two vectors.

Thanks in advance

0 Comments

Show -2 older commentsHide -2 older comments

Sign in to comment.

Sign in to answer this question.

Accepted Answer

Jan on 20 Sep 2011

  • Link

    Direct link to this answer

    https://www.mathworks.com/matlabcentral/answers/16243-angle-between-two-vectors-in-3d#answer_21971

  • Link

    Direct link to this answer

    https://www.mathworks.com/matlabcentral/answers/16243-angle-between-two-vectors-in-3d#answer_21971

Open in MATLAB Online

Or:

angle = atan2(norm(cross(a,b)), dot(a,b))

See this compact discussion about this topic: CSSM: Angle between two vectors . Only 71 replies (Google finds 89 replies, so I assume 18 spam messages?) and 68300 views currently...

[EDITED]: W. Kahan suggested in his paper "Mindeless.pdf":

2 * atan(norm(x*norm(y) - norm(x)*y) / norm(x * norm(y) + norm(x) * y))

9 Comments

Show 7 older commentsHide 7 older comments

developer on 20 Sep 2011

Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/16243-angle-between-two-vectors-in-3d#comment_35872

  • Link

    Direct link to this comment

    https://www.mathworks.com/matlabcentral/answers/16243-angle-between-two-vectors-in-3d#comment_35872

Thanks simon :)

actually i have seen this thread before and confused with

angle = atan2(norm(cross(a,b)), dot(a,b))

and

acos(dot(v1, v2) / (norm(v1) * norm(v2)))

Jan on 20 Sep 2011

Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/16243-angle-between-two-vectors-in-3d#comment_35893

  • Link

    Direct link to this comment

    https://www.mathworks.com/matlabcentral/answers/16243-angle-between-two-vectors-in-3d#comment_35893

The ATAN2 approach has a higher numerical stability, but it is slower. Although Matlab states in the documentation, that ACOS from the FDLIBM library is use, I cannot reproduce the results exactly using the source from netlib.org. But the differences concern the angles very near to 0 and 180 degrees.

TAEYUN on 30 Oct 2014

Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/16243-angle-between-two-vectors-in-3d#comment_246675

  • Link

    Direct link to this comment

    https://www.mathworks.com/matlabcentral/answers/16243-angle-between-two-vectors-in-3d#comment_246675

hey simon I have some questions if i have 3values of x,y,z how can i find angle between two 3d vectors?

Bineet_Mehra on 28 Apr 2016

Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/16243-angle-between-two-vectors-in-3d#comment_362281

  • Link

    Direct link to this comment

    https://www.mathworks.com/matlabcentral/answers/16243-angle-between-two-vectors-in-3d#comment_362281

I have u1 v1 w1(velocity components) volumetric data. Size of u1 is NxNxN (N is 100) and same is true frol v1 and w1.

I have one more case of u2, v2, w2, each one of size NxNxN. both these data sets are obtained from TriScatteredInterp and meshgrid. Basically i plotted streamlines for these two cases and now i want to see how much deviation is there between these streamlines (from case 1 to 2.). I need to find the angle between them at the points given by meshgrid. But cross product wont work (A and B must have at least one dimension of length 3.).. any suggestion ?? Thanks a lot

Jan on 28 Apr 2016

Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/16243-angle-between-two-vectors-in-3d#comment_362287

  • Link

    Direct link to this comment

    https://www.mathworks.com/matlabcentral/answers/16243-angle-between-two-vectors-in-3d#comment_362287

Open in MATLAB Online

@Bineet_Mehra: Please open a new thread for a new problem. Otherwise you cannot accept an answer as a solution.

I guess you want:

vel1 = [u1(:), v1(:), w1(:)]

vel2 = [u2(:), v2(:), w2(:)]

Now the cross-product should work.

Bineet_Mehra on 29 Apr 2016

Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/16243-angle-between-two-vectors-in-3d#comment_362472

  • Link

    Direct link to this comment

    https://www.mathworks.com/matlabcentral/answers/16243-angle-between-two-vectors-in-3d#comment_362472

@Jan Simon, Thanks for your suggestion. I shall open a new thread and will try the solution given by you.

Thanks

Bineet_Mehra on 29 Apr 2016

Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/16243-angle-between-two-vectors-in-3d#comment_362498

  • Link

    Direct link to this comment

    https://www.mathworks.com/matlabcentral/answers/16243-angle-between-two-vectors-in-3d#comment_362498

http://fr.mathworks.com/matlabcentral/answers/281635-cross-product-multi-dim-data new thread and new answer

Dyuman Joshi on 1 Feb 2023

Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/16243-angle-between-two-vectors-in-3d#comment_2592555

  • Link

    Direct link to this comment

    https://www.mathworks.com/matlabcentral/answers/16243-angle-between-two-vectors-in-3d#comment_2592555

@Jan the CSSM thread you linked does not exist anymore.

Do you happen to have an archived link for that thread?

I am unable to find the thread by simply searching the title, on the Google Groups (CSSM archive)

Bruno Luong on 1 Feb 2023

Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/16243-angle-between-two-vectors-in-3d#comment_2592640

  • Link

    Direct link to this comment

    https://www.mathworks.com/matlabcentral/answers/16243-angle-between-two-vectors-in-3d#comment_2592640

Sign in to comment.

More Answers (3)

Lucas García on 20 Sep 2011

  • Link

    Direct link to this answer

    https://www.mathworks.com/matlabcentral/answers/16243-angle-between-two-vectors-in-3d#answer_21970

  • Link

    Direct link to this answer

    https://www.mathworks.com/matlabcentral/answers/16243-angle-between-two-vectors-in-3d#answer_21970

Open in MATLAB Online

You can use the subspace function to find the angle between two subspaces:

>> subspace([1;0;0],[0;1;0])

ans =

1.5708

1 Comment

Show -1 older commentsHide -1 older comments

Yadu Bhusal on 5 Aug 2021

Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/16243-angle-between-two-vectors-in-3d#comment_1675117

  • Link

    Direct link to this comment

    https://www.mathworks.com/matlabcentral/answers/16243-angle-between-two-vectors-in-3d#comment_1675117

I have 3 points in a line( suppose) and one calculations point separately. A(1,1,1)B(2,2,2)C(3 3 3) in a line and P( 5 5 5) as separate. I want to calculate angle A which is subtended by distance AP. And similar for BP,CP. Is it possible to find angles or make program to calculate these angles at once?

Sign in to comment.

David Young on 20 Sep 2011

  • Link

    Direct link to this answer

    https://www.mathworks.com/matlabcentral/answers/16243-angle-between-two-vectors-in-3d#answer_21969

  • Link

    Direct link to this answer

    https://www.mathworks.com/matlabcentral/answers/16243-angle-between-two-vectors-in-3d#answer_21969

Open in MATLAB Online

acos(dot(v1, v2) / (norm(v1) * norm(v2)))

EDIT: Having seen Jan Simon's reply, and the long thread at CSSM that he refers to, I realise that the formula I proposed is not a particularly good one. The two methods in Jan's reply are both likely to be preferable.

2 Comments

Show NoneHide None

developer on 20 Sep 2011

Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/16243-angle-between-two-vectors-in-3d#comment_35871

  • Link

    Direct link to this comment

    https://www.mathworks.com/matlabcentral/answers/16243-angle-between-two-vectors-in-3d#comment_35871

Thanks actually i have seen the post referred by Jan simon

and confused that what is the difference between

angle = atan2(norm(cross(a,b)), dot(a,b))

and

acos(dot(v1, v2) / (norm(v1) * norm(v2)))

Jan on 20 Sep 2011

Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/16243-angle-between-two-vectors-in-3d#comment_35896

  • Link

    Direct link to this comment

    https://www.mathworks.com/matlabcentral/answers/16243-angle-between-two-vectors-in-3d#comment_35896

Mathematically identical, but numerically more stable, when the vectors have very different lengths:

acos(dot(v1 / norm(v1), v2 / norm(v2)))

Sign in to comment.

rashi on 15 Jun 2018

  • Link

    Direct link to this answer

    https://www.mathworks.com/matlabcentral/answers/16243-angle-between-two-vectors-in-3d#answer_324832

  • Link

    Direct link to this answer

    https://www.mathworks.com/matlabcentral/answers/16243-angle-between-two-vectors-in-3d#answer_324832

hi I want to find the angle in azimuth and elevation plane between wo vectors in 3d. please help

0 Comments

Show -2 older commentsHide -2 older comments

Sign in to comment.

Sign in to answer this question.

See Also

Categories

MATLABMathematicsSparse Matrices

Find more on Sparse Matrices in Help Center and File Exchange

Tags

  • angle
  • vectors
  • 3d

Community Treasure Hunt

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

Start Hunting!

An Error Occurred

Unable to complete the action because of changes made to the page. Reload the page to see its updated state.


Angle between two vectors in 3d (18)

Select a Web Site

Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .

You can also select a web site from the following list

Americas

  • América Latina (Español)
  • Canada (English)
  • United States (English)

Europe

  • Belgium (English)
  • Denmark (English)
  • Deutschland (Deutsch)
  • España (Español)
  • Finland (English)
  • France (Français)
  • Ireland (English)
  • Italia (Italiano)
  • Luxembourg (English)
  • Netherlands (English)
  • Norway (English)
  • Österreich (Deutsch)
  • Portugal (English)
  • Sweden (English)
  • Switzerland
    • Deutsch
    • English
    • Français
  • United Kingdom(English)

Asia Pacific

  • Australia (English)
  • India (English)
  • New Zealand (English)
  • 中国
  • 日本Japanese (日本語)
  • 한국Korean (한국어)

Contact your local office

Angle between two vectors in 3d (2024)
Top Articles
When His Eyes Turn Into Hearts - Chapter 1 - wendy_deluxe
10 Rarest and Most Valuable Milk Glass Pieces: Value Guide
Drury Inn & Suites Bowling Green
Global Foods Trading GmbH, Biebesheim a. Rhein
Access-A-Ride – ACCESS NYC
Www.politicser.com Pepperboy News
Get train & bus departures - Android
Best Cav Commanders Rok
Camstreams Download
Delectable Birthday Dyes
Ukraine-Russia war: Latest updates
Sport Clip Hours
6th gen chevy camaro forumCamaro ZL1 Z28 SS LT Camaro forums, news, blog, reviews, wallpapers, pricing – Camaro5.com
Radio Aleluya Dialogo Pastoral
Springfield Mo Craiglist
2 Corinthians 6 Nlt
Convert 2024.33 Usd
Lehmann's Power Equipment
Concordia Apartment 34 Tarkov
Robert Deshawn Swonger Net Worth
Xsensual Portland
Qhc Learning
Gazette Obituary Colorado Springs
Lost Pizza Nutrition
Kabob-House-Spokane Photos
WRMJ.COM
Skidware Project Mugetsu
Scott Surratt Salary
Askhistorians Book List
Tokioof
The Rise of "t33n leaks": Understanding the Impact and Implications - The Digital Weekly
Scat Ladyboy
Gr86 Forums
Craigslist Greencastle
Gwu Apps
Compare Plans and Pricing - MEGA
Trizzle Aarp
Convenient Care Palmer Ma
Vons Credit Union Routing Number
O'reilly's El Dorado Kansas
Shoecarnival Com Careers
Citibank Branch Locations In North Carolina
Top 40 Minecraft mods to enhance your gaming experience
Academic Calendar / Academics / Home
Brauche Hilfe bei AzBilliards - Billard-Aktuell.de
Pickwick Electric Power Outage
Wisconsin Volleyball titt*es
F9 2385
Ciara Rose Scalia-Hirschman
Deviantart Rwby
Ravenna Greataxe
Comenity/Banter
Latest Posts
Article information

Author: Rev. Porsche Oberbrunner

Last Updated:

Views: 5862

Rating: 4.2 / 5 (53 voted)

Reviews: 84% of readers found this page helpful

Author information

Name: Rev. Porsche Oberbrunner

Birthday: 1994-06-25

Address: Suite 153 582 Lubowitz Walks, Port Alfredoborough, IN 72879-2838

Phone: +128413562823324

Job: IT Strategist

Hobby: Video gaming, Basketball, Web surfing, Book restoration, Jogging, Shooting, Fishing

Introduction: My name is Rev. Porsche Oberbrunner, I am a zany, graceful, talented, witty, determined, shiny, enchanting person who loves writing and wants to share my knowledge and understanding with you.