Click here to Skip to main content
15,897,273 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I have a straight line in space with an start and end point (x,y,z) and I am attempting to get the angle but I cannot figure out the formula for this. I am using VB.NET

Here is a picture of the line in my 3d environment (the one that is circled in red)

If someone can help, it would be appreciated. Again, i have the values of the start and end points (x,y,z)

It is set to an angle of 70 degrees right now.
Posted
Updated 20-Jan-15 7:53am
v2
Comments
Sergey Alexandrovich Kryukov 20-Jan-15 12:43pm    
Angle between what and what? If you want to get direction relative to coordinate system, this is not one angle but two.
Just learn a bit of vector algebra; if someone write some code for you, it won't help you. Do I even have to explain why?
—SA

VB
Dim x, y, z As Double

        x = EndPoint.X - StartPoint.X
        y = EndPoint.Y - StartPoint.Y
        z = EndPoint.Z - StartPoint.Z

        'a = arcsin(v.z / sqrt(v.x²+v.y²+v.z²))
        MsgBox((Math.Asin(z / Math.Sqrt((x ^ 2) + (y ^ 2) + (z ^ 2)))) * (180 / Math.PI))



Is the solution. Someone was kind enough to assist me on another site!
 
Share this answer
 
Comments
[no name] 20-Jan-15 15:57pm    
Then it would be nice for the autrhor of the other site to give a link to it!
Richard MacCutchan 27-Jan-15 11:23am    
Well that's clearly mathematics rather than programming.
That is a mathematical question, nothing to do with VB.NET, or any other language. As far as I recall it has something to do with the length of the sides, and sines, cosines etc.
 
Share this answer
 
Comments
jk0391 20-Jan-15 12:34pm    
Well I'd like to get the proper code to execute the formula which at the same time I am trying to find.
Richard MacCutchan 20-Jan-15 12:45pm    
The code is easy once you know the formula. And Google will find that for you.
jk0391 20-Jan-15 12:55pm    
Would you be able to help? I've been searching google for hours :(
Richard MacCutchan 20-Jan-15 13:04pm    
Seriously? You couldn't work out https://www.google.coM/search?q=calculate+angle?
jk0391 20-Jan-15 13:38pm    
It's more complicated than that. You also don't have to be rude.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900