Author Topic: Bisecting an angle in 3D  (Read 250 times)

Bob P

  • Hero Member
  • *****
  • Posts: 1157
    • Era Replica Automobiles
Bisecting an angle in 3D
« on: September 29, 2016, 05:08:51 AM »
Just thought I'd post this old-ish macro that I use frequently. It bisects an angle with three points.
Point 1 at the vertex
Points 2 and 3 created by snapping to lines in each direction to be bisected.
A plane is created in the bisecting plane, passing through the vertex. (The size of the plane can be modified.  See below.)

Code: [Select]
'This bisects an intersection of two lines with a plane 20X the cursor step
'bis.d3m
SETPOINT "Set a point at the vertex and points on each line: " 3
POINTVAL X Y Z 1
POINTVAL X1 Y1 Z1 2
POINTVAL X2 Y2 Z2 3
SYS(1)=0

'D1=Distance from vertex to first point
D1=((ABS(X1-X))^2+(ABS(Y1-Y))^2+(ABS(Z1-Z))^2)^.5
'D2=Distance from the vertex to the second point
D2=((ABS(X2-X))^2+(ABS(Y2-Y))^2+(ABS(Z2-Z))^2)^.5

'The direction vectors from the origin to the second point are:
DX=(X2-X)/D2
DY=(Y2-Y)/D2
DZ=(Z2-Z)/D2

'The new second point is:
NX=X+DX*D1
NY=Y+DY*D1
NZ=Z+DZ*D1

'Create a line between the new points
>line
{
<POINTXYZ [NX, NY, NZ]
<POINTXYZ [X1, Y1, Z1]
}

'Create a perpendicular plane by setting two points at the midpoint of the line
>PERPENDICULARPLANE
{
'If you want to change the size of the perp plane, change the next line
planesize=1.6*(((x-x1)^2+(y-y1)^2+(z-z1)^2)^.5)
<width [planesize]
<POINTXYZ [(NX+X1)/2, (NY+Y1)/2, (NZ+Z1)/2]
<POINTXYZ [(NX+X1)/2, (NY+Y1)/2, (NZ+Z1)/2]
}

sys(80) = 0
lastm1 = sys(9) - 1 'last minus one, aka 2nd to last

getattr lastm1, type, select
putattr lastm1, type, 1

if sys(80) > 0 then
  >erase
    {
    }
endif
END