Author Topic: [LISP] Normal vector in given point on surface  (Read 1669 times)

0 Members and 1 Guest are viewing this topic.

WhoseThatLispIsOnTheCAD

  • Mosquito
  • Posts: 3
[LISP] Normal vector in given point on surface
« on: October 12, 2021, 06:01:33 AM »
Hello everyone.
Im working on some script whitch be able to wrap a plane onto a curved shaped surface. Something similar to "shrikwrap" modifier in Blender. I try to simulate the natural effect of a lath bending on bottle neck. If the direction of bending a board is collinear with the main curvature its tend to twist.
This effect is shown here:
https://drive.google.com/file/d/16FR6H5uFYlVO7usGb3SpZHULhjBFtJCh/view?usp=sharing
The steps of the program looks like:
1. Find a startPoint - whitch is an itersection point of a given ray and the surface
   here i have also some problems because to find this point i generate the section via Vl-cmdf _section and looks  for an intersection point with a given ray (red color line on the image). Sometimes created section shape is made of lines, polylines, 3dpolylines or splines. Espacialy when splines are being created the intersection points can not be find because of a devation - the splines doesnt lays on a section plane (diferrences about 0,0001) 
2. From the startPoint program looks for edge points (width of lath P1 and P2)
3. The lath is being divided into small parts (points along dthe edges) and tests the distance relation beetwen them.
4. From P1 and P2 scripts is looking for points Px1 and Px2 on a surface whitch have the same distance relations as the oryginal ones. Px1 becomes P1 and so on for given number of iteration...
to find this point im using get_border_on_surface whitch collects a sort of point list spreaded around the given point  P1 with the same distance
https://www.youtube.com/watch?v=Ys2yoAecjio   - here is sample testing...
The program works very slowly and the problems accurs when the curvature fades out of the horizon - surface became prependicular to the curent UCSSo i need to find to find normal vector in a point P1 to generate multiple sections around this normal axis
https://drive.google.com/file/d/1LAbW8A-S93FDITzycgWjNiOCmWEXdE2J/view
IS any way to get point list of a intersected face by ray as a subsurface element via vlisp??
ps. Im a newbie with lacks of knowlege, but here is probably one and only place i can get some hints and where i can be enligthen. You are my Hope - the most proffecional cad forum on worldWide... :-)

didier

  • Newt
  • Posts: 48
  • expatrié
Re: [LISP] Normal vector in given point on surface
« Reply #1 on: October 12, 2021, 07:06:04 AM »
Bonjour WhoseThatLispIsOnTheCAD

What you are asking for is programmable if what you call surface are face3d.
But since you are a beginner (it is you who say it) I think it is not a good idea to treat this kind of concern.
The ancient elders said "think big but start small".

Amicalement
eternal beginner ...
my english is not fluent ...

WhoseThatLispIsOnTheCAD

  • Mosquito
  • Posts: 3
Re: [LISP] Normal vector in given point on surface
« Reply #2 on: October 12, 2021, 08:32:04 AM »
Thanks for Your interest didier.
As a subsurface i mean the planar part (polygon) of entire surface, like is in an edit mesh mode in other 3d modelling softwares. If i could get vertices from that face (3 planar points) thats would solve the problem... Solids and surfaces (dxf code) are a mystery for me, total magic witch them i can not deal with :(. In dynamic UCS mode autocad recognize that normal vector immediately according to the cursor position on the screen. Im wondering how to intercept that....

didier

  • Newt
  • Posts: 48
  • expatrié
Re: [LISP] Normal vector in given point on surface
« Reply #3 on: October 12, 2021, 11:33:43 AM »
Bonjour

to transform surfaces into 3D faces you just have to decompose them
then it is a calculation of vectors and normal for each point of the polygon to project on the faces.
As I told you it is not simple for a beginner.
Amicalement
eternal beginner ...
my english is not fluent ...

d2010

  • Bull Frog
  • Posts: 323
Re: [LISP] Normal vector in given point on surface
« Reply #4 on: October 17, 2021, 05:57:12 AM »
You need integrate mathematicallyLisp  inside VLISP.?
You develop, here,  the  list-of-all-Steps as you need.
If you can not write a LIST-of-Steps, then you cannot finish this post.
Code: [Select]
01).You upload a sample Drawing.dwg (as old-version Acad2010 or Acad2018)
02).User select one point outside from surface3d.
03).-- You fill here --
....
31)....
Hello everyone.
Im working on some script whitch be able to wrap a plane onto a curved shaped surface. Something similar to "shrikwrap" modifier in Blender. I try to simulate the natural effect of a lath bending on bottle neck. If the direction of bending a board is collinear with the main curvature its tend to twist.

