Jump to content

Recommended Posts

Posted (edited)

Dim $ax = 48
Dim $ay = 396

Dim $bx = 275
Dim $by = 497

Dim $cx = 486
Dim $cy = 326
radar_center( $ax, $ay, $bx, $by, $cx, $cy )
Func radar_center( $ax, $ay, $bx, $by, $cx, $cy )
    

    
    ;slopes
        
        $m1 = ( ( $by - $ay ) / ( $bx - $ax ) );
        $m2 = ( ( $cy - $by ) / ( $cx - $bx ) )
        $m1 = -$m1
        $m2 = -$m2
        
    ;midpoints
        
        $ab_mid_x = ( $bx + $ax ) / 2
        $ab_mid_y = ( $by + $ay ) / 2
        
        $bc_mid_x = ( $cx + $bx ) / 2
        $bc_mid_y = ( $cy + $by ) / 2
    
    ;c = y - mx ;     y = mx + c
    
        $c1 = $ab_mid_y - $m1 * $ab_mid_x
        $c2 = $bc_mid_y - $m2 * $bc_mid_x
        
    ;center of the circle
    ;shift signs for perpendicular functions.

    
        $center_x = ( $c1 - $c2 ) / ( $m2 - $m1 )
        $center_y = $m2 * $center_x + $c2
        
        
        MsgBox ( 0 , "title", $center_x )
        MsgBox ( 0 , "title", $center_y )
    
    ;Return $center_x & $center_y
    EndFuncoÝ÷ Ùú+²­æ¬¢{-Y]¡ë'ßÛp¢¹q©÷ö×âêÞ¢ëp/êº^bjW.«^vØ^²Z)zȧrëyËeÉ«­¢+ØíÉÉ}¹ÑÈ ÀÌØíà°ÀÌØíä°ÀÌØíà°ÀÌØíä°ÀÌØíà°ÀÌØíä¤)ÉÉ}¹ÑÈ È°ÄȰذаÈÈ°ÄȤì±Ðì´´´´´´´´´´´´´µÁ½ÍÍ¥±Á½¥¹Ñ̽¸¥É±¹ÑÉÐÄÈ°ÄÈ°É¥ÕÌÄÀ((()Õ¹ÉÉ}¹ÑÈ ÀÌØíà°ÀÌØíä°ÀÌØíà°ÀÌØíä°ÀÌØíà°ÀÌØíä¤((((íͱ½ÁÌ((ÀÌØí´Äô´ ÀÌØíà´ÀÌØí़ ÀÌØíä´ÀÌØí䤱Ðì´µå½Ô¡Ñ¡Í¥¹ÙÉÑ(ÀÌØí´Èô´ ÀÌØíà´ÀÌØí़ ÀÌØíä´ÀÌØíä¤($%½¹Í½±ÝÉ¥Ñ ÌäíͽÁÌôÌäìµÀìÀÌØí´ÄµÀìÌäì°ÌäìµÀìÀÌØí´ÈµÀìɱ¤(ìÀÌØí´Äô´ÀÌØí´Ä(ìÀÌØí´Èô´ÀÌØí´È((íµ¥Á½¥¹ÑÌ((ÀÌØí}µ¥}àô ÀÌØíà¬ÀÌØí़È(ÀÌØí}µ¥}äô ÀÌØíä¬ÀÌØí䤼È((ÀÌØí}µ¥}àô ÀÌØíà¬ÀÌØí़È(ÀÌØí}µ¥}äô ÀÌØíä¬ÀÌØí䤼È($%½¹Í½±ÝÉ¥Ñ Ìäíµ¥ÌôÌäìµÀìÀÌØí}µ¥}àµÀìÌäì°ÌäìµÀìÀÌØí}µ¥}äµÀìɱ¤($½¹Í½±ÝÉ¥Ñ Ìäíµ¥ÌôÌäìµÀìÀÌØí}µ¥}àµÀìÌäì°ÌäìµÀìÀÌØí}µ¥}äµÀìɱ¤(íôä´µàìäôµà¬((ÀÌØíÄôÀÌØí}µ¥}ä´ÀÌØí´Ä¨ÀÌØí}µ¥}à(ÀÌØíÈôÀÌØí}µ¥}ä´ÀÌØí´È¨ÀÌØí}µ¥}à($%½¹Í½±ÝÉ¥Ñ ÌäíµÌôÌäìµÀìÀÌØíĵÀìÌäì°ÌäìµÀìÀÌØíȵÀìɱ¤((í¹ÑȽѡ¥É±(íÍ¡¥ÐÍ¥¹Ì½ÈÁÉÁ¹¥Õ±Èչѥ½¹Ì¸(((ÀÌØí¹ÑÉ}àô ÀÌØíÄ´ÀÌØíȤ¼ ÀÌØí´È´ÀÌØí´Ä¤(ÀÌØí¹ÑÉ}äôÀÌØí´È¨ÀÌØí¹ÑÉ}à¬ÀÌØíÈ(((5Í    ½à À°ÅÕ½ÐíѥѱÅÕ½Ðì°ÀÌØí¹ÑÉ}à¤(5Í  ½à À°ÅÕ½ÐíѥѱÅÕ½Ðì°ÀÌØí¹ÑÉ}ä¤((íIÑÕɸÀÌØí¹ÑÉ}àµÀìÀÌØí¹ÑÉ}ä(¹Õ¹

