Trigonometrie - Winkel + Seiten berechnung [B3D]

Übersicht BlitzBasic Codearchiv

Neue Antwort erstellen

Fobsi

Betreff: Trigonometrie - Winkel + Seiten berechnung [B3D]

BeitragSa, Sep 11, 2010 23:14
Antworten mit Zitat
Benutzer-Profile anzeigen
Hi @ll

Ka ob es jemand verwenden kann oder ob es überhaupt würdig ist in diesem Bereich zu verweilen. Naja ich poste es nun einfach mal hier. Jeder darf tun und lassen damit was er will:

Nur Code:
BlitzBasic: [AUSKLAPPEN]

Graphics 800,600,0,2
SetBuffer BackBuffer()

Global p1x =1
Global p1y =1
Global w1# =1
Global cx
Global cy
Global lang1#=1

Global p2x =1
Global p2y =1
Global w2# =1
Global lang2#=1

Global p3x =1
Global p3y =1
Global w3# =1
Global lang3#=1

Global posx1
Global posy1

Global posx2
Global posy2

Global posx3
Global posy3

Global alpha#
Global beta#
Global gamma#

Global mh
Global md
Global mh2
Global mx
Global my

timer = CreateTimer(60)

While Not KeyHit(1)
Cls
mx = MouseX()
my = MouseY()
Color 0,255,0
Text 20,20,mh+"-"+md+"/"+mh2+" X:"+mx+" Y:"+my+" p1:"+p1x+"/"+p1y+" p2:"+p2x+"/"+p2y+" p3:"+p3x+"/"+p3y
Text 20,40,"Mit einem Linksklick Punkt setzen ¦ Mit einem Rechtsklick alles löschen ¦ Punkte verschiebbar (ziehen)"
Color 255,0,0
Text 20,60,"Rot -> Winkel (Grad) ¦"
Color 0,0,255
Text 195,60," Blau -> Länge (Pixel)"
r = Rand(1,255)
g = Rand(1,255)
b = Rand(1,255)
Color r,g,b
Text 20,580,"By Fabian + Jürgen - Danke!"

Color 255,255,0
If p2x <> 1 And p1x <> 1 Then
Line (p1x),(p1y),(p2x),(p2y)
EndIf
If p2x <> 1 And p3x <> 1 Then
Line (p2x),(p2y),(p3x),(p3y)
EndIf
If p1x <> 1 And p3x <> 1 Then
Line (p1x),(p1y),(p3x),(p3y)
EndIf

If p1x <> 1 Then
Oval (p1x-5),(p1y-5),10,10,0
EndIf
If p2x <> 1 Then
Oval (p2x-5),(p2y-5),10,10,0
EndIf
If p3x <> 1 Then
Oval (p3x-5),(p3y-5),10,10,0
EndIf

Set_Point (mx,my)
Move_Point(mx,my)
Berechnungen()

If p2x <> 1 And p1x <> 1 Then
Color 255,255,255
Rect posx1,posy1, StringWidth(lang1) + 2, StringHeight(lang1), 1
Color 0,0,255
Text posx1,posy1,lang1
EndIf
If p2x <> 1 And p3x <> 1 Then
Color 255,255,255
Rect posx2,posy2, StringWidth(lang2) + 2, StringHeight(lang2), 1
Color 0,0,255
Text posx2,posy2,lang2
EndIf
If p2x <> 1 And p3x <> 1 Then
Color 255,255,255
Rect posx3,posy3, StringWidth(lang3) + 2, StringHeight(lang3), 1
Color 0,0,255
Text posx3,posy3,lang3
EndIf
If p2x <> 1 And p3x <> 1 Then
Color 255,255,255
Rect p2x+10,p2y+10, StringWidth(gamma) + 2, StringHeight(gamma), 1
Color 255,0,0
Text p2x+10,p2y+10,gamma
EndIf
If p2x <> 1 And p3x <> 1 Then
Color 255,255,255
Rect p3x+10,p3y+10, StringWidth(alpha) + 2, StringHeight(alpha), 1
Color 255,0,01
Text p3x+10,p3y+10,alpha
EndIf
If p2x <> 1 And p3x <> 1 Then
Color 255,255,255
Rect p1x+10,p1y+10, StringWidth(beta) + 2, StringHeight(beta), 1
Color 255,0,0
Text p1x+10,p1y+10,beta
EndIf


If MouseHit(2) = True Then mh2 =1 Else mh2 =0
If MouseDown(1)= True Then md =1 Else md =0
If MouseHit(1) = True Then mh =1 Else mh =0
WaitTimer(timer)
Flip
Wend
End

