We value your input!
Please participate in Archicad 28 Home Screen and Tooltips/Quick Tutorials survey

GDL
About building parametric objects with GDL.
SOLVED!

How to get the coordinates of a line in gdl?

LeeJaeYoung
Virtuoso

LeeJaeYoung_0-1664891893466.png

In gdl, we know the coordinates of p1 and p2 and we know the distance from x1 to x4. Then how do we get the coordinates of x1~x4?

 

2D
We know the coordinates of p1 and p2. And we know the distance from p1 to x4.
1. How do you find the angle with p1 and p2?
2. How do you find the coordinates of x4? (Example: Autolisp (setq x4 (polart p1 angle distance))
3. How do you find the coordinates of x3?

Do I need to convert to radians when using angles?

Thanks for reading.

AC27 on window 11
2 ACCEPTED SOLUTIONS

Accepted Solutions
Solution
julienK
Advocate

the easiest way to find the coordinates of a point on a line is to use the parametric equation of a line:

 

x4 = x1+((x2-x1)*(ratio))
y4 = y1+((y2-y1)*(ratio))

 

with p1(x1,y1) p2(x2,y2).

ratio is a number between 0 and 1 representing the distance from p1 to p2

 

 

just a bit of math to find the rest:

 

!p1 & p2

xp1 = -5
yp1 = 0
xp2 = 0
yp2 = 5

!distance from p1 to x4  p1 to x1
ratio = .25



x4 = xp1+((xp2-xp1)*(ratio))
y4 = yp1+((yp2-yp1)*(ratio))

x1 = xp1+((xp2-xp1)*(1-ratio))
y1 = yp1+((yp2-yp1)*(1-ratio))


!slope of the line need to find x3 and x2
THETA = atn((yp2-yp1)/(xp2-xp1))

! distance  between x3 and x4
offset = 2

! coordinates of point x3
x3 = x4+ offset *cos(90+THETA)
y3 = y4+  offset *sin(90+THETA)

x2 = x1+ offset *cos(90+THETA)
y2 = y1+  offset *sin(90+THETA)




!draw lines

line2 xp1,yp1,xp2,yp2

line2 x4,y4,x3,y3
line2 x1,y1,x2,y2

line2 x3,y3,x2,y2

View solution in original post

Solution
julienK
Advocate

The ratio is just a value you chose of how far along the line x4 and x1 are.

if you use .5  it will be  in the middle.

 

Copy the full code I posted in a new object 2D script and change to value of ration and offset to see how the 2D view changes.

View solution in original post

7 REPLIES 7
Miha Nahtigal
Advocate

1. calculate the angle of the line to y or x axis

2. rot2 command -  rotate the coordinate system so the line between p1 and p2 is vertical or horizontal

3. the rest should be easy... you have only straight lines to draw between points

BIMquants.comBETA - Quantities and Costs Estimation in Archicad - BETA testers needed.
LeeJaeYoung
Virtuoso

It means using ADD2 and ROT2 to handle it.
thank you ^^

AC27 on window 11
Solution
julienK
Advocate

the easiest way to find the coordinates of a point on a line is to use the parametric equation of a line:

 

x4 = x1+((x2-x1)*(ratio))
y4 = y1+((y2-y1)*(ratio))

 

with p1(x1,y1) p2(x2,y2).

ratio is a number between 0 and 1 representing the distance from p1 to p2

 

 

just a bit of math to find the rest:

 

!p1 & p2

xp1 = -5
yp1 = 0
xp2 = 0
yp2 = 5

!distance from p1 to x4  p1 to x1
ratio = .25



x4 = xp1+((xp2-xp1)*(ratio))
y4 = yp1+((yp2-yp1)*(ratio))

x1 = xp1+((xp2-xp1)*(1-ratio))
y1 = yp1+((yp2-yp1)*(1-ratio))


!slope of the line need to find x3 and x2
THETA = atn((yp2-yp1)/(xp2-xp1))

! distance  between x3 and x4
offset = 2

! coordinates of point x3
x3 = x4+ offset *cos(90+THETA)
y3 = y4+  offset *sin(90+THETA)

x2 = x1+ offset *cos(90+THETA)
y2 = y1+  offset *sin(90+THETA)




!draw lines

line2 xp1,yp1,xp2,yp2

line2 x4,y4,x3,y3
line2 x1,y1,x2,y2

line2 x3,y3,x2,y2

Could you please explain the formula to find the ratio in an easy way?

AC27 on window 11
Solution
julienK
Advocate

The ratio is just a value you chose of how far along the line x4 and x1 are.

if you use .5  it will be  in the middle.

 

Copy the full code I posted in a new object 2D script and change to value of ration and offset to see how the 2D view changes.

LeeJaeYoung_0-1664979643118.png

 

!p1 & p2

xp1 = HA
yp1 = B-D2-0.05
xp2 = 0
yp2 = B

!distance from p1 to x4 p1 to x1
ratio = .1
ratio1 = .11

x4 = xp1+((xp2-xp1)*(ratio1))
y4 = yp1+((yp2-yp1)*(ratio1))

x1 = xp1+((xp2-xp1)*(1-ratio))
y1 = yp1+((yp2-yp1)*(1-ratio))


!slope of the line need to find x3 and x2
THETA = atn((yp2-yp1)/(xp2-xp1)) + 180

! distance between x3 and x4
offset = 0.05

! coordinates of point x3
x3 = x4+ offset *cos(90+THETA)
y3 = y4+ offset *sin(90+THETA)

x2 = x1+ offset *cos(90+THETA)
y2 = y1+ offset *sin(90+THETA)

!draw lines
line2 xp1,yp1,xp2,yp2

line2 x4,y4,x3,y3
line2 x1,y1,x2,y2

line2 x3,y3,x2,y2
AC27 on window 11

thank you so much

AC27 on window 11