# Determining angle

I'm programming in vb .Net and i need to know how to determine angles. For example i have a figura like the following:

|
|
|
------------------
|
|
|
and i need to determine the left, inferior angle. How can i do that?

• [CODE]
|
|
|
------------------
|
|
|
[/CODE]

Now we understand eachother better...
Use some math func
Look at some math site
They got good examples and helpings on how to do.

I can't remember how to do it, I think you should use the tan func.

Wait, now I looked, and you should take a point a specific distance from the crossing and the same for the other, then calculate the height difference and the width difference and use the atan2 on them.

[CODE]
|
[red][b]|[/b][/red]
|
------------[green][b]-[/b][/green]-----
|
|
|

[/CODE]
[red]First point[/red] x1,y1
[green]Second point[/green] x2,y2
whatyouwant = atan2(x1-x2,y1-y2)

[b]Niklas Ulvinge[/b] [white]aka [b]IDK[/b][/white]

• Yes, i see, but what hapens when i have an angle like this?

/
/
/
/

I can't use the same equation, or can i?

thanks

: [CODE]
: |
: |
: |
: ------------------
: |
: |
: |
: [/CODE]
:
: Now we understand eachother better...
: Use some math func
: Look at some math site
: They got good examples and helpings on how to do.
:
: I can't remember how to do it, I think you should use the tan func.
:
: Wait, now I looked, and you should take a point a specific distance from the crossing and the same for the other, then calculate the height difference and the width difference and use the atan2 on them.
:
: [CODE]
: |
: [red][b]|[/b][/red]
: |
: ------------[green][b]-[/b][/green]-----
: |
: |
: |
:
: [/CODE]
: [red]First point[/red] x1,y1
: [green]Second point[/green] x2,y2
: whatyouwant = atan2(x1-x2,y1-y2)
:
: [b]Niklas Ulvinge[/b] [white]aka [b]IDK[/b][/white]
:
:

• Use the code tags ([leftbr]code[rightbr] to display line's as spaces dissaper
[code]
/
/
/
/

[/code]

It should work.

I thoght of another way of doing it, see the red line, use pytagoras theorem to calculate it, and then use the sinus formulas to calculate...
[code]
/
/
/[red]|[/red]
/ [red]|[/red]
[red]|[/red]
[red]|[/red]

[/code]

Still try to search the web on trigonometry and you'll find what you want (and you'll maybe learn something, I'm 15 and we haven't started with trignometry at school, but I still know a lot).

[b]Niklas Ulvinge[/b] [white]aka [b]IDK[/b][/white]

• : I'm programming in vb .Net and i need to know how to determine angles. For example i have a figura like the following:
:
: |
: |
: |
: ------------------
: |
: |
: |
: and i need to determine the left, inferior angle. How can i do that?
:
angle_of_line_a = ATan((ay2-ay1)/(ax2-ax1))
angle_of_line_b = ATan((by2-by1)/(bx2-bx1))
angle_between_a_n_b = angle_of_line_a - angle_of_line_b

• : angle_of_line_a = ATan[red]2[/red]((ay2-ay1)[red],[/red] (ax2-ax1))
: angle_of_line_b = ATan[red]2[/red]((by2-by1)[red],[/red] (bx2-bx1))
: angle_between_a_n_b = angle_of_line_a - angle_of_line_b
:
The changes I did in [red]red[/red] will make the code better, but I don't know if VB supports ATAN2 ...
I usually don't program in VB...

[b]Niklas Ulvinge[/b] [white]aka [b]IDK[/b][/white]

• [b][red]This message was edited by Shoaib Nawaz at 2005-9-26 15:0:14[/red][/b][hr]
: : angle_of_line_a = ATan[red]2[/red]((ay2-ay1)[red],[/red] (ax2-ax1))
: : angle_of_line_b = ATan[red]2[/red]((by2-by1)[red],[/red] (bx2-bx1))
: : angle_between_a_n_b = angle_of_line_a - angle_of_line_b
: :
: The changes I did in [red]red[/red] will make the code better, but I don't know if VB supports ATAN2 ...
: I usually don't program in VB...
:
: [b]Niklas Ulvinge[/b] [white]aka [b]IDK[/b][/white]
:
:
ATan is Arc Tangent but What is ATan2?
ATan2 is not supported in VB.
However I made a mistake in my code that [red]ATan[/red] instead [red]Math.Atn[/red]
What kind of your correction with red comma?

Line Angle is the Arc Tangent of Slope of line. And Slope is the rise/step of line's end points.

Rise = ay2 - ay1
Step = ax2 - ax1

angle_of_a_line = Math.Atn(Rise/Step)

And similarly the angle of other line.

• : What kind of your correction with red comma?

Atn is bad becouse it will give you wrong values. (this maybe wont aply to VB. But in lot of other languages it will)
Atn2(x, y) is the same as Atn(x/y) only it gives the rigth values...

The following code is in C#, but applies to VB.Net to.
When trying to get the argument of a complex number, it's wrong to use math.atn(i/r)...
[code]
...
public struct ComplexNumber
{
//real
public double r;
public double i;
//imaginary variables
public double argument
{
get
{
//return Math.Atan(i / r); wrong!
return Math.Atan2(i, r);
}
set
{
r = modulus * Math.Cos(value);
i = modulus * Math.Sin(value);
}
}
...
[/code]

[b]Niklas Ulvinge[/b] [white]aka [b]IDK[/b][/white]