Hawkysoft Posted December 14, 2013 Share Posted December 14, 2013 Anybody knows how to translate this to AutoIT? int x, y, l; int cx = width/2; int cy = height/2; float ang; for(int i = 0; i < pixels.length; i++){ y = i / width - cy; x = i % width - cx; l = dist(x, y, cx, cy); if(l < radius){ ang = degrees(atan2(y,x)); } if(ang >= 30 && ang <=90){ // inside slice } } I'm rlly stuck to be honest...;/ Link to comment Share on other sites More sharing options...
markyrocks Posted December 14, 2013 Share Posted December 14, 2013 I'm afraid to answer bc I'm sure someone will bash me if I'm wrong. Spoiler "I Believe array math to be potentially fatal, I may be dying from array math poisoning" Link to comment Share on other sites More sharing options...
Tekk Posted December 14, 2013 Share Posted December 14, 2013 (edited) for(int i = 0; i < pixels.length; i++){} Is a For Next loop. pixels.length is the same as AutoIts Ubound() function. The % operator is the same as AutoIts Mod() function. The && operator is the same as AutoIts And keyword. Distance can be found like this: Sqrt(($x - $cx) ^ 2 + ($y - $cy) ^ 2) #include <Math.au3> has definitions for _ATan2() and _Degree() Everything else is pretty much the same as if it were AutoIt. You can do this. It's the best way to learn. EDIT: Fixed the variable order in getting the distance. Edited December 14, 2013 by Tekk Hawkysoft 1 Link to comment Share on other sites More sharing options...
Developers Jos Posted December 14, 2013 Developers Share Posted December 14, 2013 (edited) I'm afraid to answer bc I'm sure someone will bash me if I'm wrong. Then don't, but refrain from useless post like this. s Anybody knows how to translate this to AutoIT? int x, y, l; int cx = width/2; int cy = height/2; float ang; for(int i = 0; i < pixels.length; i++){ y = i / width - cy; x = i % width - cx; l = dist(x, y, cx, cy); if(l < radius){ ang = degrees(atan2(y,x)); } if(ang >= 30 && ang <=90){ // inside slice } } I'm rlly stuck to be honest...;/ Show what you have that isn't working yet so people can help when they want. Jos Edited December 14, 2013 by Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
Hawkysoft Posted December 14, 2013 Author Share Posted December 14, 2013 (edited) So erhm basically it goes wrong bigtime.... not sure where though, just to be clear what I basically want is to get all the pixel coords from a circle givin from an exact point, and determ if a specific pixel is in what part of the circle... maybe there's an easier way to do this? #include <Math.au3> Global $x, $y, $l, $cx, $cy, $ang GetPicCircle(10,10,15) Func GetPicCircle($width,$height,$mRad) For $i = 0 To $mRad $cx = $width / 2 $cy = $height / 2 $y = $i / $width - $cy $x = Mod($i, $width - $cx) $l = Sqrt(($x - $cx) ^ 2 + ($y - $cy) ^ 2) If $l < $mRad Then FileWrite("testa.txt",$x & " - " & $y & @CRLF) $ang = _Degree(_ATan2($y,$x)) EndIf If $ang >= 30 AND $ang <= 90 Then FileWrite("test.txt",$x & " - " & $y & @CRLF) EndIf Next EndFunc this was the output I received in testa.txt 0 - -5 1 - -4.9 2 - -4.8 3 - -4.7 4 - -4.6 0 - -4.5 1 - -4.4 2 - -4.3 3 - -4.2 4 - -4.1 0 - -4 1 - -3.9 2 - -3.8 3 - -3.7 4 - -3.6 0 - -3.5 Edited December 14, 2013 by Hawkysoft Link to comment Share on other sites More sharing options...
markyrocks Posted December 15, 2013 Share Posted December 15, 2013 (edited) Is the point of origin in the circle or not and what is the point of this btw? Edited December 15, 2013 by markyrocks Spoiler "I Believe array math to be potentially fatal, I may be dying from array math poisoning" Link to comment Share on other sites More sharing options...
markyrocks Posted December 15, 2013 Share Posted December 15, 2013 (edited) ok i think i got it figured out Mod() equals out to the remainder of division between two numbers so in your script $x is always gona be 0-4 hence 0/5 no remainder to 5/5 see mod example this part is important "Local $x = Mod(4, 7) ;$x == 4 because the divisor > dividend" I guess this mod gives unexpected results with floating point numbers...... once i = 6 x = the remainder of 6/5 witch is 1 then 7/5 which is 2 and so on. also your if statements theres no difference between the results so the output is always gona be the same besides that the $l is always gona be < mrad due to the mod func poor results. besides that the initialization of the x and y variables there not modified in the script besides the i value changing. In the y value its always gona be some weird floating point the x value is always 0-4. what you can do to fix this is beyond me because I have no clue what the desired result is. another question I have is what does $mRad stand for? because if it stands for radius of a circle with a height of 10 and a width of 10 then the radius would be 5 not 15. height or width of a circle is the diameter the radius is half of that. I do have alot more to say about this thread but i'd like to let someone else jump in or hear from the Op before I say anything else. But i'd like to know where the original bit of code came from to be translated or w/e. Edited December 15, 2013 by markyrocks Spoiler "I Believe array math to be potentially fatal, I may be dying from array math poisoning" Link to comment Share on other sites More sharing options...
Solution Tekk Posted December 15, 2013 Solution Share Posted December 15, 2013 If you simply want to find out if a point lies within a circle you could measure the distance from the circle center to the point. If the distance to the point is less than the radius of the circle then the point is within the circle. Func GetDistance($fX1, $fY1, $fX2, $fY2) Return Sqrt(($fX1 - $fX2) ^ 2 + ($fY1 - $fY2) ^ 2) EndFunc If the point is within the circle you could then get the angle from the circle center to the point. Knowing the distance and the angle would tell you exactly which part of the circle the pixel is in. Func GetAngle($fX1, $fY1, $fX2, $fY2) Return ((($fY2 <= $fY1) * 180) - (ATan(($fX1 - $fX2) / ($fY1 - $fY2)) * 57.295779) + 90) EndFunc As far as getting all the pixel coordinates of a circle, I can’t think of an efficient way to do it. This would work but is very slow... Func GetCircleCoordinates($fCircCentX, $fCircCentY, $fCircRadius) Local $aCoordinates[Abs(($fCircRadius * 2) ^ 2) + 1][2] For $iY = Abs($fCircCentY - $fCircRadius) To Abs($fCircCentY + $fCircRadius) For $iX = Abs($fCircCentX - $fCircRadius) To Abs($fCircCentX + $fCircRadius) If (GetDistance($fCircCentX, $fCircCentY, $iX, $iY) < $fCircRadius) Then $aCoordinates[0][0] += 1 $aCoordinates[$aCoordinates[0][0]][0] = $iX $aCoordinates[$aCoordinates[0][0]][1] = $iY EndIf Next Next ReDim $aCoordinates[$aCoordinates[0][0] + 1][2] Return $aCoordinates EndFunc Hawkysoft 1 Link to comment Share on other sites More sharing options...
Hawkysoft Posted December 15, 2013 Author Share Posted December 15, 2013 (edited) @markyrocks thanks for your help so far mate. The point of origin is always 0,0 And I'm basically just learning autoit, so the hardest things there are around I try to accomplish, however got rlly stuck on this one... Also I do know that radius is half of the width... btw the code came from http://processing.org/discourse/beta/num_1276536212.html @Tekk Thanks allot mate, I can work further from this point, that it's slow at this point isn't really such a big of an deal since I could basically write all the positions to an array and determ when a location is mentioned to see if it's in this array or not However if someone finds a faster way to do it, I'm always pleased to hear Edited December 15, 2013 by Hawkysoft Link to comment Share on other sites More sharing options...
markyrocks Posted December 15, 2013 Share Posted December 15, 2013 (edited) Well in your script the point of origin is always radius, radius which if the diameter is 10 the point of origin is 5,5. Also in your script the x can never be negative to find an x, y of a circle the x and y axis need a range of -5,5 (for diameter of 10) Also the other problem that I have with this the x can only be a max of 4 which it needs to be able to be max of 5 same with the y can like 3.somthing. maybe I'm missing the point here idk. I just think there's an issue with the logic. Edited December 15, 2013 by markyrocks Spoiler "I Believe array math to be potentially fatal, I may be dying from array math poisoning" Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now