WhoseThatLispIsOnTheCAD

  • Mosquito
  • Posts: 3
Re: [LISP] Normal vector in given point on surface
« Reply #5 on: October 21, 2021, 08:55:10 AM »
Merci beaucoup #didier
Thanks for Your interest #d2010

https://drive.google.com/file/d/1Vh-648H4NXEMZ219qd18fSUdSJW_Jkk5/view?usp=sharing there is a .dwg file with sample mesh and effect of my script "foldit"
-along the path the lath are positioned and then all of them are wraped onto sample mesh..
for 9 of 10 lath its works fine exept one. In that place mesh is little bit complicated... (as a product of boolean union of 2 compound object with fillet operation on the common edge)

thanks for your suggestions, i have some trace to follow, for now i dont want to bother anybody with my problems.... :)

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8659
  • AKA Daniel
Re: [LISP] Normal vector in given point on surface
« Reply #6 on: October 28, 2021, 11:17:41 PM »
Hi, I had written an ARX routine for someone once to get the closest point on a surface, maybe it will help you.

Code - Text: [Select]
  1. (defun c:usage()
  2.   (setq pnt1 (cdr (assoc 10 (entget(car(entsel))))))
  3.   (setq pnt2 (getClosestPointTo (car (entsel)) pnt1))
  4.   (grdraw pnt1 pnt2 1 0)
  5. )
  6.  

Also you may be able to read some surface data with lisp, though its limited.

Code - Text: [Select]
  1. (defun foo ( acis_data )
  2.     (   (lambda ( bar )
  3.             (mapcar
  4.                '(lambda ( x ) (if (eq 1 (car x)) (cons 1 (bar (cdr x))) x))          
  5.                 acis_data
  6.             )      
  7.         )
  8.         (lambda ( string )
  9.             (vl-list->string
  10.                 (mapcar
  11.                    '(lambda ( x ) (if (eq 32 x) x (boole 6 95 x)))
  12.                     (vl-string->list string)
  13.                 )
  14.             )
  15.         )  
  16.     )  
  17. )
  18.  
  19. (defun c:doit2 ()
  20.  (foo (entget (car(entsel))))
  21. )
  22.  

Quote
(1 . "point $-1 -1 $-1 27.2409519097224404 13.84081836339358773 0 #") (1 . "point $-1 -1 $-1 27.2409519097224404 41.68038048964594822 0 #")

Lee Mac

  • Seagull
  • Posts: 12905
  • London, England
Re: [LISP] Normal vector in given point on surface
« Reply #7 on: October 29, 2021, 06:27:29 PM »
Code - Text: [Select]
  1. (defun foo ( acis_data )
  2.     (   (lambda ( bar )
  3.             (mapcar
  4.                '(lambda ( x ) (if (eq 1 (car x)) (cons 1 (bar (cdr x))) x))          
  5.                 acis_data
  6.             )      
  7.         )
  8.         (lambda ( string )
  9.             (vl-list->string
  10.                 (mapcar
  11.                    '(lambda ( x ) (if (eq 32 x) x (boole 6 95 x)))
  12.                     (vl-string->list string)
  13.                 )
  14.             )
  15.         )  
  16.     )  
  17. )
  18.  
  19. (defun c:doit2 ()
  20.  (foo (entget (car(entsel))))
  21. )
  22.  

This has MP's fingerprints all over it - I still can't believe he's no longer with us  :-(