2024 Technology Preview Program:
Master powerful new features and shape the latest BIM-enabled innovations
2022-10-04 04:04 PM - edited 2022-10-04 04:42 PM
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.
Solved! Go to Solution.
2022-10-05 02:20 PM - edited 2022-10-05 02:42 PM
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
2022-10-05 03:57 PM
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.
2022-10-04 05:34 PM - edited 2022-10-04 05:35 PM
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
2022-10-04 06:09 PM
It means using ADD2 and ROT2 to handle it.
thank you ^^
2022-10-05 02:20 PM - edited 2022-10-05 02:42 PM
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
2022-10-05 03:16 PM
Could you please explain the formula to find the ratio in an easy way?
2022-10-05 03:57 PM
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.
2022-10-05 04:21 PM - last edited on 2022-10-06 01:30 AM by Laszlo Nagy
!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
2022-10-05 04:42 PM
thank you so much