How to implement obstacle avoidance in Netlogo using the concept of two intersecting lines

34 views
Skip to first unread message

ioannis

unread,
Mar 12, 2020, 1:22:43 PM3/12/20
to netlogo-users
0

How can we convert the heading, of a Netlogo turtle, into a line equation (y = mx + c ) so that it can be compared to another line equation (eg that of patches representing a wall) ?  (turlte heading vs wall made of patches - both treated as lines that will intercept at one point)

I need to convert the heading of a turtle into a line equation. Then compare the heading line equation with the line equation of a wall (which will have either a fixed x or a fixed y – depending on whether the wall is vertical or horizontal) 

There is an interception of lines example code in the library (that I don’t understand that well) which is using moving segments. I think what I am after is a bit simpler. 

Perhaps a better starting point would be the code below that I found in one of the forums.

to-report calculate-line [ x y angle] let m tan angle let A m let B -1 let C ( - m * x + y ) report (list A B C) end

What must be done in order to 'read' the x and y values of the current turtle's heading and input those into the equations? Similarly, how can a set of patches that have been colored to represent a wall, can be converted into a line equation that will be used to check possible intersection (between the heading line equation and wall line equation)? 

For example, I have create a line/segment of grey patches using the below code to represent the wall and given it is straight, there must be a way to convert this into a line equation (which will have a fixed y value - so that I will only have to 'test' the x value against the line equation of the turtle's heading. (In the simulated environment there are 4 walls in total - 2 vertical and 2 horizontal)

ask patches with [abs pycor = 10] [set pcolor grey] ask patches with [abs pycor = 11] [set pcolor grey]

Many thanks in advance for any help/suggestions

Charles Staelin

unread,
Mar 12, 2020, 4:15:42 PM3/12/20
to netlogo-users

ioannis e papasliotis

unread,
Mar 12, 2020, 4:26:39 PM3/12/20
to Charles Staelin, netlogo-users
Much appreciated. Thank you

--
You received this message because you are subscribed to the Google Groups "netlogo-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to netlogo-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/netlogo-users/ae8482dc-9cc5-4d40-ba35-e9e471bd3808%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages