## Get mesh points from shape

Posts that don't fit into other categories.
assofohdz
Posts: 26
Joined: Mon Apr 17, 2017 10:46 am

### Get mesh points from shape

Hi

Is there any way to get the mesh point (x,y) from a shape in Dyn4j?

William
Posts: 378
Joined: Sat Feb 06, 2010 10:23 pm

### Re: Get mesh points from shape

It will depend on the shape:

Shapes that implement Wound will have getVertices() and getNormals() methods: Link, Segment, Polygon, Rectangle, Triangle.

The other shapes; Circle, Ellipse, HalfEllipse, and Slice have curved features so technically have an infinite number of vertices. Each one is stored differently. For example, a circle is represented as a center point and a radius, an ellipse is represented by it's width/height and local axis, and so on.

If you are using the Shape or Convex interfaces you'll need to do some type checking:
1. Convex c = // whatever;
2. if (c instanceof Wound) {
3.   Wound w = (Wound)c;
4.   Vector2[] points = w.getVertices();
5. }

If you need all your shapes to have vertices, look into the Geometry.createPolygonalX methods to create polygonal approximations of the curved shapes.

William

assofohdz
Posts: 26
Joined: Mon Apr 17, 2017 10:46 am

### Re: Get mesh points from shape

Thanks. I found the JavaDoc after I posted and also found the method you mentioned. I converted my circles to polygonals. I guess some of my shapes will have to have circle-shape (due to game logic I want projectiles to bounce correctly off surfaces for example, but it doesn't matter that much for impact on enemies if the enemy is circular or polygonal).

Thanks for the quick response