Function Set_Point(x,y)

If mh = 1 Then
If p1x = 1 Then
p1x =x
p1y =y
Else
If p2x = 1 Then
p2x = x
p2y = y
Else
If p3x = 1 Then
p3x = x
p3y = y
EndIf
EndIf
EndIf
ElseIf mh2 = 1 Then
p1x =1:p1y =1:p2x =1:p2y =1:p3x =1:p3y =1
EndIf

End Function
Function Move_Point(x,y)


If md = 1 Then
If RectsOverlap(x,y,1,1,p1x-25,p1y-25,50,50) = True Then
p1x = x
p1y = y
If md = 0 Then
p1x = x
p1y = y
EndIf
EndIf
If RectsOverlap(x,y,1,1,p2x-25,p2y-25,50,50) = True Then
p2x = x
p2y = y
If md = 0 Then
p2x = x
p2y = y
EndIf
EndIf
If RectsOverlap(x,y,1,1,p3x-25,p3y-25,50,50) = True Then
p3x = x
p3y = y
If md = 0 Then
p3x = x
p3y = y
EndIf
EndIf
EndIf

End Function
Function Berechnungen()
lang1 = Sqr(((p1y - p2y)^2)+((p1x - p2x)^2))
lang2 = Sqr(((p2y - p3y)^2)+((p2x - p3x)^2))
lang3 = Sqr(((p1y - p3y)^2)+((p1x - p3x)^2))

posx1 = Abs((p2x - p1x)/2+p1x)
posy1 = Abs((p2y - p1y)/2+p1y)

posx2 = Abs((p2x - p3x)/2+p3x)
posy2 = Abs((p2y - p3y)/2+p3y)

posx3 = Abs((p1x - p3x)/2+p3x)
posy3 = Abs((p1y - p3y)/2+p3y)

alpha#= ACos((lang1 * lang1 - lang2 * lang2 - lang3 * lang3) / (-2 * lang2 * lang3))
beta# = ACos((lang2 * lang2 - lang3 * lang3 - lang1 * lang1) / (-2 * lang3 * lang1))
gamma#= ACos((lang3 * lang3 - lang1 * lang1 - lang2 * lang2) / (-2 * lang1 * lang2))
End Function


Und zuguterletzt noch die Exe:

http://www.megaupload.com/?d=HUUIRBLY

lg Fobsi

Xeres

Moderator

BeitragSa, Sep 11, 2010 23:27
Antworten mit Zitat
Benutzer-Profile anzeigen
a) Trigonometrie ist nicht unbedingt so kompliziert, dass es noch ein Codearchiveintrag dazu braucht (meine persönliche Einschätzung).
b) Eine genaue Beschreibung, was der Code anstellt ist in jedem Falle nötig.
c) Blitzbasic Code im BlitzMax Archiv?
Win10 Prof.(x64)/Ubuntu 16.04|CPU 4x3Ghz (Intel i5-4590S)|RAM 8 GB|GeForce GTX 960
Wie man Fragen richtig stellt || "Es geht nicht" || Video-Tutorial: Sinus & Cosinus
T
HERE IS NO FAIR. THERE IS NO JUSTICE. THERE IS JUST ME. (Death, Discworld)

hectic

Sieger des IS Talentwettbewerb 2006

BeitragSo, Sep 12, 2010 1:29
Antworten mit Zitat
Benutzer-Profile anzeigen
Nur so als Tipp:

Frag die alte Mausposition ab, ob bei gedrückter Maustaste eine Kollision auf ein Oval statt gefunden hat. Und wenn ja, positioniere es an die aktuelle Mausposition. Dann verliert man nicht den Grip, wenn man mal die Maus mehr als x Pixel pro Frame bewegt.
Download der Draw3D2 V.1.1 für schnelle Echtzeiteffekte über Blitz3D

Holzchopf

Meisterpacker

BeitragSo, Sep 12, 2010 13:21
Antworten mit Zitat
Benutzer-Profile anzeigen
Definitiv im falschen Codearchiv Wink

~VERSCHOBEN~
Dieser Thread passte nicht in das Forum, in dem er ursprünglich gepostet wurde.

mfG
Holzchopf
Erledige alles Schritt um Schritt - erledige alles. - Holzchopf
CC BYBinaryBorn - Yogurt ♫ (31.10.2018)
Im Kopf da knackt's und knistert's sturm - 's ist kein Gedanke, nur ein Wurm

Neue Antwort erstellen


Übersicht BlitzBasic Codearchiv

Gehe zu:

Powered by phpBB © 2001 - 2006, phpBB Group