Netlogo: How do you find the distance in a straight line? [closed] - distance

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
I know that distance measures the distance in a radius, but how can you find the distance between a turtle and a patch that is directly in front of them (the patch can change depending on which patch you are looking at)
Thanks

Can you explain a little more what you mean? Does the distance primitive not get what you're after? For example:
to setup
ca
crt 1
reset-ticks
end
to go
ask turtles [
rt random 60 - 30
fd 1
; Show the distance to the center of
; the patch that is 3 patches away
print distance patch-ahead 3
]
end

Related

From XY all coordinates find angle [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
I am new to MATLAB, my problem is I created a triangle, now requirement is to gather all the x,y coordinates on three sides of triangle in order to find the angles to the starting point (0,0).
My approach is
side_1=[linspace(0,2,100),linspace(1,1,100)]
side_2=[linspace(2,0,100),linspace(1,5,100)]
side_3=[linspace(0,0,100),linspace(5,1,100)]
all_coordinates=(side_1, side_2, side_3)
The 4th line of the above code failed, I need make a matrix that contains all x,y coordinates in order to calculate angles that every points face to (0,0) by atan function. Looking for advice.
The first three lines of you code created three 1x200 row vectors. I presume you are trying to combine them into a single matrix with dimensions 3x200. In that case use:
all_coordiantes=[side_1; side_2; side_3]

Turtles has to die after few ticks after collision [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 years ago.
Improve this question
Turtles has to die after few ticks after collision?
problem in TICK position and some issue with Turtles-own and its implementation?
Turtles has to die after few ticks after collision
turtles-own [ functioning ]
globals [ non-functioning-ticks ]
to setup
clear-all
;ask turtles [set functioning True]
create-bikes 1 [
set functioning true
]]
create-cycles 1 [set functioning true]
end
to go
ifelse functioning = true
[ show functioning
ask turtles [ move ]]
[ show functioning
ask turtles [after-collision]
[
if not any? turtles [ stop ]
tick
end
to move
ask bikes [set color blue
fd 1 ]
ask cycles [set color blue
fd 1]
ask turtles with radius 1
set functioning False
set color red ]]]
end
to after-collision
ifelse non-functioning-ticks >= 3
[ die ]
[ set non-functioning-ticks non-functioning-ticks + 1 ]
end
Your problem is that you have non-functioning-ticks as a global variable. If you think about it, each turtle needs its own copy as some will be alive and some will collide. This is a problem throughout your code. Anything that is potentially different for some turtles must be defined by a turtles-own statement instead of a globals statement. You then need to change the value of that variable with a set (as for globals) but you have to tell NetLogo which turtles to change the value for. So you will have something like:
ask turtles with [<some condition>]
[ set <variable> <value>
]
You need a new state (perhaps called collided or collision-time) that can be referenced in after-collision that's where you're going to increase the ticks, when they're >= 3 then you kill it.

how to reduce the number of regions based on colors in this image? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I need to show this image in 3 colors , by giving each similar color region one color. The result should be in 3 colors without escape for any region in the image.
how i can combine the small regions with same color in one region as possible limits
i need to reduce the number of regions.
thanks
I hope you already have the regions yourself, else you'd be asking a too broad question, as those super-pixels are hard to get.
While I wont write thw code for you, ill give you the steps needed.
Find the average color of each region. Remember to work in HSV, and not RGB. Also, remember that H is circular. [1 0 0] and [0 0 0] are the same color in HSV.
Perform a classification of those colors, by, for example, KNN. Create 3 clusters, and compute the centroids of those clusters. Those will be your 3 colors
Convert the 3 centroids and the mean color of each superpixel to L*a*b* color space. This space is defined as "closest color is most similar color". Basically, compute the euclidean distance of each of the mean values of the superpixels to the 3 "class colors". The minimum distance class will be the one corresponding to that superpixel.
You can find help on each of these steps easily if you Google/search Stackverflow.
The nice thing of coding it properly is that you can try more colors, say 5 or 6, to see if the image/classification is better. 3 seem like to few colors.

Create 2D grid in matlab [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I want to create a grid in Matlab, I want mark some cell as free , some(blacks) as obstacle, and mark one cell as start and another cell as end point and some as path, like below image,how can I achieve this in Matlab?
To get you started, here's how to create something that looks like the image you included using pcolor.
A = ones(11,11)
A(5,1:3) = 0;
A(8:10,2:3) = 0;
A(5:7,6:7) = 0;
A(1:3,8:10) = 0;
pcolor(A)
colormap(gray(2))
% To flip the vertical axes, uncomment next line
%axis ij
For start and goal
patch([1,2,2,1],[2,2,3,3],[0.5 0.5 1]) % [r g b] values
text(1.25,2.5,'Start')
patch([10,11,11,10],[10,10,11,11],'g')
text(10.25,10.5,'Goal')

Matlab: How to count? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I have above image with white background. I need to count the circles and get diameter of each circle using morphological, logical and set operations of matlab. Any ideas how to do it?
Use regionprops:
img = imread('http://i.stack.imgur.com/OJidJ.png');
bw = img(:,:,1) < 128; %// convert to logical mask
d = regionprops( bw, 'EquivDiameter' );
d = [d.EquivDiameter]; %// array with diameter of each coin.