December 04, 2020, 11:44:26 AM

### Author Topic: [bb] Line Normal by sswift [ 1+ years ago ]  (Read 483 times)

#### BlitzBot

• Jr. Member
• Posts: 1
##### [bb] Line Normal by sswift [ 1+ years ago ]
« on: June 29, 2017, 12:28:41 AM »
Title : Line Normal
Author : sswift
Posted : 1+ years ago

Description : This function will calculate the normal of a line.

Code :
Code: BlitzBasic
1. Global Nx#
2. Global Ny#
3. Global Nd#
4.
5. Function Get_Line_Normal(X1#, Y1#, X2#, Y2#)
6.
7.         ; Calculate the normal of the line, (A = Nx, B = Ny)
8.         ; and the distance of the line (D) from the origin (0,0,0) at it's closest point to the origin.
9.         Nx# = Y2# - Y1#
10.         Ny# = X1# - X2#
11.         Nd# = X2#*Y1# - X1#*Y2#
12.
13.
14.         ; Normalize the normal.
15.         ; (Remove any scaling which will skew our results.  Make the normal's length 1.)
16.         Length# = Sqr(Nx#*Nx# + Ny#*Ny#)
17.         Nx# = Nx# / Length#
18.         Ny# = Ny# / Length#
19.         Nd# = Nd# / Length#
20.
21. End Function

Comments : none...

SimplePortal 2.3.6 © 2008-2014, SimplePortal