Android Question Get list of B4XPath points?

Jeffrey Cameron

Well-Known Member
Licensed User
Longtime User

DonManfred

Expert
Licensed User
Longtime User
As B4XPath is a wrap around android.graphics.Path: I don´t see any Methods to get the Points in a Path.
 
Upvote 0

emexes

Expert
Licensed User
As B4XPath is a wrap around android.graphics.Path: I don´t see any Methods to get the Points in a Path.

not the precise points, agreed, but how about:

approximate
added in API level 26

public float[] approximate (float acceptableError)

Approximate the Path with a series of line segments. This returns float[] with the array containing point components. There are three components for each point, in order:
  • Fraction along the length of the path that the point resides
  • The x coordinate of the point
  • The y coordinate of the point
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
not the precise points, agreed, but how about:

approximate
added in API level 26
This method is only available in Android 8+. It is not available in Android 7-, B4J implementation or B4i implementation. XUI methods must be cross platform.

Instead of adding the points directly to the path, add them to a list and then create a B4XPath from this list.
Another option is to use BitmapCreator with BCPath. You can access its points.
 
Upvote 0

emexes

Expert
Licensed User
Another option is to use BitmapCreator with BCPath. You can access its points.

That could work, if the path doesn't involve/require them fancy math-formula/scalable curves that presumably are the reason that the Android method is only returning approximate points.
 
Upvote 0

Jeffrey Cameron

Well-Known Member
Licensed User
Longtime User
Another option is to use BitmapCreator with BCPath. You can access its points.
I looked at the BC first, but it lacks the "InitializeArc" method. I'm using that method to draw a pie graph, and I was hoping to utilize the list of points created for each "slice" in a "PointInPolygon" type method to determine which slice the user taps. Is there an easier method I'm overlooking?

I was hoping to keep it cross-platform in case the client changes their mind about deployment, however a B4A-specific method for now would be acceptable. Any suggestions?
 
Upvote 0

agraham

Expert
Licensed User
Longtime User
Is there an easier method I'm overlooking?
I assume that the graph is circular and you know the location of the centre. Why not then just calculate the length and angle of the vector from the tap to the centre by simple geometry. If the length is is less than the circle radius he/she/it has tapped within the graph and the angle should tell you which segment.
 
Upvote 0

Jeffrey Cameron

Well-Known Member
Licensed User
Longtime User
just calculate the length and angle of the vector
Your easy is not the same as my easy ;) It's been nearly 40 years since my geometry class.

That's is what I ended up doing, getting the distance and then converting the Atan2 of the points to degrees and then a for-each loop to compare the start/end angle of each slice.

Thank you all for the input (although it would still be nice to have a built-in function to return a list of Double(,) for paths).
 
Upvote 0

emexes

Expert
Licensed User
Is there an easier method I'm overlooking?
This might be a too-far-outside-the-box idea, but... assuming your chart segments are in different colours, perhaps you can identify which segment was clicked by looking at the colour of the pixel/click-point (for clicks that are in the area of the chart).
 
Last edited:
Upvote 0

emexes

Expert
Licensed User
And along the same line of thinking (whilst I'm out here in the lazy-programmer-shortcuts doghouse), what I have sometimes done is to detect which region a click is in, without all the is-this-point-inside-this-path geometry math, is to overlay the area with a translucent image (alpha = 1 = undetectable) and then use one of the RGB color components to distinguish between up to 255 regions. Need to keep an eye on the memory usage, though, as in don't start leaving no-longer-needed megabyte-size bitmaps all over the place.
 
Upvote 0

udg

Expert
Licensed User
Longtime User
40yrs for me too, but I'm lucky..from time to time I can peek at my son's school book (and homeworks too) :)
 
Upvote 0

MarkusR

Well-Known Member
Licensed User
Longtime User
Last edited:
Upvote 0
Top