Surface from 3 points

Surface from 3 points

BB8x
Advocate Advocate
2,703 Views
13 Replies
Message 1 of 14

Surface from 3 points

BB8x
Advocate
Advocate

Hello

 

Maybe someone has or can write something for me. I need to draw surface from 3 points (triangle, planar).

 

I can imagine this like that:

1) I do click 3 points in the drawing

2) Lisp creates 3d poly or 3d face (what is easier)

3) Lisp turns 3d poly or 3d face into surface

4) Lisp deletes base 3d poly or 3d face

 

Thanks

0 Likes
Accepted solutions (3)
2,704 Views
13 Replies
Replies (13)
Message 2 of 14

doaiena
Collaborator
Collaborator
Accepted solution

Here you go.

(defun c:test ( / p1 p2 p3 lastEnt)

(setq p1 (getpoint "\nPick first point: "))
(setq p2 (getpoint "\nPick second point: "))
(setq p3 (getpoint "\nPick third point: "))

(if (and p1 p2 p3)
(progn

(if (vl-cmdf "3dface" p1 p2 p3 "" "")
(progn
(setq lastEnt (entlast))
(vl-cmdf "convtosurface" lastEnt "")
(vl-cmdf "erase" lastEnt "")
))
))
(princ)
);defun
Message 3 of 14

Sea-Haven
Mentor
Mentor

A surface is a more plural answer of multiple 3dfaces, so why convert ? Are you trying to make a multi 3dface surface if so just google for Triangulation it will make a surface form points.

0 Likes
Message 4 of 14

BB8x
Advocate
Advocate

Thanks doaiena lips works great

 

Usually I do triangulation, but sometimes is easier to draw than delete unwanted elements from triangulation

0 Likes
Message 5 of 14

_gile
Consultant
Consultant
Accepted solution

Hi,

 

It would be much cheaper to simply do some geometric computation.

You can easily calculate the signed area of a triangle (it's equal to the half of the Z coordinate of the cross product of (p1,p2) and (p1,p3) vectors). The sign of the result also indicate if points are clockwise or not.

 

(defun signedArea (p1 p2 p3)
  (/ (-	(* (- (car p2) (car p1)) (- (cadr p3) (cadr p1)))
	(* (- (car p3) (car p1)) (- (cadr p2) (cadr p1)))
     )
     2.0
  )
)

(defun c:test (/ p1 p2 p3)
  (and
    (setq p1 (getpoint "\nPick first point: "))
    (setq p2 (getpoint "\nPick second point: "))
    (setq p3 (getpoint "\nPick third point: "))
    (alert
      (strcat
	"Area = "
	(rtos (abs (signedArea p1 p2 p3)))
	"\nPoints are "
	(if (minusp (signedArea p1 p2 p3))
	  "clockwise"
	  "counterclockwise"
	)
      )
    )
  )
  (princ)
)

 



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 6 of 14

john.uhden
Mentor
Mentor

BTW, if you're looking to shave off a few nanoseconds, I think I found years ago that multiplying by 0.5 is faster than dividing by 2.

John F. Uhden

Message 7 of 14

braudpat
Mentor
Mentor

Hello @john.uhden 

 

Your answer is THE BEST !

 

THE HEALTH (Stay Safe), Regards, Patrice

 

Patrice ( Supporting Troops ) - Autodesk Expert Elite
If you are happy with my answer please mark "Accept as Solution" and if very happy please give me a Kudos (Felicitations) - Thanks

Patrice BRAUD

EESignature


0 Likes
Message 8 of 14

john.uhden
Mentor
Mentor
Yes, well, after enough millenia, those nanoseconds can add up, maybe to as
much as a full blink of an eye. *;)*

John F. Uhden

0 Likes
Message 9 of 14

diagodose2009
Collaborator
Collaborator
Accepted solution

Can you extend this routine?

;; Revision :07/03/2020 @Anonymous:44
(defun c:fc1 ( / p1 p2 p3)
(progn  
       (setq p1 (getpoint "\nPick first point: "))
       (setq p2 (getpoint "\nPick second point: "))
       (setq p3 (getpoint "\nPick third point: "))
       (setq p4 (getvar "VIEWCTR"))
       (if (and p1 p2 p3)
       (progn  (setq CmColor 1)
               (entmakex (list (cons 0 "3DFACE") 
                         (cons 100 "AcDbEntity") 
                                    (cons 67  0) 
                                    (cons 8 "0") 
                               (cons 62 CmColor) 
                           (cons 100 "AcDbFace") 
                             (cons 10  p1) 
                             (cons 11  p2) 
                             (cons 12  p3)
                             (cons 13  p3) 
                                   (cons 70 0)))
               (princ)
               (entmakex (list (cons 0 "3DFACE") 
                         (cons 100 "AcDbEntity") 
                                    (cons 67  0) 
                                    (cons 8 "0") 
                               (cons 62 50) 
                           (cons 100 "AcDbFace")
                             (cons 10  p1) 
                             (cons 11  p2) 
                             (cons 12  p3)
                             (cons 13  p4) 
                                   (cons 70 0)))
               (princ)
       ))
      )
) ; end eMaker
0 Likes
Message 10 of 14

_gile
Consultant
Consultant

@diagodose2009  a écrit :

Can you extend this routine?


Sorry, I do not understand what you mean.



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 11 of 14

Sea-Haven
Mentor
Mentor

You mean repeat

 

 

(while (setq p1 (getpoint "\nPick first point: "))

extra close bracket at end

               (princ)
       ))
      ))
) 

 

0 Likes
Message 12 of 14

BB8x
Advocate
Advocate

Hello again

 

Is there a chance to upgrade this lisp? For now creates surfaces. Would be possible to create surfaces OR mesh OR 3d solid (selectable)?

 

Lets say like this:

1) Lisp start

2) "What would you like to do you lazy ****? Surface Mesh 3dSolid"

3) Carry on with lisp

4) Chosen output

0 Likes
Message 13 of 14

Sea-Haven
Mentor
Mentor

Just go back to what I said get a triangulation routine pick all points, this makes 3dfaces. Google for next steps. They exist.

0 Likes
Message 14 of 14

BB8x
Advocate
Advocate

I know google knows that and been trying for few days. Thing is I did find only way to extrude or thicken surface. I wanted to keep in as it is (planar). All I am doing now is extruding for 0.0001 drawing units

0 Likes