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

0 Members and 1 Guest are viewing this topic.

ribarm

  • Gator
  • Posts: 3225
  • Marko Ribar, architect
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)

:)

M.R. on Youtube

ribarm

  • Gator
  • Posts: 3225
  • Marko Ribar, architect
Just as addition...

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)

:)

M.R. on Youtube

ribarm

  • Gator
  • Posts: 3225
  • Marko Ribar, architect
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)

:)

M.R. on Youtube

BIGAL

  • Swamp Rat
  • Posts: 1396
  • 40 + years of using Autocad
A man who never made a mistake never made anything

BIGAL

  • Swamp Rat
  • Posts: 1396
  • 40 + years of using Autocad
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 »
A man who never made a mistake never made anything

ribarm

  • Gator
  • Posts: 3225
  • Marko Ribar, architect
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)

:)

M.R. on Youtube

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
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: 1451
  • Marco
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: 3225
  • Marko Ribar, architect
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)

:)

M.R. on Youtube

ribarm

  • Gator
  • Posts: 3225
  • Marko Ribar, architect
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)

:)

M.R. on Youtube

ribarm

  • Gator
  • Posts: 3225
  • Marko Ribar, architect
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)

:)

M.R. on Youtube

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
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
  • BricsCAD 18
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: 3225
  • Marko Ribar, architect
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)

:)

M.R. on Youtube

ribarm

  • Gator
  • Posts: 3225
  • Marko Ribar, architect
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)

:)

M.R. on Youtube