Hi guys, I have 4 centroid points, from these 4 points (non-corner) I intended to create a rectangular, given I only know the location of the four points. Is there a way to do this?

Thanks in advance!

Hi guys, I have 4 centroid points, from these 4 points (non-corner) I intended to create a rectangular, given I only know the location of the four points. Is there a way to do this?

Thanks in advance!

The problem of your approach is that those four points can define an infinite number of rectangles.

Better take the approach of defining corners.

Hi @architectcoding!

I think youâ€™re right. But with the information I have, Iâ€™m not sure of the best way to do this. Briefly, I actually have 4 solids â€ślineâ€ť like the in the image below, what Iâ€™m trying to do is get the center lines of the 4 solids, so that I can get its center curve. So far I have only comes to extracting its centroid and trying to form a rectangular from those points. I guess there should be a better approach to my problem?

If you have the center curves, you could just offset those curves by 1/2 the distance between the other center points.

Thatâ€™s exactly the information I donâ€™t have at the moment.

Iâ€™m confused. By the first image, it looks like you have 4 points that are at the center of the lines. Canâ€™t you make lines using those 4 points (index 0 and 2, and index 1 and 3) to make the center lines?

Thatâ€™s not corner points, you canâ€™t make a rectangular from those points. The best you can get is a diamond shaped polygon.

I know itâ€™s not, I said the center points, not corner points. That is why I said this:

If you have the horizontal line and the vertical line, offset them by half the length of the other.

Assuming the four solids are individual objects, getting the points which make up all edges of the geometry and doing a line by best fit through points may work better.

If you only need to consider the global coordinate system and your box is axis-aligned, you can use BoundingBox.ByGeometry providing your 4 points as the input, get the min and max points then use them to infer the other two corner points to create a rectangle.

If you need to create a rectangle with a specified rotation to the global coordinate system, you can use simple trigonometry and all cases should be solvable (in theory) so long as you accept cases where the some of the points do not touch the boundary curves of rectangle (but remain colinear).

3 Likes