DesignCAD 3D Max 2027 box
Now available

DesignCAD 2027

Hatches that follow their boundaries, an on-screen dial to turn your model, and a way to find any command by name, in a clean Windows 11 look.

Command to draw a line from a point above a plane to the closest point on an ind

Started by prl, January 23, 2013, 12:14:28 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

prl

QuoteF-148   Command to draw a line from a point above a plane to the closest point on an indicated plane; the resulting line MUST be perpendicular to the (extended) plane.   (Dr PR)   OUTSTANDING   
http://forum.designcad.com/index.php?topic=2453.0

I was combing through Dempsey's list and saw this.  This has been solved with BasicCAD.



'Program: pv2p.d3m  (perpendicular vector to plane)

'12/9/2012  prl
'draw a normal (perpendicular) vector from a point not on the plane to three points defining a plane

SetPoint "Set three points for the plane, 4th point for point not on the plane", 4
if Sys(1) < 4 Then end

Pointval x1 y1 z1, 1
Pointval x2 y2 z2, 2
Pointval x3 y3 z3, 3
Pointval x4 y4 z4, 4
sys(1)=0

'normal vector 
a = y1*(z2 - z3) + y2*(z3 - z1) + y3*(z1 - z2)
b = z1*(x2 - x3) + z2*(x3 - x1) + z3*(x1 - x2)
c = x1*(y2 - y3) + x2*(y3 - y1) + x3*(y1 - y2)

'equation for plane variable d
d = a*x1+b*y1+c*z1

denom = sqrt(a*a + b*b + c*c)

'unit normal
au = a/denom
bu = b/denom
cu = c/denom

'distance 4th point to plane
mag = -(a*x4+b*y4+c*z4- d)/denom

if mag = 0 then
   Message "point is coplanar"
   sys(1)=0
   End
endif

'intersection point of normal to plane
xi = x4+mag*au
yi = y4+mag*bu
zi = z4+mag*cu

'draw the normal line from the 4th point to the plane intersection
>line
  {
  <pointxyz [x4, y4, z4]
  <pointxyz [xi, yi, zi]
  }
 
end

minstrel

Thanks prl,

...another big  ;D comes to the surface!  ...and another 'tool' added to the chest!

Minstrel

Dr PR

prl,

Thanks. Not only is this a very useful addition, it is also a road map for the programmers to add the function as a built-in command.

The main problem with macros is that they cannot be used within a command the way native point positioning functions can be. However, we can use this macro to set a point and draw a temporary line, then gravity snap to the end of the line, and that will be a great improvement!

Phil
DesignCAD user since 1987

Lar

When saving Prl's macro I came across this macro. It asks you to set 3 points to define the plane and the length of the line then it draws a line of that length at the first point you set (actually it draws the line at 000 then moves it to the plane so that is is perpendicular). The direction it points depends on the direction of the 3 points set. I have no idea who wrote it but I suspect it's Prl, based on the word "Program:" in the first line (normally I put the author's name in the filename when I download macros but I didn't do it with this one). The saved date is 26 Feb, 2003.


'Program: pl2p.d3m (perp line to plane)
'turns off ortho and angle constraint modes during macro

Dim X(3), Y(3), Z(3)

fixedstate = sys(152)
sys(152)=1 'change to fixed state

'save status of ortho and angle constraint modes
omode=sys(347)
acmode=sys(1024)

'turn off ortho and angle constraint modes
sys(347)=0
sys(1024 )= 0

user:
SetPoint "Set 3 points to define plane: " 3
If Sys(1) < 3 Then goto user

For i = 1 To 3
PointVal X(i) Y(i) Z(i) i
Next i
Sys(1) = 0


precision 15
'get input, use string input format so user can enter feet and inches if desired
input "enter magnitude (length) of the line: ", rz$
r=val(rz$)

if r = 0 then
message "error: no line length input provided."
end
end if

sys(80)=0

'draw a line at 0,0,0 of specified length
>line
{
<Pointxyz [0, 0, 0]
<Pointxyz [0, r, 0]
}

'select the line just drawn
getattr sys(9), type, select
putattr sys(9), type, 1

>SetHandle
{
<Pointxyz [0, 0, 0]
<Pointxyz [1, 0, 0]
<Pointxyz [0, 0, 1]
}

>move
{
<Pointxyz [X(1), Y(1), Z(1)]
<Pointxyz [X(2), Y(2), Z(2)]
<Pointxyz [X(3), Y(3), Z(3)]
}

sys(1)=0
sys(152)= fixedstate 'restore to initial setting

'reset ortho and angle constraint modes
sys(347)=omode
sys(1024)=acmode

>SelectPrevious
{
}

End

prl

Quote from: Lar on January 24, 2013, 07:23:59 PM
but I suspect it's Prl, based on the word "Program:" in the first line (normally I put the author's name in the filename when I download macros but I didn't do it with this one). The saved date is 26 Feb, 2003.

I'm getting old.  I wrote it and looks like you improved it.  The version at the top of the post is straight vector math, the  pl2p.d3m version does it with handle transformations.  DesignCAD is so wonderfully flexible.

Plus just yesterday I was hunting for something in the macros.hlp file and this caught my eye.  I'll need to experiment and see if this flag works.  I think Mark and Phil having been asking for this in order to snap points during a DesignCAD command.

Quote1032 - Plane Snap mode [0 or 1] (R/W) (V. 13)
This function controls the behavior of the Plane Snap command. When set to zero, the plane snap command snaps to the nearest point in the mathematical plane occupied by the nearest surface (but that point may not actually be on the surface).  When set to one, the plane snap command behaves normally, and always snaps to the nearest point on the nearest surface (default).

Edit:  I tried the above and it isn't as useful as I thought.

Mark, Phil, you can experiment with the flag by pressing the space bar and typing:  sys(1032)=0
To return you machine to normal mode, space bar and type: sys(1032)=1

Bob P

prl,

Great catch.  Too bad there's no documentation in the manual about that option, nor any reference to it in the Options window.  For me, snap-to-a-virtual-plane is more useful than the default behavior.

Dr PR

prl,

Good catch. Now if we could just get this implemented as an option in the Plane Snap command ...

Phil
DesignCAD user since 1987