Is it possible if we get the coordinates of the 4 vertices of the rectangle by choosing any point inside the rectangle?

Is it possible if we get the coordinates of the 4 vertices of the rectangle by choosing any point inside the rectangle?

tim11_manhhieu
Advocate Advocate
260 Views
2 Replies
Message 1 of 3

Is it possible if we get the coordinates of the 4 vertices of the rectangle by choosing any point inside the rectangle?

tim11_manhhieu
Advocate
Advocate

The question may be silly, but it is possible if we pick any point E inside the rectangle ABCD, then display the coordinates of the 4 vertices A, B, C, D.

 

tim11_manhhieu_0-1739173245853.png

 

0 Likes
Accepted solutions (1)
261 Views
2 Replies
Replies (2)
Message 2 of 3

norman.yuan
Mentor
Mentor
Accepted solution

Yes, it is possible, or rather easy to do it (but code-wise, it might be quite big chunk of code, depending on how you approach it). Here are the steps of a possible approach, once you have the point (by user selected, or by your code identified...)

 

1. Create a Ray (AcadRay) starting at the point;

2. loop through all AcadLWPolylines (assume the rectangle is an AcadLWPolyline) to test:  a. if the polyline is closed with 4 vertices; b. if the ray intersects with the polyline ONLY ONCE. If the 2 condition meets, the point is inside the closed polyline. (There are different way to test if a point is inside an area. You can search online, or ask Copilot/Chat-GPT... for other algorithms);

3. Determine if the closed polyline is a RECTANGLE. If the rectangle is supposed to be horizontal/vertical with its segments, then the coordinates of the 4 vertices would be the same as the bounding box. If the rectangle is rotated in an angle, you would need to test the angle of a connected segments for being 90 degree.

4. After all is done, remember to delete the auxiliary ray.

Norman Yuan

Drive CAD With Code

EESignature

0 Likes
Message 3 of 3

tim11_manhhieu
Advocate
Advocate

I did it, but I recommend one thing when checking the intPoints array in the reference code below, use count element instead of using vartype().

 

https://help.autodesk.com/view/ACD/2017/JPN/?guid=GUID-1243A593-5DAE-4DC3-B539-59FDA990E687 

 

If VarType(intPoints) <> vbEmpty then

change to

elementCount = UBound(intPoints) - LBound(intPoints) + 1

 

0 Likes