Is it possible to create a concave polygon in PhysicsJS? - physicsjs

I know we are able to create a convex polygon. How about concave polygon? Is it possible to combine two convex polygons then group them to form a concave one? I know Box2D can do that.

Not yet. Creating concave polygons will involve decomposing them into convex polygons and creating a composite body with them. Composite bodies are an upcoming feature. So unfortunately you'll have to wait a bit.

Related

Leaflet Polygon with 6 or more latlon points

Helo! I have 8 points and I need to draw a polygon, but if I pass the points randomly, the lines cross as shown in the image below. I needed to make a closed polygon without crossing lines.
var latlngs
var polygon = L.polygon(latlngs, {color: 'red'}).addTo(map);
Leaflet has no idea what the "intended" order of points is. While you may have in your mind that you want a relatively convex shape crafted from x number of points, you need to be the one to order them properly so that the shape you intend is drawn as you intend it.
If you are facing a problem where you have an unsorted array of points, and you need to draw the most convex shape around those points that you can, this is a classic convex hull problem. TurfJS has a convex function you can use for that. There's also a concave hull function there if that's what you need.

How to check if given 3d point is outside convex hull

I'm working on a science project. I have a list of xyz-coordinates of voronoi diagram vertices, and a list of points that create my protein's convex-hull (from triangulation). Now some of the vertices lie quite far from the hull and I'd like to filter them out. How can I do it in c++ ? For now it doesn't have to be super optimised, I'm only focused on removing those points.
visualization
I was also thinking to check if a line from voronoi vertex(red crosses) to center of protein(pink sphere) is intersecting with hull face at any point, but I'm not sure how to achive that.
I've read that you can check if a point is inside a polygon by counting the times an infinite line from the point is crossing the hull, but that was for two dimensions. Can similar approach be implemented to suit my needs ?
https://www.geeksforgeeks.org/how-to-check-if-a-given-point-lies-inside-a-polygon/
Let's start with the two-dimensional case. You can find the solution to that on CS.SX:
Determine whether a point lies in a convex hull of points in O(logn)
The idea is that each two consecutive points on the convex hull define a triangular slice of the plane (to some internal point of the hull); you can find the slice in which your point is located, and check whether it's closer to the internal point than the line segment bounding the slide.
For the three-dimensional case, I'm guessing you should be able to do something similar, but the search for the 3 points forming the relevant triangle might be a little tricky. In particular, it would also depend on how the convex hull is represented - as in the 2-d case the convex hull is just a sequence of consecutive points on a cycle.
I know this doesn't quite solve your problem but it's the best I've got given what you've written...

Convex Hull with a predefined number of vertices

I am working on image segmentation and I thought the convex hull can provide me with a simple solution to my problem. Currently I have polygons with for sides (see image below). Due to image processing issues, the shape does not have clean straight sides and hence when I use the standard convex hull (in Matlab) I may get more than the four main corners to define it.
My goal is to force the convex hull algorithm to find the best 4 vertices that will enclose my polygons (i.e. 4 best enclosing vertices per polygon). Is this possible? An example code will be appreciated.
Thanks
The problem of the minimum area bounding polygon is briefly mentioned in "Geometric applications of a matrix-searching algorithm" (see Applications section). It is not simple and is probably not the way for you.
For an easier (but approximate) answer to your question, you can consider the four cardinal directions and find the farthest points in these, which define a quadrilateral. (Also consider the four intermediate directions, which are more appropriate for an axis-aligned rectangle.)
If you insist having an enclosing quadrilateral, you can translate the four edges to the farthest points in the respective perpendicular directions, and find the pairwise intersections.
If you insist having a rectangle, compute the convex hull and find the minimum area or minimum perimeter bounding rectangle by the Rotating Calipers method. https://geidav.wordpress.com/tag/rotating-calipers/

I have a point set in image,how to find the External irregular shape circling all the points by Matlab

I got a point set after executing SIFT algorithm.Now I want to find the external irregular shape of those points.Is there anyone knowing the relevant functions in Matlab? Notice that I don't want the convex hall.Thank you!
If you want convex hull, (unclear based on your comment... you can edit questions btw), look up convhull.
If you don't want convex hull, a Delaunay triangulation will probably get you started since the result captures both the convex hull of the points, but also the internal structure such that you may be able to remove some edges from the outside of the returned triangulation.

Create contour of given points using MKPolygon in iPhone

I have various number of points each time, and I want to draw contour from them. So I need to draw polygon using only extreme points. Is there any ready to use solution?
EDIT:
It sounds like you are looking for the convex hull of a set of points.
Implemented using the google maps API v3