Community Tip - Did you know you can set a signature that will be added to all your posts? Set it here! X
Hi, I have a square versus triangle problem that I would appreciate help with. Please see attached.
Thanks for any help.
Jason
Solved! Go to Solution.
Jason Bryant wrote:
Hi Richard, the CC seems like a good method but Im guessing its quite involved. For the maximum seperation, I dont follow how this would tell you if its more squar elike or triangle like.
It may be that, for a simple approximation, you are actually looking for two (binary) measures, which you can then combine with an 'and' conjunction. The extended version of my original worksheet calculates the standard deviation of the angles of each corner (eliminates too shalllow an angle) and the stdev of the side lengths (to avoid too trapezoid a shape). Pick some threshold values to choose 'squareish'.
Stuart
There's probably some nice method out there just for this problem, but I'm too lazy to look.
So I'd be tempted to look at the differences between the angles between successive points. A more triangular pattern should have a pair of more open angles.
Stuart
Do you really need the "squareness"? If each of your points really represents cluster of points, and you need to be able to distinguish between them, all you would need is maximum separation.
If squareness is important, calculate the correlation coefficient for all possible combinations of three points. A high CC indicates the three points are close to a straight line, in which case your shape is close to a triangle.
Hi Richard, the CC seems like a good method but Im guessing its quite involved. For the maximum seperation, I dont follow how this would tell you if its more squar elike or triangle like.
Thanks
Jason
Hi Richard, the CC seems like a good method but Im guessing its quite involved.
Not really.
For the maximum seperation, I dont follow how this would tell you if its more squar elike or triangle like.
It wouldn't, but it's not clear to me why you need to determine that. If you are trying to distinguish the four fluorescent species then all you need is maximum separation between the points. Well, not quite, because each point is not really a point. If you were to measure multiple samples each point would actually be cluster of points, and what you need is to minimize the overlap between the clusters. If the clusters are small that just means getting the points far enough apart that there is effectively no overlap. If the clusters are large enough that complete separation is not possible then to get the best separation you would need to consider not only the distance between the clusters, but also the size of the clusters.
But maybe I misunderstand the nature of the problem (quite likely, given the brief description!)
Jason Bryant wrote:
Hi Richard, the CC seems like a good method but Im guessing its quite involved. For the maximum seperation, I dont follow how this would tell you if its more squar elike or triangle like.
It may be that, for a simple approximation, you are actually looking for two (binary) measures, which you can then combine with an 'and' conjunction. The extended version of my original worksheet calculates the standard deviation of the angles of each corner (eliminates too shalllow an angle) and the stdev of the side lengths (to avoid too trapezoid a shape). Pick some threshold values to choose 'squareish'.
Stuart
Hi Stuart. Could I ask for help regarding your standard deviation of angles method. Its great btw!
If now P1 & P2 are functions of a variable (v1), and P3 & P4 are functions of a second variable (v2), how would I incorporate this into the stdev calculation. My aim would be then to optimise the figure of merit (=stdev of angle) which is now a fucntion of v1 & v2 to deliver the minimum FOM.
Thanks
Jason
Do you mean something like the attached, Jason?
Stuart
Perfect!
Thanks Stuart
Jason
Theres one more thing I just cant work out. In your "Sides" function, you calculate the distance of each point from the adjacent point. I would like to create another function that has the input arguments P again but now calculates the minimum distance of any of the 3 other points. Then the net result being the actual minimum distance between any of the points. Im going to see how this optimises.
Thank
Jason
Jason Bryant wrote:
Theres one more thing I just cant work out. In your "Sides" function, you calculate the distance of each point from the adjacent point. I would like to create another function that has the input arguments P again but now calculates the minimum distance of any of the 3 other points. Then the net result being the actual minimum distance between any of the points. Im going to see how this optimises.
I've put a function that returns the distance between a point and its nearest neighbour, Jason. However, I suspect that you might be better off also trying to minimize the differences in distance ... have a look at how the function has minimized the distance in the last example.
Stuart
Thankyou again Stuart - thats great.
J
No worries, Jason.
Stuart
Is it not possible to have the Minimize function in a condition statement depending on what the user choices like the attached
I want to explore various ideas (1: sigma of angles, 2: sigma of sides or 3: just the minimum distance) and optimise depending on whats chosen. The problem is, that the last one of these requires a maximize rather than minimise so I can tus ea generic minimize function
BTW, the sheet wont work, but it shows the syntax.
Thanks
Jason
Unfortunately, Jason, I haven't had time (or access to M14 or M15) to look at your sheet, but in principle it should be possible to choose a function. My only concern would be static unit checking taking a dislike to something or other and preventing you using certain functions.
Stuart
I can't test it because most of your variables are not defined, but try defining three functions findMin1, findMin2, and findMin3. Then call one of those functions using the "if" block. That should work.
Hi, does the attached help. It seems I cant have the option to select whether to use Minimize or Maximise depending on the user input.
What you are doing should in fact work. You had two problems that stopped it from doing so. One is a syntax error: some extra brackets that shouldn't be there. The other is that when the worksheet is opened no button is selected, so F1 is zero. Your if statement does not take into account the case when F1=0 though, so it fails. I added some radio buttons that have a default selection when the worksheet is opened, which fixes that problem.
Hi Richard. Thanks for pointing out my errors. Im still not convinced its working. When the 3rd selection is chosen - so the FOM needs to be maximised, it still actually seems to be minimising. Its almost as if the FOM function logic is not working. If at the end you compare the default (FOM(P1)) to the optimised FOM(POpt) its actually smaller.
MMMM. I I think its still trying to Minimize when F3 is selected rather than maximize. Do you see this.
sorry If Im wasting your time.
Jason
It seems like its always doing the first line in the Optimise function i.e. the condition for F1=1 whatever the value of F1?
Yeah, what a pain. It's a quirk of maximize and minimize which do not always behave the same way other functions do (possibly because they are functionals). An extra level of indirection is required.
Great, thanks a lot.
Jason
AHHHHHH. Just when I though this was complete - I have stumbled across another anomaly with the mixed use of minimize and maximize.
If you put a condition in, when the Maximise function is called via Func 2 - it ignores the constraint:
I introduce the constraint using
Given
v1>1.5
It does work when the minimize function is called tho via Func1!
It appears that the Given followed by the condition only applies to the 1st of the functions Func1 in this case and not the Func2. If I swap these around then it does work with Func2 and not Func1. hmmmmmm?????
Jason
The keyword "Given" starts a solve block. The function definition for Func1 includes the Minimize function, and therefore terminates the solve block. If you want constraints to apply to the Func2 definition then you need to start another solve block (so add a Given and v1>1.5 immediately before the definition of Func2) .
Hi Richard, yes I had worked this out. My real worksheet has a set of complicate constraints and although it a pain to have to dublicate and not elegant, at least it works.
Thanks for all your input.
Jason
Hello Jason,
without providing some code I suggest that you check for parallelity within the shape. E.g. connect the two highest points by a straight line (the two lowest likewise) and check whether the angle between the two lines is less than a given threshold.
A triangle should have less parallels than a rectangle 😉
Raiko
Hi guys, thanks for your help, I like all 3 ideas provided
1: STANDARD DEVIATION OF THE ANGLES
2: CORRELATION COEFFICIENT FOR 3 POINTS
3: PARALLEL LINES
After a quick play, it seems the standard deviation is quite sensitive. So (sorry Richard and Raiko) - I will have to give the "correct answer" to Stuart. I will flag as helpful answers to you both, although all 3 of you have given me the correct answer. Thanks again - extremely useful
Jason
Better later than never?
Here are a few other intuitive (to me) measures that may also be helpful. The points in order RBGP (red, blue, green.purple) form a simple polygon (no crossed lines). Assuming this, or an appropriate reordering:
1. Area of the quadrilateral. There's a 2:1 difference between the trangle and the square.
2. Maximum size of the four interior angles; close to 90deg => square, close to 180deg => traingle.
3. Ratio of the lengths of the two diagonals ( I think not as robust as 1 and 2). Same ~2:1 for triangle and square, assuming range of possible positions limited to approx. variations is as shown.
Lou