News:

Please note new Forum URL: forum.designcad.com

Main Menu
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.

Perpendicular From a Line

Started by Pearlitic, March 01, 2015, 10:01:19 AM

Previous topic - Next topic

0 Members and 0 Guests are viewing this topic.

Pearlitic

Thanks for your help on the midpoint equation. 
Once I found the midpoint I discovered that the second point of the cylinder is the radius.  The function "perpendicular from a line" works great in my test when I am drawing a line, but I need to use that for the second point of a cylinder. 

I've looked this up on the internet, but I can't wrap my head around the change from simple XY to XYZ. 

prl

#1
What are you trying to do?   Draw a solid cylinder between two points of a line segment?   Create a small sample drawing manually of what you are trying to achieve and attach the *.dcd to your response.  I'm assuming this is related to your 50 frequency quarter globe construction.

Pearlitic

Yes, I am trying to draw a cylinder in space.  I like that the radius is set when using the "perpendicular from a line".  If I shoot a line through the midpoint, I will get a different radius unless I compensate for it by using SSS to calculate the new angle.

Thanks for your help.

Pearlitic


prl

#4
Quote from: Pearlitic on March 01, 2015, 11:53:46 AM
Here is a better example.

Looked at your drawing.   I see lots of midpoint pointmarks and blue and black lines.  Obviously you want to have DesignCAD cycle the drawing, read the line data, compute a midpoint and draw a cylinder from someplace to someplace.  It is the last part I don't get.  Define your points or define the cylinders using a different color line for now.  That way I'll understand where you want the 3d cylinders. 

You may also want to look at a macro I wrote many years ago called cyl2.d3m to create cylinder solids along two points,  see http://forum.designcad.com/index.php?topic=4533.msg27417#msg27417.   (I called my version cal.d3m, Cylinder Along Line, but BobP amended the code to ask some questions regarding radius and facet count, etc.  Nice improvement.)

Also the reason for me asking you to draw the cylinder lines in yellow (for example), one could write some code where basiccad cycles the drawing database, reads the ends points of only yellows lines, and replaces them with solid cylinders between those points.  That code I have floating around somewhere. 

Pearlitic

Here is a sample of what I am trying to do.  Obviously all of the struts will eventually be cylindrical.  Each strut will be split in half.   Before I am finished, I will have to recalculate the end points to get rid of the dihedral gaps and I will likely change the cylinders into a combination of tubes and cylinders and then join them.   My end objective is to create an SLA of a tool that will make parts (the cylindrical) hubs.

I really appreciate your taking your time to investigate this.   

Pearlitic :)

prl

Quote from: Pearlitic on March 01, 2015, 02:44:36 PM
I really appreciate your taking your time to investigate this.   

Thanks.  So getting back to your 50 Frequency quarter.dcd file, in that file you have many planes (shading your drawing).  Are the planes a triangular tubular assembly? In other words, do the perimeter points of those shaded DesignCAD planes define a steel triangle tubular assembly?

Pearlitic

I have created a program that lets me create multi-frequency octahedrals.   I can create 0-100 frequency octahedrals with it.

A 2 frequency octahedral is an octahedral where the strut (edges) have been bisected and the midpoint is moved an equal distance to the endpoints of the octahedral.  Creating the octahedral is relatively easy and is explained by Hugh Kenner in "Geodesic Math and how to use it".

The three current inputs for the program are the frequency,  the radius of the octahedral and the cylinder radius.

The planes in the previous example (50 frequency) will be replaced by the tubular design.  The planes are mainly for reference now. 

I originally wanted to use the midpoint as my first point for the cylinder and then increasing the length of the ray for the next point.  The problem with this is that it yields an inconsistent cylinder diameter.

Cleanest would be if I could set the end of the segment point, then perpendicular from that line the second point (with the cylinder radius)  and then finally the set the midpoint.

Alternatively it would work if I could do the midpoint of the strut and then perpendicular from that line (with the cylinder radius) and then finally set the end segment point.

If I have to use calculate the length of the line perpendicular to the endpoint or midpoint, I will have to calculate the angles of these all the new triangles to compensate for the variance.

Thanks,

Pearlitic



prl

#8
Here is a routine, ca2p.d3m, that will do what you need.  This version is user interactive, so you feed it two points in 3d space and it will do the rest.  (If you are mathematically computing points, eliminate the user input portion and simply feed it the 3d points.)

Also made a video showing it in action on your sample file.  In the movie I'm gravity snapping to the points you created.

A movie - ca2p.d3m demo of creating a cylinder defined by 2 points in 3d space

'Program: ca2p.d3m (cylinder along two points)

'3/1/2015 forum topic http://forum.designcad.com/index.php?topic=6125.0

precision 15

curstate = sys(242)

'default data
rad = 1.5 'radius for cylinder, change this as desired
facet = 12 'facet count for cylinder, change this as desired

here:
setpoint "Point 1 for cylinder beginning, point 2 for cylinder end, press enter to END looping" 2
if sys(1) = 0 then goto Finish

sys(36)=2
pointval x1, y1, z1, 2
pointval x2, y2, z2, 1
sys(1)=0

'compute length in 3d spsace
dx = x2 - x1
dy = y2 - y1
dz = z2 - z1
d =  dx * dx + dy * dy + dz * dz

if d = 0 then
  message "error: 1st and 2nd points are identical, unable to determine unit direction vector."
  end
end if

rlength = sqrt(d)

'now draw a vertical cylinder at the ORIGIN, then matrix move it, the cylinder construction is easier at the origin
sys(242) = 1 'select object when created ON
>Cylinder
  {
  <Orientation 0
  <Nface [facet]
  <pointxyz [0, 0, 0]
  <pointxyz [rad, 0, 0]
  <pointxyz [0, rlength, 0]
  }

'set handles and move to proper location in 3d space
>sethandle
  {
  <type 0
  <Pointxyz [0, 0, 0]
  <pointxyz [0, rlength, 0]
  }
 
>move
  {
  <Reference 0
  <Type 1
  <Pointxyz [x1,y1,z1]
  <Pointxyz [x2,y2,z2]
  }
sys(80)=0   
sys(36)=0
regen
goto here

Finish:
sys(242) = curstate   
regen

End

Pearlitic

Wow!  I am impressed.  I watched the video and think that I can make this work.  I'll study it tomorrow night and try it out.

Thanks Again.

Pearlitic.