Is there a simple equation for this?

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

ajperks
Posts: 103
Joined: Sat Sep 06, 2014 3:38 pm

Is there a simple equation for this?

Post by ajperks » Fri Sep 09, 2022 5:45 pm

I am attempting to mimic the movement of a cell in a Pietri dish.
At this stage, the cell is attracted to a target and moves slowly, an increment at a time, towards it.
Cells diagram.jpg
I have the coordinates of the target (shall we say 144,62)
I have the coordinates of the cell (shall we say 320,104)
The movement increments will be the ABS and also the INT (of the differences). The INT is because the smaller value of the difference will always be a fraction of (smaller value divided by larger value).
As I see it, I have to test to see if I add or subtract to each of the 2 cell values. They could be both + or - or one of each, depending if the cell is closer to 0,0 or 400,400 in relation to teh target, in this 400x400 dish area. Yes, I know Pietri dishes are circular, but at this point I am not concerned with that.

The question is, is there a simple mathematical way of avoiding the pluses and minuses, tests etc to simulate the cell movement to target?

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9670
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Is there a simple equation for this?

Post by dunbarx » Fri Sep 09, 2022 6:19 pm

Hi.

I have made a number of "random walk" gadgets in my life. Here is one I just made that might be useful to you. The field in the upper left contains a small integer. This determines the rate of movement.

A single handler in the "Start" button...
Random Walk 2livecode.zip
(1.14 KiB) Downloaded 64 times
Craig

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9670
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Is there a simple equation for this?

Post by dunbarx » Fri Sep 09, 2022 6:24 pm

Let me know if it was of use.

This has to be embellished if the location of the" target" changes (or itself moves?). Right now it is simple because that target lies still, roughly at a 45° angle to the origin.

Craig

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9670
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Is there a simple equation for this?

Post by dunbarx » Fri Sep 09, 2022 6:30 pm

Hi again.

Your post, which I just reread, implies that the target moves. Please confirm before I make the changes needed for the cell to track down that moving target,.

Your post implied you have a sense of what is needed. Isn't it then just a matter of changing the contents of the two item lists to optimize the next cell movement? Those lists would indeed, at each iteration, look at the current locations of the two objects, and concoct a short string of values that "point" the cell in the direction of the target.

Craig

ajperks
Posts: 103
Joined: Sat Sep 06, 2014 3:38 pm

Re: Is there a simple equation for this?

Post by ajperks » Fri Sep 09, 2022 6:56 pm

Hi Craig, ultimately the target may move.
I will look at the download after my evening meal.

FYI, this project is a brain stretcher for me. I haven't used Livecode for a while and building this simulation should get the grey cell working and bring me back up to speed with LC.

My main interest is robotics. To some extent, this might provide a better insight into developing algorithms. We shall see.
Thanks for your interest and help.

ajperks
Posts: 103
Joined: Sat Sep 06, 2014 3:38 pm

Re: Is there a simple equation for this?

Post by ajperks » Fri Sep 09, 2022 7:06 pm

I have already started the long winded approach of testing etc. I know it will work that way, but i had hoped there was a simple routine that avoids testing the + or - of the values.
I note the slick code you suggest that moves in one direction. It will take me a while to understand it. I tend to write obvious code and then refine it later. I know you have been coding for ages, because you have helped me before. Always appreciated.
Thanks.

stam
Posts: 2686
Joined: Sun Jun 04, 2006 9:39 pm
Location: London, UK

Re: Is there a simple equation for this?

Post by stam » Fri Sep 09, 2022 8:22 pm


dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9670
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Is there a simple equation for this?

Post by dunbarx » Fri Sep 09, 2022 8:36 pm

Let me know how it goes.

I had originally thought this was some form of random walk, but with a favored direction.

Getting the X and Y differences of the current locs of each object will tell us which direction to move the cell. Over-simply, we can then simply choose one of four sets of items, one for movement along the diagonal in each of the four quadrants. This can then be refined to move more efficiently within a particular quadrant, so that the cell can move not on the quadrant diagonal, but rather on the line connecting it to that target.

And since the target moves as well, we need to make sure that the "cell" moves faster if it is chasing behind it, or efficiently if only heading it off.

Such fun...

Craig

ajperks
Posts: 103
Joined: Sat Sep 06, 2014 3:38 pm

Re: Is there a simple equation for this?

Post by ajperks » Sat Sep 10, 2022 9:16 am