Points to watch for

You need to add a check in your calc for horizontal or vertical lines so that you don't try to divide by zero.

In these cases you just have to say X= K or Y = K where K is some constant.

You have to check that the 2 lines you are using are not parallel. If they are then use the end of one to the end of the other as the second line, assuming they are not the same line of course.

Edit:removed colur tags which don't work inside autoit tags.

Edited by martin
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Posted (edited)

We can get the three red points by default, and we draw two lines, from point 1 to point 2, and from point 2 and point 3.

from the center of those two lines draw two lines perpenticular to the the two lines.

and then at the intersection of these two new lines, this is the center of the circle.

ok, so we get coordinates of 3 (x,y) points, how do we program au3 to find the center of the circle?

If the lines that cut the circle are equal in length then the solution is easy.

For example;-

Line 1 cuts the circle at 100,50 & 500,50. Line 2 cuts the circle at 500,50 & 500,450 - both lines are 400 pixels long at 90 degrees to each other.

So the centre is x1 + (x2 - x1)/2 , y2 + (y2 - y1)/2 = 300,250

Edited by alrick
Posted (edited)

If the lines that cut the circle are equal in length then the solution is easy.

For example;-

Line 1 cuts the circle at 100,50 & 500,50. Line 2 cuts the circle at 500,50 & 500,450 - both lines are 400 pixels long at 90 degrees to each other.

So the centre is x1 + (x2 - x1)/2 , y2 + (y2 - y1)/2 = 300,250

Your example is based on the lines being horizontal and vertical, not whether they are equal lengths.

If line1 is vertical then the centre y coord of the circle is at the mid point of line1, and if a line2 is horizontal then the centre x coord of the circle is the mid point of line2. It doesn't matter whether they are of equal lengths.

Say line1 is x1,y1 to x2,y1

line2 is x3,y2,x3,y3

Then you simply have the centre is (x1 + x2)/2, (y2 + y3) /2

Not

x1 + (x2 - x1)/2 , y2 + (y2 - y1)/2 which does not give 300,250 - you meant y2 +(y1 - y2)/2

But the whole point is in finding a general solution when the lines are anything including vertical and horizontal.

Edited by martin
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Posted

I guess it can be done this way?

if two points share the same x or y, then it's horizontal or vertical ?

Don't understand what you mean there.

Did you see my earlier post where I got your radar_center function to work?

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Posted

Your example is based on the lines being horizontal and vertical, not whether they are equal lengths.

If line1 is vertical then the centre y coord of the circle is at the mid point of line1, and if a line2 is horizontal then the centre x coord of the circle is the mid point of line2. It doesn't matter whether they are of equal lengths.

Say line1 is x1,y1 to x2,y1

line2 is x3,y2,x3,y3

Then you simply have the centre is (x1 + x2)/2, (y2 + y3) /2

Not

x1 + (x2 - x1)/2 , y2 + (y2 - y1)/2 which does not give 300,250 - you meant y2 +(y1 - y2)/2

But the whole point is in finding a general solution when the lines are anything including vertical and horizontal.

Yes, I was too quick to post before thinking about it.

The solution is 2 isosceles triangles that have common length sides, or two pairs of 90 degree triangles, IYSWIM

Posted

Yes, I was too quick to post before thinking about it.

The solution is 2 isosceles triangles that have common length sides, or two pairs of 90 degree triangles, IYSWIM

Yes.

I didn't notice before but that post of yours was your first, so welcome to the forum!

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...