90° Winkel an beliebige Strecke antragen
Übersicht

![]() |
StarwarBetreff: 90° Winkel an beliebige Strecke antragen |
![]() Antworten mit Zitat ![]() |
---|---|---|
Hallo,
Kann mir jemand sagen, wie ich an eine beliebige Strecke (im Bild lila) einen 90° Winkel antragen kann? Bin erst in der 9. und hab daher kaum Ahnung von den ganzen Winkelfunktionen... ![]() Danke schonmal |
||
![]() |
Smily |
![]() Antworten mit Zitat ![]() |
---|---|---|
Welche Variablen sind dir denn gegeben? (startkoords, endkoords der Linie? Oder Startkoords + Richtung + Ausdehnung? ODer ganz anders? ) | ||
![]() |
SpionAtom |
![]() Antworten mit Zitat ![]() |
---|---|---|
Wenn du zwei Punkte einer Geraden gegeben hast, ist dieses eine Möglichkeit:
Code: [AUSKLAPPEN] SetBuffer BackBuffer()
Repeat ;Dragdropzeugs If drag = 0 And MouseDown(1) Then x1 = MouseX() y1 = MouseY() drag = 1 End If If drag = 1 And MouseDown(1) Then x2 = MouseX() y2 = MouseY() End If If drag = 1 And (Not MouseDown(1)) Then drag = 0 End If ;orthogonale berechnen ox1 = (x1 + x2) / 2 - Sin(Winkel(x1, y1, x2, y2) - 90) * 400 oy1 = (y1 + y2) / 2 - Cos(Winkel(x1, y1, x2, y2) - 90) * 400 ox2 = (x1 + x2) / 2 - Sin(Winkel(x1, y1, x2, y2) + 90) * 400 oy2 = (y1 + y2) / 2 - Cos(Winkel(x1, y1, x2, y2) + 90) * 400 Cls Text 0, 0, "Ziehen Sie mit gedrückter Maustaste eine Linie" Oval x1 - 2, y1 - 2, 4, 4 ;vorgegebene Linie Oval x2 - 2, y2 - 2, 4, 4 Line x1, y1, x2, y2 ;orthogonale Linie Line ox1, oy1, ox2, oy2 Flip() Until KeyDown(1) End ;Berechnet den Winkel zwischen der X-Achse und einer Geraden durch zwei Punkte Function Winkel#(x1#,y1#,x2#,y2#) Return (360+ATan2(x1#-x2#,y1#-y2#)) Mod 360 End Function |
||
os: Windows 10 Home cpu: Intel Core i7 6700K 4.00Ghz gpu: NVIDIA GeForce GTX 1080 |
![]() |
Starwar |
![]() Antworten mit Zitat ![]() |
---|---|---|
Das ging ja schnell!
Es ist der Start und der Endpunkt der Ausgangsgerade gegeben. Die Variante von SpionAtom scheint das richtige zu sein. Ich spiele mal ein bisschen damit rum. Danke an euch. |
||
![]() |
StarwarBetreff: Neues Problem |
![]() Antworten mit Zitat ![]() |
---|---|---|
Hallo nochmal,
Ich barauch(te) die winkelfunktion um ne Winkelschnecke zu zeichnen. Mein nächstes Problem ist, dass die Kathete immer krürzer wird. ic denke es liegt bei "*l#;". Code: [AUSKLAPPEN] SeedRnd MilliSecs() Graphics 800,600,32,2 SetBuffer BackBuffer() x# = 350 y# = 320 l# = 100 startx# = x# starty# = y# Color 255,255,255 Line x#,y#,x#+l#,y# ;X-Linie Line x#,y#,x#,y#-l# ;Y-Linie Color Rand(100,255),Rand(100,255),Rand(100,255) Line x#,y#-l#,x+l#,y# ;Hypothenuse Flip WaitKey ax# = x# ;ax Aandock-X ay# = y#-l# y1 =starty# :x1 = startx#+l# y = y - l# Flip() For mal = 1 To 20000 r = Rand(100,255): b=Rand(100,255):g=Rand(100,255) x2 = x#: y2 = y# ;If mal = 0 Then y2=y2-l# : x2 = x2 + l# :Color 0,255,0 : Oval x2,y2,4,4 : Flip() : WaitKey() Color r,g,b: Oval x2,y2,4,4 :Oval x1,y1,4,4 :Text x1+5,y1+5,"1" :Text x2+5,y2+5,"2" Color 255,255,255 ox1 = (x1 + x2) / 2 - Sin(Winkel(x1, y1, x2, y2)-90)*l#; oy1 = (y1 + y2) / 2 - Cos(Winkel(x1, y1, x2, y2)-90 )*l# ox2 = (x1 + x2) / 2 - Sin(Winkel(x1, y1, x2, y2)+90)*-l#;* oy2 = (y1 + y2) / 2 - Cos(Winkel(x1, y1, x2, y2)+90 )*-l# Line ax#,ay#, ox2-l#/2, oy2-l#/2 ;90° Strecke Color r,g,b Line startx#+l#,starty#,ox2-l#/2, oy2-l#/2 ;Verbindung Color 255,255,255 x# = ox2-l#/2 y# = oy2-l#/2 ax# = x# ay# = y# Flip() WaitKey() If KeyDown(1) Then End Next Delay 1000 :End Function Winkel#(x1#,y1#,x2#,y2#) Return (360+ATan2(x1#-x2#,y1#-y2#)) Mod 360 End Function Bitte entschuldigt, dass der Code so unordentlich ist ![]() Kann mir jemand helfen? Danke. |
||
Dreamora |
![]() Antworten mit Zitat ![]() |
|
---|---|---|
relativ hässlicher und rechenintensiver code wenn man genau so gut vektoren nehmen kann. Denn in 2D ist ein orthogonaler vektor sehr einfach!
Vector1 = (x,y) -> orthogonaler Vector2 = (y, -x) oder (-y, x) also einfach die richtungen vertauschen und eine der beiden negieren. Das wars moved |
||
Ihr findet die aktuellen Projekte unter Gayasoft und könnt mich unter @gayasoft auf Twitter erreichen. |
![]() |
SpionAtom |
![]() Antworten mit Zitat ![]() |
---|---|---|
Könnte dies eine Winkelschnecke sein?
Code: [AUSKLAPPEN] Graphics 1024, 768, 0, 2 SetBuffer BackBuffer() mx = GraphicsWidth() * 0.5 my = GraphicsHeight() * 0.5 segment = 10 DrawWinkelSchnecke(mx, my, mx - segment, my, segment) End Function DrawWinkelSchnecke(x, y, x2, y2, L#) Color 255, 0, 0 Line x, y, x2, y2 w = Winkel(x, y, x2, y2) - 90 nx = x2 - Sin(w) * L# ny = y2 - Cos(w) * L# nw = Winkel(x, y, nx, ny) Color 0, 255, 0 Line x2, y2, nx, ny Flip() If KeyDown(1) Then End DrawWinkelSchnecke(x, y, nx, ny, L) End Function ;Berechnet den Winkel zwischen der X-Achse und einer Geraden durch zwei Punkte Function Winkel#(x1#,y1#,x2#,y2#) Return (360+ATan2(x1#-x2#,y1#-y2#)) Mod 360 End Function Edit: Hier findet man die Wurzelschnecke/Spirale, und auch einige andere interessante Figuren. |
||
os: Windows 10 Home cpu: Intel Core i7 6700K 4.00Ghz gpu: NVIDIA GeForce GTX 1080 |
Übersicht


Powered by phpBB © 2001 - 2006, phpBB Group