### Author Topic: {=-Challenge-=} - closestpointto on reference surface from 3D point in space  (Read 11487 times)

0 Members and 1 Guest are viewing this topic.

#### ribarm

• Gator
• Posts: 3327
• Marko Ribar, architect
##### {=-Challenge-=} - closestpointto on reference surface from 3D point in space
« on: October 27, 2019, 01:50:26 AM »
Similar to what function (vlax-curve-getclosestpointto curve wcspt) do with reference curve, the task is now to find point on surface that is closest to reference point in 3D space...

Here on picture I marked point from as center of red sphere and in attachment there is also DWG with the same describing the task - problem...

IMHO I don't think this could be solved by using ALISP, but rather some other approach...
As a result I am expecting operational function that can operate correctly for all 3D entities such as 3DSOLIDs, SURFACEs, REGIONs, BODY entities, NURBS SURFACEs and all 3D Modeler entities...

Thanks for reading, may the competition begin...
M.R.
Marko Ribar, d.i.a. (graduated engineer of architecture)

#### ribarm

• Gator
• Posts: 3327
• Marko Ribar, architect
##### Re: {=-Challenge-=} - closestpointto on reference surface from 3D point in space
« Reply #1 on: October 27, 2019, 02:37:53 AM »

Hint : You can start with very small sphere with point as center and make it grow until it touches SURFACE... That point of touch would be solution...
But then again this is slow process...
There is a case where there could be multiple solutions (for ex. reference point is in center of reference SURFACE converted from SPHERE)...
In this case I suppose that solution would be intersection of X axis through center and SURFACE-SPHERE...
Similary if there are more than 1 soultion - the first one closest to X axis vector from reference point would be correct one... All in all - instead of (vlax-curve-getclosestpointto), you need to code for (vlax-surface-getclosestpointto) - results should be very similar in the way it is behaving with multiple solutions - single point (not list of points)...
Marko Ribar, d.i.a. (graduated engineer of architecture)

#### ribarm

• Gator
• Posts: 3327
• Marko Ribar, architect
##### Re: {=-Challenge-=} - closestpointto on reference surface from 3D point in space
« Reply #2 on: October 27, 2019, 07:32:49 AM »
This is preliminary result that I got with applying this function with sel. set of red curves describing surface...

Code: [Select]
`(defun vlax-surface-getclosestpointto ( ss pt / i c pl )  (vl-load-com)  (repeat (setq i (sslength ss))    (setq c (ssname ss (setq i (1- i))))    (if (/= (cdr (assoc 0 (entget c))) "VERTEX")      (setq pl (cons (vlax-curve-getclosestpointto c pt) pl))    )  )  (car (vl-sort pl '(lambda ( a b ) (< (distance a pt) (distance b pt))))))`
(setq p (vlax-surface-getclosestpointto ss pt))

Look in attachment - there is DWG for you to compare your result...
Marko Ribar, d.i.a. (graduated engineer of architecture)

#### BIGAL

• Swamp Rat
• Posts: 1469
• 40 + years of using Autocad
##### Re: {=-Challenge-=} - closestpointto on reference surface from 3D point in space
« Reply #3 on: October 27, 2019, 07:57:47 PM »

#### BIGAL

• Swamp Rat
• Posts: 1469
• 40 + years of using Autocad
##### Re: {=-Challenge-=} - closestpointto on reference surface from 3D point in space
« Reply #4 on: October 29, 2019, 03:34:50 AM »
The answer may be more in using a TIN Triangular irregular network. If the point can have a 90 projection and land on the surface is 1st step 2nd would be to compare distances. There is math theory for vector to 3 points. Just don't ask me how to do in lisp.

Using 3 points you can set a UCS plane going through 3 points then the point would have a z the distance off.
« Last Edit: October 29, 2019, 03:53:27 AM by BIGAL »

#### ribarm

• Gator
• Posts: 3327
• Marko Ribar, architect
##### Re: {=-Challenge-=} - closestpointto on reference surface from 3D point in space
« Reply #5 on: October 29, 2019, 08:03:10 AM »
The answer may be more in using a TIN Triangular irregular network. If the point can have a 90 projection and land on the surface is 1st step 2nd would be to compare distances. There is math theory for vector to 3 points. Just don't ask me how to do in lisp.

Using 3 points you can set a UCS plane going through 3 points then the point would have a z the distance off.

I don't think you can achieve desirable results with TIN - in terms of timing of computation... Beside that you can never interpolate surface with desirable amount of points and further more after TIN, curving of surface would be neglected - you can always get Z of 3 points and reference point in space, but to flat plane - not apex point of surface curving shape... My method of finding preliminary point is my best approach, just don't know how to proceed after that - result is never exact like it is with (vlax-curve-xxx) functions...
Marko Ribar, d.i.a. (graduated engineer of architecture)

