January 15, 2021, 05:08:37 PM
Welcome,
Guest
. Please
login
or
register
.
Did you miss your
activation email
?
1 Hour
1 Day
1 Week
1 Month
Forever
Login with username, password and session length
Home
Forum
Help
Search
Gallery
Login
Register
SyntaxBomb - Indie Coders
»
Languages & Coding
»
Blitz Code Archives
»
Algorithms
»
[bb] Intersections by Subirenihil [ 1+ years ago ]
« previous
next »
Print
Pages: [
1
]
Go Down
Author
Topic: [bb] Intersections by Subirenihil [ 1+ years ago ] (Read 403 times)
BlitzBot
Jr. Member
Posts: 1
[bb] Intersections by Subirenihil [ 1+ years ago ]
«
on:
June 29, 2017, 12:28:39 AM »
Title :
Intersections
Author :
Subirenihil
Posted :
1+ years ago
Description :
Have fun!
Code :
Code: BlitzBasic
Graphics
1280
,
1024
,
32
,
1
SetBuffer
BackBuffer
(
)
SeedRnd
MilliSecs
(
)
Type
pt
Field
x#,y#
End Type
Type
ln
Field
p1.pt,p2.pt
End Type
Type
arc
Field
c.pt,r#,a1#,a2#
End Type
p1.pt=
New
pt
p1x#=
Rnd
#
(
0
,
1280
)
p1y#=
Rnd
#
(
0
,
1024
)
l1.ln=
New
ln
If
l1p1=
Null
Then
l1p1=
New
pt
If
l1p2=
Null
Then
l1p2=
New
pt
l1p1x#=
Rnd
#
(
0
,
1280
)
l1p1y#=
Rnd
#
(
0
,
1024
)
l1p2x#=
640
;Rnd#(0,1280)
l1p2y#=
512
;Rnd#(0,1024)
l2.ln=
New
ln
If
l2p1=
Null
Then
l2p1=
New
pt
If
l2p2=
Null
Then
l2p2=
New
pt
l2p1x#=
Rnd
#
(
0
,
1280
)
l2p1y#=
Rnd
#
(
0
,
1024
)
l2p2x#=
Rnd
#
(
0
,
1280
)
l2p2y#=
Rnd
#
(
0
,
1024
)
a1.arc=
New
arc
If
a1c=
Null
Then
a1c.pt=
New
pt
a1cx#=
640
;Rnd#(0,1280)
a1cy#=
512
;Rnd#(0,1024)
a1
#=
Rnd
#
(
50
,
250
)
a1a1#=
Rnd
#
(
0
,
360
)
a1a2#=
Rnd
#
(
0
,
360
)
a2.arc=
New
arc
If
a2c=
Null
Then
a2c.pt=
New
pt
a2cx#=
Rnd
#
(
0
,
1280
)
a2cy#=
Rnd
#
(
0
,
1024
)
a2
#=
Rnd
#
(
50
,
250
)
a2a1#=
Rnd
#
(
0
,
360
)
a2a2#=
Rnd
#
(
0
,
360
)
Local
tmp1.pt
Local
tmp2.ln
Local
tmp3.ln
Repeat
l1p1x#=
MouseX
(
)
l1p1y#=
MouseY
(
)
If
tmp1 <>
Null
Delete
tmp1
If
tmp2 <>
Null
Delete
tmp2p1:
Delete
tmp2p2:
Delete
tmp2
If
tmp3 <>
Null
Delete
tmp3p1:
Delete
tmp3p2:
Delete
tmp3
Cls
tmp1.pt=IntersectionLineLine
(
l1,l2
)
tmp2.ln=IntersectionLineArc
(
l1,a1
)
DrawArc a1
DrawArc a2
DrawLn l1
DrawLn l2
DrawPt p1
DrawPt tmp1
If
tmp2<>
Null
Then
DrawPt tmp2p1
If
tmp2<>
Null
Then
DrawPt tmp2p2
If
tmp3<>
Null
Then
DrawPt tmp3p1
If
tmp3<>
Null
Then
DrawPt tmp3p2
Flip
Until
KeyHit
(
1
)
End
Function
DrawPt
(
p.pt
)
If
p <>
Null
Color
255
,
0
,
0
Line
px-
5
,py,px+
5
,py
Line
px,py-
5
,px,py+
5
EndIf
End Function
Function
DrawLn
(
l.ln
)
If
l <>
Null
If
lp1 <>
Null
And
lp2 <>
Null
Color
0
,
255
,
0
Line
lp1x,lp1y,lp2x,lp2y
EndIf
EndIf
End Function
Function
DrawArc
(
a.arc
)
If
a <>
Null
If
ac <>
Null
If
aa1>=aa2
Then
aa2=aa2+
360
LockBuffer
GraphicsBuffer
(
)
asteps#=
Floor
#
(
(
(
a
*
6.2831853072
)
*
(
aa2-aa1
)
)
/
360
)
+
1
For
a1=
0
To
asteps
angle#=aa1#+
(
(
a1/asteps#
)
*
(
aa2-aa1
)
)
WritePixel
acx#+a
#*
Cos
#
(
angle#
)
,acy#-a
#*
Sin
#
(
angle#
)
,
255
Next
UnlockBuffer
GraphicsBuffer
(
)
EndIf
EndIf
End Function
Function
IntersectionLineLine.pt
(
l1.ln,l2.ln
)
If
l1 <>
Null
And
l2 <>
Null
If
l1p1 <>
Null
And
l1p2 <>
Null
And
l2p1 <>
Null
And
l2p2 <>
Null
Local
x1#=l1p1x,y1#=l1p1y,x2#=l1p2x,y2#=l1p2y
Local
x3#=l2p1x,y3#=l2p1y,x4#=l2p2x,y4#=l2p2y
Local
x#,y#,ab#,am#,bb#,bm#
If
x1<>x2
am=
(
y2-y1
)
/
(
x2-x1
)
ab=y1-am*x1
If
x3<>x4
bm=
(
y4-y3
)
/
(
x4-x3
)
bb=y3-bm*x3
If
am<>bm
x=
(
bb-ab
)
/
(
am-bm
)
y=am*x+ab
Else
Return
Null
EndIf
Else
x=x3
y=am*x+ab
If
y3=y4
And
(
x=x3
Or
y=y3
)
Then
Return
Null
EndIf
Else
x=x1
If
x3<>x4
bm=
(
y4-y3
)
/
(
x4-x3
)
bb=y3-bm*x3
y=bm*x+bb
If
y1=y2
And
(
x=x1
Or
y=y1
)
Then
Return
Null
Else
Return
Null
EndIf
EndIf
If
Abs
(
x1-x2
)
<
Abs
(
x1-x
)
+
Abs
(
x2-x
)
Then
Return
Null
If
Abs
(
y1-y2
)
<
Abs
(
y1-y
)
+
Abs
(
y2-y
)
Then
Return
Null
If
Abs
(
x3-x4
)
<
Abs
(
x3-x
)
+
Abs
(
x4-x
)
Then
Return
Null
If
Abs
(
y3-y4
)
<
Abs
(
y3-y
)
+
Abs
(
y4-y
)
Then
Return
Null
r.pt=
New
pt
rx=x
ry=y
Return
r
Else
Return
Null
EndIf
Else
Return
Null
EndIf
End Function
Function
IntersectionLineArc.ln
(
l1.ln,a1.arc
)
If
l1 <>
Null
And
a1 <>
Null
If
l1p1 <>
Null
And
l1p2 <>
Null
And
a1c <>
Null
Local
rtn.ln=
Null
Local
x#
Local
y#
Local
x1#=l1p1x
Local
y1#=l1p1y
Local
x2#=a1cx
Local
y2#=a1cy
Local
f#=l1p2x-l1p1x
Local
g#=l1p2y-l1p1y
Local
r#=a1
Local
t#
Local
root#
root = r*r*
(
f*f+g*g
)
-
(
f*
(
y2-y1
)
-g*
(
x2-x1
)
)
*
(
f*
(
y2-y1
)
-g*
(
x2-x1
)
)
If
root<
0.0
Return
Null
ElseIf
root =
0.0
rtn.ln=
New
ln
rtnp1=
New
pt
rtnp2=
Null
t =
(
f*
(
x2-x1
)
+g*
(
y2-y1
)
)
/
(
f*f+g*g
)
If
t>=
0
And
t<=
1
Then
rtnp1x = x1+f*t
rtnp1y = y1+g*t
ang#=
ATan2
#
(
x2-rtnp1x,y2-rtnp1y
)
:
If
ang<
0
Then
ang=
360
+ang
ang=
(
ang+
90
)
Mod
360
If
a1a1>ang#
Or
a1a2<ang#
Then
Delete
rtnp1
Else
Delete
rtnp1
EndIf
If
rtnp1=
Null
And
rtnp2=
Null
Then
Delete
rtn
Return
rtn
ElseIf
0.0
< root
root#=
Sqr
#
(
root
)
rtn.ln=
New
ln
rtnp1=
New
pt
rtnp2=
New
pt
t =
(
(
f*
(
x2-x1
)
+g*
(
y2-y1
)
)
-root
)
/
(
f*f+g*g
)
If
t>=
0
And
t<=
1
Then
rtnp1x = x1+f*t
rtnp1y = y1+g*t
ang#=
ATan2
#
(
x2-rtnp1x,y2-rtnp1y
)
:
If
ang<
0
Then
ang=
360
+ang
ang=
(
ang+
90
)
Mod
360
If
a1a1>ang#
Or
a1a2<ang#
Then
Delete
rtnp1
Else
Delete
rtnp1
EndIf
t =
(
(
f*
(
x2-x1
)
+g*
(
y2-y1
)
)
+root
)
/
(
f*f+g*g
)
If
t>=
0
And
t<=
1
Then
rtnp2x = x1+f*t
rtnp2y = y1+g*t
ang#=
ATan2
#
(
x2-rtnp2x,y2-rtnp2y
)
:
If
ang<
0
Then
ang=
360
+ang
ang=
(
ang+
90
)
Mod
360
If
a1a1>ang#
Or
a1a2<ang#
Then
Delete
rtnp2
Else
Delete
rtnp2
EndIf
If
rtnp1=
Null
And
rtnp2=
Null
Then
Delete
rtn
Return
rtn
EndIf
Else
Return
Null
EndIf
Else
Return
Null
EndIf
End Function
Comments :
none...
Logged
Print
Pages: [
1
]
Go Up
« previous
next »
SyntaxBomb - Indie Coders
»
Languages & Coding
»
Blitz Code Archives
»
Algorithms
»
[bb] Intersections by Subirenihil [ 1+ years ago ]
SimplePortal 2.3.6 © 2008-2014, SimplePortal