Sure, I am interested.I don't have any code, but I do have an idea on how I'd try to solve it. Let me know if you want me to describe it, no meaning if you're not interested.
I am interested in your code.Hello! I have already created a 1-bit (two-color) bitmap with different shapes scattered around. And the program looked for them all, went around them, and wrote out the x, y circle travel positions. If we start from this, we may need to draw the shape on a bitmap with a higher resolution and move it around.
ok share the position of the points and I will try to find a solution for you to get the position of the district points!I am interested in your code.
Note I am passing a list of lat/lng types (points on the map) and need in return another list of lat/lng types describing a polygon tightly surrounding those map points.
RBS
It is just a list of lat/lngs (as a type). You can just take any sample you want.ok share the position of the points and I will try to find a solution for you to get the position of the district points!
Sure, I am interested.
Thanks, that sounds like a simple approach and it will be an interesting exercise to code that.Ok, so this would be the principle:
Start with a polygon with four points that match the corners of the image. All four points are considered movable.
Then it's just a case of running this small loop:
For each movable point in our polygon:
- Move it 1 unit toward polygon center.
- If the changed line intersects a latlong point:
- Add another point to our polygon at intersecting location and mark it as unmovable.
- Add two new movable points as neighbours to the newly added unmovable points, at center of segment.
- If the changed line intersects a previous line in the polygon, move the polygon point back to previous position and mark it as unmovable. (So we don't "tie off" sections and make islands.)
Example conditions for when to stop the loop:
- Number of polygon segments are high enough.
- Enough time has passed.
- Median segment length is below a certain value.
...or whatever makes sense in your case.
And to illustrate, this is sort of what it would look like with the image @MasterGy posted:
(rotated and cropped to not eat too much space here)
red dots = movable points
purple dots = red dots, but shows that they were added as effect of added green dot (I chose this color poorly, check the images manually if you really want to see where the purple dots are)
green dots = unmovable points
Start at the corners:
View attachment 158504
Narrowing in, nothing happening yet:
View attachment 158505
First unmovable points added, and purple dots inbetween:
View attachment 158506
More unmovable points added, more purple dots added:
View attachment 158507
More unmovable points added, more purple dots added:
View attachment 158508
More unmovable points added, more purple dots added:
View attachment 158509
At this point I started losing my sanity trying to do this by hand. I hope it illustrates the concept well enough. (And I'm certain I've made multiple mistakes when I drew dots, but it should be correct enough to show how it would work.)
> I'd love to see the results if you actually do code this.Sorry, I have no idea. I don't really know Java so I can't help you out there.
One more thing I thought of, I'm being very hand-wavy with the concept of "center of polygon", so that's an exercise for you to figure out what that is. (There are several different answers to it, depending on your needs.)
What I wanted to leave you with is that it might make sense to add nervousness to the center so it's not static at the exact same position all the time. That would probably make the shrinkwrap go further into some narrow areas, is my gut feeling.
I'd love to see the results if you actually do code this. And please consider adding a little bit of code to make a snapshot every time you move a point so you can assemble the images to an animated gif later. Both for your understanding of how well the algorithm works, but also for our entertainment - I imagine it will look cool.
Private Sub shrinkwrap(pts As List) As List
Dim ps As List
ps.initialize
bc.CopyPixelsFromBitmap(cv.CreateBitmap)
Dim argb As ARGBColor
'sweep at delta degree angles (0 to 359) find point at furthest distance from center - limit the radius to surrounding rectangle
Dim minLeftTop As point = Createpoint(Root.Width, Root.Height)
Dim maxRightBottom As point = Createpoint(0, 0)
For Each pt As point In pts
If pt.x < minLeftTop.x Then minLeftTop.x = pt.x
If pt.y < minLeftTop.y Then minLeftTop.y = pt.y
If pt.x > maxRightBottom.x Then maxRightBottom.x = pt.x
If pt.y > maxRightBottom.y Then maxRightBottom.y = pt.y
Next
Dim r As B4XRect
r.Initialize(minLeftTop.x, minLeftTop.y, maxRightBottom.x, maxRightBottom.y)
Dim center As point = Createpoint(.5 * (minLeftTop.x + maxRightBottom.x), .5 * (minLeftTop.y + maxRightBottom.y))
Dim maxRadius As Float = distance(center, minLeftTop)
For angle = 0 To 359 Step 1
Dim savePt As point = Createpoint(0, 0)
For radius = 5 To maxRadius Step 5
Dim x As Float = center.x + radius * CosD(angle)
Dim y As Float = center.y + radius * SinD(angle)
bc.GetARGB(x, y, argb)
If argb.r < 50 And argb.g < 50 And argb.b < 50 Then savePt = Createpoint(x, y)
Next
If savePt.x > 0 Or savePt.y > 0 Then ps.Add(savePt)
Next
Return ps
End Sub
Thanks, that's kind of you.I had the same thought as @Sandman - using the shrinkwrap principle. I used it in the past for turning arbitrary shapes into clickable buttons.
https://www.b4x.com/android/forum/t...scellaneous-image-shapes-into-buttons.140309/
He describes it very well.
I see you specify the center in your code. Did you consider adding nervousness to the center, and re-calculating it every iteration? Then again, perhaps it's not really applicable to your principle, as you don't do iterations the same way as my proposal. Perhaps it wouldn't change much?it is sensitive to the choice of center
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?