#### roy_043

• Water Moccasin
• Posts: 1895
##### Re: {=-Challenge-=} - closestpointto on reference surface from 3D point in space
« Reply #6 on: October 29, 2019, 09:36:14 AM »
In BricsCAD the ZPERpendicular snap actually behaves as a 'closest point to surface' snap (at least in V18).
The distance between the point object in the DWG and the point found by BC is 0.10 units.

#### Marc'Antonio Alessi

• Swamp Rat
• Posts: 1454
• Marco
##### Re: {=-Challenge-=} - closestpointto on reference surface from 3D point in space
« Reply #7 on: October 29, 2019, 09:50:47 AM »
In BricsCAD the ZPERpendicular snap actually behaves as a 'closest point to surface' snap (at least in V18).
The distance between the point object in the DWG and the point found by BC is 0.10 units.
I do not know if it is inherent but perhaps it may be interesting:
V20 LISP
Added a BricsCAD-specific Lisp function (vl-vector-project-PointToEntity point viewDir entity) to calculate the point projected onto the "surface" of an entity. The function supports closed curves, 3DFace, 3DSolid, Region, Surface, PolyfaceMesh and PolygonMesh entities.

#### ribarm

• Gator
• Posts: 3327
• Marko Ribar, architect
##### Re: {=-Challenge-=} - closestpointto on reference surface from 3D point in space
« Reply #8 on: October 29, 2019, 10:01:39 AM »
Here is my further analysis...
Roy can you check DWG I am attaching here with the results of BricsCAD...
Is ZPERpendicular SNAP point inside small green surface marked near preliminary point?
Marko Ribar, d.i.a. (graduated engineer of architecture)

#### ribarm

• Gator
• Posts: 3327
• Marko Ribar, architect
##### Re: {=-Challenge-=} - closestpointto on reference surface from 3D point in space
« Reply #9 on: October 29, 2019, 10:17:09 AM »
Here is my further analysis...
Roy can you check DWG I am attaching here with the results of BricsCAD...
Is ZPERpendicular SNAP point inside small green surface marked near preliminary point?

You are right Roy, ZPER snap in BricsCAD gives correct results, but how can we implement correct (vlax-surface-getclosestpointto surface wcspt) when ZPER finds all perpendiculars on surface - not only in small green surface I marked...
Marko Ribar, d.i.a. (graduated engineer of architecture)

#### ribarm

• Gator
• Posts: 3327
• Marko Ribar, architect
##### Re: {=-Challenge-=} - closestpointto on reference surface from 3D point in space
« Reply #10 on: October 29, 2019, 10:36:32 AM »
Strangely AutoCAD 2018 also has ZPER OSNAP, but it won't SNAP to that point like BricsCAD is snapping... I don't know what to say - cumbersome ACAD...
Marko Ribar, d.i.a. (graduated engineer of architecture)

#### roy_043

• Water Moccasin
• Posts: 1895
##### Re: {=-Challenge-=} - closestpointto on reference surface from 3D point in space
« Reply #11 on: October 29, 2019, 02:23:19 PM »
ZPER finds all perpendiculars on surface - not only in small green surface I marked...
In my test (BricsCAD V18) only one point is found. It does not matter where you click the surface.

#### roy_043

• Water Moccasin
• Posts: 1895
##### Re: {=-Challenge-=} - closestpointto on reference surface from 3D point in space
« Reply #12 on: October 29, 2019, 02:25:14 PM »
Strangely AutoCAD 2018 also has ZPER OSNAP, but it won't SNAP to that point like BricsCAD is snapping...

Snaps to a perpendicular face (planar faces only).

#### ribarm

• Gator
• Posts: 3327
• Marko Ribar, architect
##### Re: {=-Challenge-=} - closestpointto on reference surface from 3D point in space
« Reply #13 on: October 29, 2019, 03:06:07 PM »
ZPER finds all perpendiculars on surface - not only in small green surface I marked...
In my test (BricsCAD V18) only one point is found. It does not matter where you click the surface.

I tested it once again on BricsCAD V19 and you are right, only one point on surface, but on boundaries there are many... I'll attach *.DWG once more for you to see...
Marko Ribar, d.i.a. (graduated engineer of architecture)

#### ribarm

• Gator
• Posts: 3327
• Marko Ribar, architect
##### Re: {=-Challenge-=} - closestpointto on reference surface from 3D point in space
« Reply #14 on: October 29, 2019, 03:21:49 PM »
Yes, I tested it once again without curves and yes you are right - only one ZPER snap... So discard my previous post...

Regards, M.R.
Marko Ribar, d.i.a. (graduated engineer of architecture)