GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Download
  • News
  • Community
  • Resources
  • Language Reference
  • SmallBASIC Manual

This view

  • Original page
  • New address

GeezerVison is showing smallbasic.github.io — SmallBASIC | SEGCOS

Edit History

SEGCOS

f = SEGCOS (Ax, Ay, Bx, By, Cx, Cy, Dx, Dy)

Home > Reference > Math

Cosine of the two line segments AB and CD. Start and end of the first line segment are given by the points (Ax,Ay) and (Bx, By). For the second line by (Cx, Cy) and (Dx, Dy).

Example 1:

' Line 1
Ax = 50
Ay = 50
Bx = 50
By = 100

' Line 2
Cx = 100
Cy = 100
Dx = 50
Dy = 100

print "SEGCOS: "; SEGCOS(Ax,Ay,Bx,By,Cx,Cy,Dx,Dy)
print "SEGSIN: "; SEGSIN(Ax,Ay,Bx,By,Cx,Cy,Dx,Dy)
print "Angle between the lines: "; deg(acos(SEGCOS(Ax,Ay,Bx,By,Cx,Cy,Dx,Dy))); "°"

Example 2

' Interactive example to illustrate the geometry
' of SEGCOS and SEGSIN

' Line 1
Ax = 280
Ay = 250
Bx = 250
By = 200

' Line 2
Cx = 400
Cy = 300
Dx = 210
Dy = 300

pen on
while(!pen(12))

  cls
  print "Move Mouse. Press Left Mouse Button to exit"
  
  Dx = pen(10)
  Dy = pen(11)
  
  ResultCos = SEGCOS(Ax,Ay,Bx,By,Cx,Cy,Dx,Dy)
  ResultSin = SEGSIN(Ax,Ay,Bx,By,Cx,Cy,Dx,Dy)
  print "SEGCOS between the two segments: "; ResultCos  ;"
  print "SEGSIN between the two segments: "; ResultSin  ;"
  print "Angle between the two segments : "; DEG(ACOS(ResultCos)); " DEG"
  
  'Calc intersecton of both lines
  'f1(x) = a1*x+b1
  'f2(x) = a2*x+b2
  'f1 = f2
  '-> x0 = (b2-b1) / (a1-a2)
  '-> y0 = f1(x0)
  '  
  if( (Bx - Ax) != 0 AND (Dx - Cx) != 0) then
    a1 = (By - Ay) / (Bx - Ax)
    a2 = (Dy - Cy) / (Dx - Cx)
    b1 = Ay - a1 * Ax
    b2 = Cy - a2 * Cx
  
    X0 = (b2-b1) / (a1-a2) 
    Y0 = a1*X0 + b1
  endif
  
  ' Draw
  line X0, Y0, Ax, Ay color 2  ' Line segment 1
  line X0, Y0, Cx, Cy color 2  ' Line segment 2
  line Ax, Ay, Bx, By color 10 ' Line 1
  line Cx, Cy, Dx, Dy color 10 ' Line 2
  
  
  showpage
  delay(50)
  
wend
Math
ABS   ABSMAX   ABSMIN   ACOS   ACOSH   ACOT   ACOTH   ACSC   ACSCH   ASEC   ASECH   ASIN   ASINH   ATAN   ATAN2   ATANH   ATN   CEIL   COS   COSH   COT   COTH   CSC   CSCH   DEG   DERIV   DETERM   DIFFEQN   EXP   EXPRSEQ   FIX   FLOOR   FRAC   INT   INTERSECT   INVERSE   LINEQN   LOG   LOG10   M3APPLY   M3IDENT   M3ROTATE   M3SCALE   M3TRANS   MAX   MIN   POLYAREA   POLYCENT   POLYEXT   POW   PTDISTLN   PTDISTSEG   PTSIGN   RAD   RND   ROOT   ROUND   SEC   SECH   SEGCOS   SEGLEN   SEGSIN   SEQ   SGN   SIN   SINH   SQR   STATMEAN   STATMEANDEV   STATMEDIAN   STATSPREADP   STATSPREADS   STATSTD   SUM   SUMSQ   TAN   TANH   TRANSPOSE  
This page was last edited on Wed, 2 Aug 2023 10:07:23 +0200 | Markdown processed with pandoc 3.1.12.1
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.