Line smoothing - minimum angle
Do you have questions or comments about this model? Ask them here! (You'll first need to log in.)
WHAT IS IT?
(a general understanding of what the model is trying to show or explain)
HOW IT WORKS
(what rules the agents use to create the overall behavior of the model)
HOW TO USE IT
(how to use the model, including a description of each of the items in the Interface tab)
THINGS TO NOTICE
(suggested things for the user to notice while running the model)
THINGS TO TRY
(suggested things for the user to try to do (move sliders, switches, etc.) with the model)
EXTENDING THE MODEL
(suggested things to add or change in the Code tab to make the model more complicated, detailed, accurate, etc.)
NETLOGO FEATURES
(interesting or unusual features of NetLogo that the model uses, particularly in the Code tab; or where workarounds were needed for missing features)
RELATED MODELS
(models in the NetLogo Models Library and elsewhere which are of related interest)
CREDITS AND REFERENCES
(a reference to the model's URL on the web if it has one, as well as any other necessary credits, citations, and links)
Comments and Questions
globals [Bm Bb Am Ab ang ang1 ang2 p-1_p1_hyp p_p1_hyp p-1_p_hyp A1x A1y A2x A2y B1x B1y B2x B2y Ix Iy thisdist pntlist deg r deglist rlist pos wholist p-1x p-1y px py p1x p1y two_who_list x1 y1 x2 y2 hyp] turtles-own [jag medianx mediany] to setup ca set deglist [] set rlist [] repeat Point_count [ set deg random 360 set r (max-pxcor * (inner / 100)) + random (max-pxcor * (outer / 100) - max-pxcor * (inner / 100)) set deglist lput deg deglist set rlist lput r rlist ] set deglist sort deglist set pos -1 repeat Point_count [ set pos pos + 1 crt 1 [set label jag set size 3 set shape "dot" set heading item pos deglist jump item pos rlist] ] calcjag drawlinks end to plot_angles set-current-plot "Angles" histogram [jag] of turtles set-current-plot "Radius" histogram [distance patch 0 0] of turtles end to noise ask turtles [set heading random 360 jump random noise_distance] calcjag drawlinks plot_angles end to dropjag ask turtles with [jag < angle_threshold] [die] calcjag drawlinks plot_angles end to gomedian ask turtles with [jag < angle_threshold] [carefully [set xcor medianx set ycor mediany][]] calcjag drawlinks plot_angles end to drawlinks set wholist [] ask turtles[set wholist lput who wholist] set wholist sort wholist set pos 0 repeat (length wholist - 1) [ set pos pos + 1 ask turtle (item pos wholist) [create-link-with turtle (item (pos - 1) wholist)]] ask turtle (last wholist) [create-link-with turtle (first wholist)] end to calcjag set wholist [] ask turtles[set wholist lput who wholist] set wholist sort wholist set wholist lput first wholist wholist set wholist lput item 1 wholist wholist set pos 0 repeat (length wholist - 2) [ set pos pos + 1 set p-1x [xcor] of turtle (item (pos - 1) wholist) set p-1y [ycor] of turtle (item (pos - 1) wholist) set px [xcor] of turtle (item pos wholist) set py [ycor] of turtle (item pos wholist) set p1x [xcor] of turtle (item (pos + 1) wholist) set p1y [ycor] of turtle (item (pos + 1) wholist) set p-1_p_hyp hypot p-1x p-1y px py set p_p1_hyp hypot px py p1x p1y set p-1_p1_hyp hypot p1x p1y p-1x p-1y ifelse ((p-1_p_hyp < p_p1_hyp) and (p-1_p1_hyp < p_p1_hyp)) [ ; p_p1_hyp is the longest side of the triangle carefully [set ang (asin ((p2l_dist px py p1x p1y p-1x p-1y) / p-1_p_hyp))][set ang 0] ] [ifelse (p-1_p1_hyp < p-1_p_hyp) and (p_p1_hyp < p-1_p_hyp)[ ; AB is the longest side of the triangle carefully [set ang (asin ((p2l_dist p-1x p-1y px py p1x p1y) / p_p1_hyp))][set ang 0] ] [; AC is the longest side of the triangle carefully [set ang1 (asin ((p2l_dist p1x p1y p-1x p-1y px py) / p_p1_hyp))][set ang1 0] carefully [set ang2 (asin ((p2l_dist p1x p1y p-1x p-1y px py) / p-1_p_hyp))][set ang1 0] set ang 180 - (ang1 + ang2) ] ] ask turtle item pos wholist [set jag int ang set label jag set medianx (first calcmedian p-1x p-1y px py p1x p1y) set mediany (last calcmedian p-1x p-1y px py p1x p1y)] plot_angles ] set wholist but-last but-last wholist end to-report hypot [a b c d] report (((a - c) ^ 2) + ((b - d) ^ 2)) ^ 0.5 end to-report p2l_dist [a b c d f g] set A1x a set A1y b set A2x c set A2y d set B1x f set B1y g set Am (A1y - A2y) / (A1x - A2x) set Ab A1y - (Am * A1x) set Bm -1 / Am set Bb B1y - (Bm * B1x) ;get the y intercept ;solve for point intersection at right angle set Ix ((Bb - Ab) / (Bm - Am)) * -1 set Iy Bm * Ix + Bb report hypot B1x B1y Ix Iy end to-report calcmedian [ax ay bx by cx cy] ;show (se ax ay bx by cx cy) ;line A carefully [ ;if there's an error (division by 0) then set the median to the current turtle coordinates set A1x (ax + cx) / 2 set A1y (ay + cy) / 2 set Am (A1y - by) / (A1x - bx) set Ab A1y - (Am * A1x) ;show (se A1x A1y Am Ab) ;line B set B1x (ax + bx) / 2 set B1y (ay + by) / 2 set Bm (B1y - cy) / (B1x - cx) set Bb B1y - (Bm * B1x) ;show (se B1x B1y Bm Bb) ;lines A and B intersect set Ix ((Bb - Ab) / (Bm - Am)) * -1 set Iy (Bm * Ix) + Bb ] [set Ix bx set Iy by] report (list Ix Iy) end
There is only one version of this model, created almost 9 years ago by Eugene Martin.
Attached files
File | Type | Description | Last updated | |
---|---|---|---|---|
Line smoothing - minimum angle.png | preview | Preview for 'Line smoothing - minimum angle' | almost 9 years ago, by Eugene Martin | Download |
This model does not have any ancestors.
This model does not have any descendants.