Weekly Qbasic and Qb64 Lesson Topics
March 29, 2024, 04:13:11 am
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News: Want to see a specific Tutorial? ASK!
 
  Home Help Search Arcade Links Staff List Login Register  

geometry

Pages: [1]
  Print  
Author Topic: geometry  (Read 292 times)
659_minifly
Guest
« on: June 07, 2011, 04:08:05 pm »

hello

How to calculate the angle of a line passing by 2 points



Code:
Angle_Line 0.0,0.0, 0.0,150.0


sub Angle_Line (xDeb as double, yDeb as double, xFin as double, yFin as double)

Dim Tangeante, Angle_Rad As Double
Dim pI As Double
'PI = 4 * Atn(1)
pI = 3.1459265359

If (xFin - xDeb) = 0 Then GoTo Verti:

Tangeante = (yFin - yDeb) / (xFin - xDeb)

Angle_Rad = Atn(Tangeante)

Angle_Ligne = Angle_Rad * 57.29577951308 '(180 / pI)

GoTo Fin_ANGLE_LIGNE:

Verti:

  If (yFin - yDeb) > 0 Then Angle_Ligne = 90
  If (yFin - yDeb) < 0 Then Angle_Ligne = -90

Fin_ANGLE_LIGNE:

print  Angle_Ligne

End sub

How to calculate intersection of 2 lines

giving 2 points for the first line and 2 points for the second line return the intersection point in X1 and Y1

Code:

        line_intersect 0.0,0.0,100,100,0,15,100,15

Sub Line_intersect (Xdeb1 as double, Ydeb1 as double, Xfin1 as double, Yfin1 as double, Xdeb2 as double, Ydeb2 as double, Xfin2 as double, Yfin2 as double)



XA = Xdeb1
YA = Ydeb1
XB = Xfin1
YB = Yfin1


XC = Xdeb2
YC = Ydeb2
XD = Xfin2
YD = Yfin2

 UP = YD - YC
 VP = XC - XD
 WP = (YC * XD) - (XC * YD)


 U = YB - YA
 V = XA - XB
 W = (YA * XB) - (XA * YB)

X1 = ((V * WP) - (VP * W)) / ((U * VP) - (UP * V))
Y1 = ((W * UP) - (WP * U)) / ((U * VP) - (UP * V))

Intersection_X = X1
Intersection_Y = Y1

print x1,y1

end sub



« Last Edit: June 07, 2011, 04:12:42 pm by 659_minifly » Report Spam   Logged

Share on Facebook Share on Twitter

OlDosLover
Guest
« Reply #1 on: June 07, 2011, 06:24:42 pm »

Hi all,
    Nice additions minifly. Thank you very much. Look forward to seeing many more.
OlDosLover.
Report Spam   Logged

Pages: [1]
  Print  
 
Jump to:  

Powered by EzPortal
Bookmark this site! | Upgrade This Forum
SMF For Free - Create your own Forum


Powered by SMF | SMF © 2016, Simple Machines
Privacy Policy