Based on my research, it appears the current public opinion of how basic life forms function and perform has the underlying notion that there is intelligencee at the heart of it. I don't believe this is correct. Remarkable things happen that appear intelligence driven but are simply the result of chemistry and physics. To an isolated tribe of natives, the attraction of a magnet to some materials might suggest to them the magnet is intelligent enough to know the difference between iron and wood. We know different.
My project programming must try and avoid A.I and pre-programmed solutions like those of a robot vacuum cleaner finding its way around.
As each function or ability is refined and completed, I hope to add the next step in the creatures limited repertoire. Having sensed, by chemical attraction the direction to move in search of nutrient, what are the outcomes of energy consumption, cell division and so on.
Hopefully the thing will appear intelligent and interesting to watch as it becomes more complex.
I am exploring the links provided to other similar programmes, so thanks for those.

stam
Posts: 2686
Joined: Sun Jun 04, 2006 9:39 pm
Location: London, UK

Re: Is there a simple equation for this?

Post by stam » Sat Sep 10, 2022 11:24 am

You’re not wrong. It’s actually an old observation.

You should probably look at Conway’s game of life: in a simulation of a 2D universe divided into a grid of squares each square follows 4 simple rules. This creates absolutely epic constructions, movement and “battles”. But no intelligence….

https://en.m.wikipedia.org/wiki/Conway's_Game_of_Life

https://youtu.be/C2vgICfQawE

ajperks
Posts: 103
Joined: Sat Sep 06, 2014 3:38 pm

Re: Is there a simple equation for this?

Post by ajperks » Sat Sep 10, 2022 1:40 pm

Hi Stam,
I did find the simulation interesting. I was aware lots of people had created computer programs to do similar simulations and I have tried to avoid watching them, or at least being influenced by their techniques. I was keen to avoid being influenced by their thought processes. If I stand on the shoulders of clever people, I will end up with nothing more than they have achieved and no feeling of accomplishment at the end of it, if indeed I actually accomplish anything at all. I have low expectations.
Thanks for the link to the interesting video and Wiki.

ajperks
Posts: 103
Joined: Sat Sep 06, 2014 3:38 pm

Re: Is there a simple equation for this?

Post by ajperks » Sat Sep 10, 2022 2:11 pm

Hi Craig,
You asked to let you know how I am progressing.
Having thought about the problem, I have decided on a substantially non-mathematical approach.
My reasoning is this.
The cell only knows the rough direction of the target/nutrient because the chemicals detected are strongest on the nearest side.
The cell has no math ability, so calculation is not something I should employ to track the target.
The target will move at its own pace and direction and is not related to the cell at all. At a later stage of development the target might be programmed to detect if it is being hunted and will head away from danger.
The cell can only move at one speed, as fast as it can towards the nutrient, so catching or intercepting the target/nutrient is in the lap of the gods.
In conclusion, all I should do is loop through each movement increment to ascertain the new direction of travel. At some point the cell will either lose the scent, catch the target, or die because it runs out of energy. Cell division is unlikely during the journey unless it has ample energy reserves after sufficient cell division time has passed.
If nothing else, it has helped me a lot to discuss the problem.

stam
Posts: 2686
Joined: Sun Jun 04, 2006 9:39 pm
Location: London, UK

Re: Is there a simple equation for this?

Post by stam » Sat Sep 10, 2022 4:36 pm

It would be very interesting to see what you come up with in the end! Do keep us updated…

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9670
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Is there a simple equation for this?

Post by dunbarx » Sat Sep 10, 2022 6:09 pm

The cell has to do some "math" or it won't know which way to go. Since the detection of chemical markers indicates the direction of travel, the "math" it does derives from that knowledge. We must simulate that by determining the loc of each object and creating a pathway.

Isn't that correct? There is nothing we are doing that the cell is not. We are each just using different tools.I see no cheating here, or going behind the cell's back.

So can you find the straight line from one control to another? And then set up a small group of items from which to choose the next movement of the cell? That is the way I did it, but you do not have to.

Craig

RogGuay
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 114
Joined: Fri Apr 28, 2006 12:10 am
Location: Seattle

Re: Is there a simple equation for this?

Post by RogGuay » Sat Sep 10, 2022 6:10 pm

This is a very interesting thread for me as I tend to agree that what appears as intelligent and complex behavior sometimes, at least, can be due to simple rules. This is what Boids is all about.

Thanks to the kind recommendation from Stan, I uploaded a cleaned up version of FlockOBoids.2022. I was inspired by Bernd's version in which many "cells" or Boids are represented by the marker points of a single polygon. This greatly increases the speed and therefore allows for a greater number of Boids. FlockOBoids.2022 does not employ this method for a variety of reasons but is cleaned up a bit.

I echo Stam . . . Please do keep us updated.

Cheers,
Roger

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”