Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.

Converting a graph to a 3D diagram

Anonymous

Converting a graph to a 3D diagram

Anonymous
Not applicable

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)
)
0 Likes
Reply
Accepted solutions (1)
1,185 Views
10 Replies
Replies (10)

Anonymous
Not applicable

Any suggestions?

0 Likes

tramber
Advisor
Advisor

Hello,

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

0 Likes

Anonymous
Not applicable

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. 

0 Likes

tramber
Advisor
Advisor

p and q are point1 et point2

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

 

0 Likes

Anonymous
Not applicable

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.

0 Likes

tramber
Advisor
Advisor
Accepted solution

 

(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

0 Likes

Anonymous
Not applicable

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.

0 Likes

tramber
Advisor
Advisor

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.

0 Likes

Anonymous
Not applicable

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.

0 Likes

Anonymous
Not applicable

Export issue solved.

0 Likes