Stretch by a direction and distance

Started by Bob P, May 26, 2012, 09:45:38 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Bob P

This is an augmentation of my previous point-move-by-distance macro.
With this macro, you can do the equivalent of 4-point-stretch, but it asks for 2 points to define the direction and an actual distance along that direction.


'vstr.d3m
' Move a selected section a given distance defined by a direction and distance.
' Note that if you enter a positive distance value, the section
' will stretch from the first _toward_ the second point.  Use a negative number
' to stretch the section away from the first point.

' point 1 and 2 define the section to be stretched..
' point 3 and 4 define the direction that the point will be moved.
' a positive length draws line from point 1 in direction of point 2
' a negative length draws line in opposite direction

' created for dc version 14 and up

precision 15

setpoint "Select the section to be stretched" 2
pointval x1s y1s z1s 1
pointval x2s y2s z2s 2
sys(1)=0

setpoint "set line points: 1)Base point, 2) Direction ", 2
Input "How far from first point (toward the second point?" dist

pointval x1 y1 z1 1
pointval x2 y2 z2 2

sys(1)=0
dx = x2 - x1  'dx, dy, and dz are the direction vectors of the move
dy = y2 - y1
dz = z2 - z1
d = sqrt(dx^2 + dy^2 + dz^2)  'd=the numerical length of the stretch

if d = 0 then 'Check that the points aren't coincident (set on top of each other).
message "error: 1st and 2nd points are identical, unable to determine unit direction vector."
end
end if

'The original positions plus the unit vector dx, dy, and dz distances
di=x1+((dx/d)*dist)
dj=y1+((dy/d)*dist)
dk=z1+((dz/d)*dist)

>stretch
{
<pointxyz [x1s, y1s, z1s]
<pointxyz [x2s, y2s, z2s]
<pointxyz [x1, y1, z1]  'original point
<pointxyz [di, dj, dk]  'new location
}

end

bdeck

Hi BobP,

Congrats on a very terse macro.  ;D

BD

prl


Bob P

It obviously need a leetle work.  ;)

My copy and paste was more like a copy and "pas".

The original post is fixed now, I hope.