Jeffrey Cameron Well-Known Member Licensed User Longtime User Mar 8, 2019 #1 I saw in https://www.b4x.com/android/forum/threads/xui-modify-b4xpath-points.92397/ where @Erel said Erel said: Currently no. Click to expand... to modifying a path, but is there any way to just get a list of the point pairs in a B4XPath variable? Something such as: Code: Copy Dim pdPoints(,) As Double = MyB4xPath.ToArray() ' or something like? Dim pdPoints(,) As Double = XUI.PathToArray(MyB4xPath) If not then consider this a [WISH] request
I saw in https://www.b4x.com/android/forum/threads/xui-modify-b4xpath-points.92397/ where @Erel said Erel said: Currently no. Click to expand... to modifying a path, but is there any way to just get a list of the point pairs in a B4XPath variable? Something such as: Code: Copy Dim pdPoints(,) As Double = MyB4xPath.ToArray() ' or something like? Dim pdPoints(,) As Double = XUI.PathToArray(MyB4xPath) If not then consider this a [WISH] request
DonManfred Expert Licensed User Longtime User Mar 9, 2019 #2 As B4XPath is a wrap around android.graphics.Path: I don´t see any Methods to get the Points in a Path. Upvote 0
As B4XPath is a wrap around android.graphics.Path: I don´t see any Methods to get the Points in a Path.
E emexes Expert Licensed User Longtime User Mar 9, 2019 #3 DonManfred said: As B4XPath is a wrap around android.graphics.Path: I don´t see any Methods to get the Points in a Path. Click to expand... 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
DonManfred said: As B4XPath is a wrap around android.graphics.Path: I don´t see any Methods to get the Points in a Path. Click to expand... 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
Erel B4X founder Staff member Licensed User Longtime User Mar 10, 2019 #4 emexes said: not the precise points, agreed, but how about: approximate added in API level 26 Click to expand... 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 said: not the precise points, agreed, but how about: approximate added in API level 26 Click to expand... 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.
E emexes Expert Licensed User Longtime User Mar 10, 2019 #5 Erel said: Another option is to use BitmapCreator with BCPath. You can access its points. Click to expand... 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
Erel said: Another option is to use BitmapCreator with BCPath. You can access its points. Click to expand... 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.
Jeffrey Cameron Well-Known Member Licensed User Longtime User Mar 11, 2019 #6 Erel said: Another option is to use BitmapCreator with BCPath. You can access its points. Click to expand... 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
Erel said: Another option is to use BitmapCreator with BCPath. You can access its points. Click to expand... 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?
agraham Expert Licensed User Longtime User Mar 11, 2019 #7 Jeffrey Cameron said: Is there an easier method I'm overlooking? Click to expand... 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 said: Is there an easier method I'm overlooking? Click to expand... 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.
MarkusR Well-Known Member Licensed User Longtime User Mar 11, 2019 #8 with PathMeasure you can get any point at the path https://stackoverflow.com/questions/7972780/how-do-i-find-all-the-points-in-a-path-in-android PathMeasure https://developer.android.com/reference/android/graphics/PathMeasure Upvote 0
with PathMeasure you can get any point at the path https://stackoverflow.com/questions/7972780/how-do-i-find-all-the-points-in-a-path-in-android PathMeasure https://developer.android.com/reference/android/graphics/PathMeasure
Jeffrey Cameron Well-Known Member Licensed User Longtime User Mar 11, 2019 #9 agraham said: just calculate the length and angle of the vector Click to expand... 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
agraham said: just calculate the length and angle of the vector Click to expand... 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).
E emexes Expert Licensed User Longtime User Mar 11, 2019 #10 Jeffrey Cameron said: Is there an easier method I'm overlooking? Click to expand... 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: Mar 11, 2019 Upvote 0
Jeffrey Cameron said: Is there an easier method I'm overlooking? Click to expand... 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).
E emexes Expert Licensed User Longtime User Mar 11, 2019 #11 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
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.
agraham Expert Licensed User Longtime User Mar 12, 2019 #12 Jeffrey Cameron said: It's been nearly 40 years since my geometry class Click to expand... 60 for me but I can still remember Pythagoras (but that's about all I can remember - the calculus went years ago ) Upvote 0
Jeffrey Cameron said: It's been nearly 40 years since my geometry class Click to expand... 60 for me but I can still remember Pythagoras (but that's about all I can remember - the calculus went years ago )
udg Expert Licensed User Longtime User Mar 12, 2019 #13 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
40yrs for me too, but I'm lucky..from time to time I can peek at my son's school book (and homeworks too)
MarkusR Well-Known Member Licensed User Longtime User Mar 12, 2019 #14 there exists a region class which have a setPath & contains x,y method. https://stackoverflow.com/questions/9588003/android-how-to-check-if-a-path-contains-touched-point https://developer.android.com/reference/android/graphics/Region line/line intersect is also interesting. (each line segment from outline tested with a cross where the mouse is) Last edited: Mar 12, 2019 Upvote 0
there exists a region class which have a setPath & contains x,y method. https://stackoverflow.com/questions/9588003/android-how-to-check-if-a-path-contains-touched-point https://developer.android.com/reference/android/graphics/Region line/line intersect is also interesting. (each line segment from outline tested with a cross where the mouse is)