Sign in to follow this  
Followers 0
maestro

Multi-Origin vectors/triangles

3 posts in this topic

Hi, I'm trying to make a graph calculator sort of thing that can take 2 points on a grid and find out what direction origin 2 is from origin 1.

For example, you have a point at 50,50 and another point at -10,70 (this should be somewhere between 270 and 360 for this example)

is there any way to have it fill into the graph, origin 2 is "X"degrees from origin 1.

No I know you can take origin2 X and subtract it from origin1 X, and do the same for the Y's, but then you are always getting a -90 to 90 value,

what I am looking for is something that can say for example if you wanted 210deg it would give you 210 rather then 30deg.

Thanks,

Ilmaestro.


Hello, World!... LAME lol

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Maybe this example will help you...

;Coded by UEZ Build 2010-06-21
#include <GDIPlus.au3>
Opt("GUIOnEventMode", 1)
Opt("MouseCoordMode", 2)
$width = 600
$height = $width
$w05 = $width / 2
$h05 = $height / 2
$180_div_pi = 180 / ACos(-1)
Local $mx = $w05, $my = $h05
$r = 100
$r2 = $r / 2
$angle = 0
$hGUI = GUICreate("GDI+ Trigonometrie by UEZ 2010", $width, $height)
GUISetState()

_GDIPlus_Startup()
$hGraphics = _GDIPlus_GraphicsCreateFromHWND($hGUI)
$hBitmap = _GDIPlus_BitmapCreateFromGraphics($width, $height, $hGraphics)
$hBuffer = _GDIPlus_ImageGetGraphicsContext($hBitmap)
_GDIPlus_GraphicsSetSmoothingMode($hBuffer, 2)
_GDIPlus_GraphicsClear($hBuffer, 0xFFF0F0F0)
$hPen1 = _GDIPlus_PenCreate(0xFF0000A0, 2)
$hPen2 = _GDIPlus_PenCreate(0xA0000000, 1)
$hBrush1 = _GDIPlus_BrushCreateSolid(0x8000A000)
$hBrush2 = _GDIPlus_BrushCreateSolid(0x80A00000)

GUISetOnEvent(-3, "_Exit")

While Sleep(30)
    _GDIPlus_GraphicsClear($hBuffer, 0xA0F0F0F0)
    _GDIPlus_GraphicsDrawLine($hBuffer, 0, $h05, $width, $h05, $hPen2)
    _GDIPlus_GraphicsDrawLine($hBuffer, $w05, 0, $w05, $height, $hPen2)

    _GDIPlus_GraphicsDrawString($hBuffer, "X", $width - 15, $h05)
    _GDIPlus_GraphicsDrawString($hBuffer, "Y", $w05 - 15, 0)
    _GDIPlus_GraphicsDrawString($hBuffer, "-X", 2, $h05)
    _GDIPlus_GraphicsDrawString($hBuffer, "-Y", $w05 - 20, $height - 17)

    $mpos = MouseGetPos()
    $mwx = $mpos[0] - $w05
    $mwy = $h05 - $mpos[1]
    $pd = Pixel_Distance($w05, $h05, $mpos[0], $mpos[1])
    If $pd > 50 And $pd < $w05 - 10 Then
    $angle = -ATan($mwy / $mwx) * $180_div_pi
    If $mwx < 0 Then
    $angle = -180 + $angle
    ElseIf $mwx >= 0 And $mwy < 0 Then
    $angle = -360 + $angle
    EndIf
    _GDIPlus_GraphicsDrawString($hBuffer, StringFormat("%.2f", Abs($angle)) & "°", $mpos[0], $h05)
    _GDIPlus_GraphicsFillPie($hBuffer, $w05 - $r2, $h05 - $r2, $r, $r, 0, $angle, $hBrush1)
;~  _GDIPlus_GraphicsFillPie($hBuffer, $w05 - $r2, $h05 - $r2, $r, $r, -180, $angle, $hBrush2)
    _GDIPlus_GraphicsDrawLine($hBuffer, $width - $mpos[0], $height - $mpos[1], $mpos[0], $mpos[1], $hPen1)
    $mx = $mpos[0]
    $my = $mpos[1]
    Else
    _GDIPlus_GraphicsDrawString($hBuffer, StringFormat("%.2f", Abs($angle)) & "°", $mx, $h05)
    _GDIPlus_GraphicsFillPie($hBuffer, $w05 - $r2, $h05 - $r2, $r, $r, 0, $angle, $hBrush1)
;~  _GDIPlus_GraphicsFillPie($hBuffer, $w05 - $r2, $h05 - $r2, $r, $r, -180, $angle, $hBrush2)
    _GDIPlus_GraphicsDrawLine($hBuffer, $width - $mx, $height - $my, $mx, $my, $hPen1)
    EndIf
    _GDIPlus_GraphicsDrawImage($hGraphics, $hBitmap, 0, 0)
WEnd

Func Pixel_Distance($x1, $y1, $x2, $y2) ;Pythagoras theorem
    Local $a, $b, $c
    If $x2 = $x1 And $y2 = $y1 Then
    Return 0
    Else
    $a = $y2 - $y1
    $b = $x2 - $x1
    $c = Sqrt($a * $a + $b * $b)
    Return $c
    EndIf
EndFunc ;==>Pixel_Distance

Func _Exit()
    _GDIPlus_BrushDispose($hBrush1)
    _GDIPlus_BrushDispose($hBrush2)
    _GDIPlus_PenDispose($hPen1)
    _GDIPlus_PenDispose($hPen2)
    _GDIPlus_BitmapDispose($hBitmap)
    _GDIPlus_GraphicsDispose($hBuffer)
    _GDIPlus_Shutdown()
    GUIDelete($hGUI)
    Exit
EndFunc

Br,

UEZ

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Hey, that's a really cool user interface, but can you simplify it, taking out the section i would need, I don't need the GUI or anything just the math section of it and explain it a little better.

Thanks for the reply.

Edited by maestro

Hello, World!... LAME lol

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0