Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Converting a graph to a 3D diagram

10 REPLIES 10
SOLVED
Reply
Message 1 of 11
Anonymous
1123 Views, 10 Replies

Converting a graph to a 3D diagram

The following code (ref) can be used to generate a 2D diagram when coordinates, nodes, and edges of a graph are given.

(defun graph ( pts sls tls wgt )
    (   (lambda ( l )
            (foreach x l (text (cdr x) (itoa (car x)) 0.0 1))
            (mapcar
               '(lambda ( a b c / p q r )
                    (setq p (cdr (assoc a l))
                          q (cdr (assoc b l))
                          r (angle p q)
                    )
                    (entmake (list '(0 . "LINE") (cons 10 p) (cons 11 q) '(62 . 8)))
                    (text
                        (mapcar '(lambda ( x y ) (/ (+ x y) 2.0)) p q)
                        (itoa c)
                        (if (and (< (* pi 0.5) r) (<= r (* pi 1.5))) (+ r pi) r)
                        2
                    )
                )
                sls tls wgt
            )
        )
        (mapcar 'cons (vl-sort (append sls tls) '<) pts)
    )
)
(defun text ( p s a c )
    (entmake
        (list
           '(0 . "TEXT")
            (cons 10 p)
            (cons 11 p)
            (cons 50 a)
            (cons 01 s)
            (cons 62 c)
           '(40 . 2)
           '(72 . 1)
           '(73 . 2)
        )
    )
)


(graph
   '((75 25) (115 45) (90 60) (10 5) (45 0) (45 55) (0 25))
   '( 1  1  1  1  2  2  3  4   4  5  6)
   '( 2  3  4  5  3  6  6  5   7  7  7)
   '(50 10 20 80 90 90 30 20 100 40 60)
)


I'd like to ask for suggestions on how the above code has to be modified to draw 3D diagrams when 3D coordinates of nodes are available.

 

(graph
   '((75 25 0) (115 45 24) (90 60 21) (10 5 4) (45 0 1) (45 55 23) (0 25 123))
   '( 1  1  1  1  2  2  3  4   4  5  6)
   '( 2  3  4  5  3  6  6  5   7  7  7)
   '(50 10 20 80 90 90 30 20 100 40 60)
)
Tags (1)
Labels (1)
10 REPLIES 10
Message 2 of 11
Anonymous
in reply to: Anonymous

Any suggestions?

Message 3 of 11
tramber
in reply to: Anonymous

Hello,

Your program already works in 3D. So, what is the point ?

Message 4 of 11
Anonymous
in reply to: tramber

Sorry, this wasn't written by me. I don't completely understand how this works. But from what I understand

 

 (entmake (list '(0 . "LINE") (cons 10 p) (cons 11 q) '(62 . 8)))

uses  p and q ( are these x and y coordinates?) to construct a line. I'd like to know how to use x,y, and z coordinates. 

Message 5 of 11
tramber
in reply to: Anonymous

p and q are point1 et point2

p and q include x,y or x,y,z. 

 

Message 6 of 11
Anonymous
in reply to: tramber

Thanks a lot for the clarification. Could you please explain how the text is positioned?

(text
                        (mapcar '(lambda ( x y ) (/ (+ x y) 2.0)) p q)
                        (itoa c)
                        (if (and (< (* pi 0.5) r) (<= r (* pi 1.5))) (+ r pi) r)
                        2
                    )

I'd like to understand what x and y refer to.

Message 7 of 11
tramber
in reply to: Anonymous

 

(mapcar '(lambda ( a b  ) (/ (+ a b) 2.0)) p q)

 

foreach

xp xq

yp yq

and sometimes zp zq

it makes an average.

lambda applies its formula to each pair of contents from p and q

 

p= '(0 2 4 8 10)

q='(0 4 4 32)

gives

'(0 3 4 20) and 10 from p is ignored by lambda

Message 8 of 11
Anonymous
in reply to: tramber

Thanks a lot for the clarification. I'd like to know if the geometry generated after running this program can be saved

as a 3d CAD file. I tried to export in dxf and dwg format. But I think this generates only a 2D CAD file.

Message 9 of 11
tramber
in reply to: Anonymous

That is only a question of "point of view".

1. you can try the VIEW command (there are dozens of ways to see your drawing in perspective

2. a blue grip is always a magnet, you can put your cursor in and read the coordinates (if you activated them in the Hamburger [bottom-right], what should be always done even if it is not by default). You would see that those coordinates are 3D or not.

Message 10 of 11
Anonymous
in reply to: tramber

I could view the coordinates are in 3D. But I would like to know how to save this as a 3D CAD file for importing in tools like COMSOL.

Message 11 of 11
Anonymous
in reply to: Anonymous

Export issue solved.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

AutoCAD Inside the Factory


Autodesk Design & Make Report