News:

Be sure your post is relevant to the current discussion.  Create a new topic within the appropriate board if you are unsure.

Main Menu

Compute the end point of a normal vector for a point on a bent surface

Started by Ruedi, November 24, 2023, 05:03:59 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Ruedi

I'm dealing with the problem to draw the planks of a small boat with lapstrake planking. Lapstrake planking means that the planks overlap each other at the upper and the lower edge of the plank in the longitudinal direction of the hull.
What I have as input are splines showing the inner line of the planks. Each spline can be seen as one of several lateral stations (e.g. 6) within the hull. The edges of the planks are defined by several points (e.g. 10 per side) on the spline.
What I want to have is a drawing showing a cut thru each plank at each station and at both stems. This allows me to draw the outer lines of all stations cut out with CNC, and needed to create a building form needed to build the boat.

I'm able to construct these cuts by using a 2d view of the station splines. But there are two problems with this approach:

1. Time
To draw the cuts there are several steps needed, and they must be repeated for each plank, each station, and each stem. This makes it rather time consumineg - add rather boring as well ;-).

2. Precision
As the planks are bent longitudinally, and the splines of the inner edge of the planks is bent laterally, to be correct the plank cuts should lie on a workplane that is "normal" to the boats surface at every point on the spline. As I draw the cuts on an 2D XY workplane, they are slightly distorted. The distortion is small in the middel of the boat, but become bigger towards its ends.

This leads to the wish, to be able to compute the corner points needed to draw correct plank cuts for each point on the station splines. To be able to make it, I want to create some code to compute a normal vector (means vertical) for each point (vertex) on a spline based on the directions of all edges (depending on the location of the point in the net 2,3, or 4) that meet in this vertex.

I'm aware of the fact that this requires some highly sophisticated/complex mathematics :-).

Has anybody already worked on this? are there any ideas or even code availbale, how it can be done? Every useful idea or help to this is highly appreciated.

The images attached show:
-The boat (drawn with Delftship, 2 images)
-The principle of plank edge overlapping
-The 2 DXF file, exported imported into turboCAD, shown in turboCAD
-Drawing of a two planks cut at a station spline (plank overlap)
-An example of plank overlaps constructed in turboCAD, simple extruded and lofted (3 drawings)

Alvin Gregorio

Quote from: Ruedi on November 24, 2023, 05:03:59 AMIm dealing ...
Henry would have loved this math challenge.

But I'm sure there is a way to just use TurboCAD Tools to extrapolate the information requested.

We'll need you to upload the .dxf and/or .tcw drawing file.  Saving the .tcw file as the earliest version your version-2023 allows opens it up to more TurboCADers to open and offer input.  (such as me; I use v2022_Platinum)
Alvin Gregorio
TurboCAD: v2024_Plat (31.0.77.1); v2022_Plat; v2020_Plat; v2019_DL; v20.2_PP
Lenovo Thinkpad P20Y laptop; Windows 11 Pro; i7-11800H 2.30GHz, 8-core; 32GB RAM; NVIDIA T1200
3D_Printer: Ender-3 S1 (NOT Pro)

nikkipollard

Have you tried recording, making one of these sections with the macro recorder?
Nikki
TC20 platinum, TC 2015 platinum
TC 2017 with lightworks
TC 2021 platinum
Windows 11 Home 22h

Jeff_in_90620

Quote from: Alvin Gregorio on November 24, 2023, 07:11:24 AMWe'll need you to upload the .dxf and/or .tcw drawing file.  Saving the .tcw file as the earliest version your version-2023 allows opens it up to more TurboCADers to open and offer input. 

Saving it as an AutoCAD DWG file in the 2007/2009 format would make it accessible to pretty much any TurboCAD version from 15 (not 2015) forward, if I remember correctly.


Jeff
Jeff

TC 2026 Pro Platinum plus 2015->2024 (most with LightWorks & RedSDK) & V21
System: AMD Ryzen 9 7950X, MSI Mag X670E Tomahawk WiFi, 64GB RAM @ 4.80GHz, ARC A770 w/16GB, 3 x Samsung NVMe 990 (1TB), Windows 11 Pro (64-bit)

nikkipollard

How much Ruby do you know? The problem is I use vbscript not Ruby but they both use the SDK.
I don't use polynomial maths when working with splines in TC. I cheat

The Spline has a polyline in it's Graphic list.
The first thing I do is increase the number of nodes of the polyline using this property
dim spline, pline
Set Spline = ActiveDrawing.Selection(0)
spline.Properties.Item("$SPLINESEGS").Value = 50
Spline.Update

Set pline = Spline.Graphics(1)

Get the vertices of the underlying polyline
dim verts
Set verts = pline.Vertices
Make sure you are using the world coordinates - not the graphics' coordinate system
verts. UseWorldCS = True

Find the normal to the polyline at the relevant points.

If this was a one off I wouldn't write a script. Make a copy of the spline up the number of nodes in the underlying poly line by changing the "number of segments between adjacent point" property and explode the copied spline





Nikki
TC20 platinum, TC 2015 platinum
TC 2017 with lightworks
TC 2021 platinum
Windows 11 Home 22h

nikkipollard

I found this - If you don't want to use the cheat method.
https://pomax.github.io/bezierinfo/

To read the Fit points of the spline (I presume the spline was drawn using fit points)
This seems to be an array of points
'This doesn't work in the macro recorder
  Dim fv As New Object
        gSpline.GetFitPoints(fv)
        Dim num As Integer = UBound(fv)
        For i = 0 To num
            Dim P1 As New IMSIGX.Vertex
            With P1
                .X = fv(i, 0)
                .Y = fv(i, 1)
                .Z = fv(i, 2)
            End With
            MsgBox("(" & P1.X & "," & P1.Y & "," & P1.Z & ")", MsgBoxStyle.SystemModal)
        Next





Sorry This is vb.net code.
Ruby uses IMSIGXMGD as reference, (I prefer IMSIGX.DLL) the name of the function is GetCurveFitPoints .

Nikki
TC20 platinum, TC 2015 platinum
TC 2017 with lightworks
TC 2021 platinum
Windows 11 Home 22h

nikkipollard

I am interested to know if you were able to find a solution to this.
Nikki
TC20 platinum, TC 2015 platinum
TC 2017 with lightworks
TC 2021 platinum
Windows 11 Home 22h

Ruedi

Thank you all. I hadn't the time to have another look onto this so far, sorry ;-).

And yes, I tried to solve it with a macro. Unfortunately I was not able to find out how to use the macro for different Control Points. It works for the starting point on the spline I used to create it only. As there are about 80 other points the target construction must be made for, it does not help.

In Ruby I was unable so far to find out how to iterate over all control points I want to use as base for the calculation/construction. But I do not stick on a certain programing language - I'm open for all that is able to deliver what I need.

So I came to the conlucion that I'll do the construction work manually for each cantrol point of interest. A bit boring, but anyway.

And yes, if there's a more efficient solution with VB or Ruby for thsi problem, this would be highly appreciated. As a professional builder of small boats this design is not the one and only boat I design ...

And no, I haven't found a more efficient way than constructing every single plan/station crossing by hand to get what I needa so far, sigh ...

I'll create and deliver a DWG file soon ...

nikkipollard

Hi Ruedi. I don't know anything about ship building.
I use cad for architectural work so when I work with splines it is usually Draw the spline in CAD, Oh That looks pretty - then program something to follow the path.
It is not really a train smash if the spline is redefined fractionally.


I am aware that your boat boat might sink with my approach - but it is quicker then drawing from scratch.


I have an examples of how I work with splines -in 2d.
These are for 2d splines on the xy plane. But the principles are the same with 3d splines.

Nikki
TC20 platinum, TC 2015 platinum
TC 2017 with lightworks
TC 2021 platinum
Windows 11 Home 22h

Alvin Gregorio

Quote from: Ruedi on November 24, 2023, 05:03:59 AM...
What I want to have is a drawing showing a cut thru each plank at each station and at both stems. This allows me to draw the outer lines of all stations cut out with CNC, and needed to create a building form needed to build the boat.
...
This leads to the wish, to be able to compute the corner points needed to draw correct plank cuts for each point on the station splines. To be able to make it, I want to create some code to compute a normal vector (means vertical) for each point (vertex) on a spline based on the directions of all edges (depending on the location of the point in the net 2,3, or 4) that meet in this vertex.

I'm aware of the fact that this requires some highly sophisticated/complex mathematics :-)
I suspect there is a non-math way that TurboCAD can further aid you in building this boat.

Perhaps you can continue this discussion in the "General Discussion" board, reference (link) to this thread, and restate you ultimate objective.
If you do so, please include the 2D DXF export file from Delftship.

Alvin Gregorio
TurboCAD: v2024_Plat (31.0.77.1); v2022_Plat; v2020_Plat; v2019_DL; v20.2_PP
Lenovo Thinkpad P20Y laptop; Windows 11 Pro; i7-11800H 2.30GHz, 8-core; 32GB RAM; NVIDIA T1200
3D_Printer: Ender-3 S1 (NOT Pro)

Ruedi

Dear Nikki,
thank you for your quick and useful answer.

I'll have alook onto your code (thank you for this too), and I'll give it a try.

I have two questions:

-the width of the planks on a lapstrake hull - means vertically overlapping planks - is not the same for all ten planks. Their overall width is not the same. This is true too for each single plank. Its width differs longitudinally. This means it has different widths at different stations (see yz views). This must be made to get a "harmonic" view of the hull in the end.
Is your code made to handle these differences of plank widths?

-the planks are bent longitudinally (see xy view). This means that the cut trough a plank has a different angle of the y axis at each station. To get a correct cut, one must adjust the workplane for each plank/station crossing accordingly.
Is your code made to handle these differences of plank angles?

As English is a foreign language for me, I'm probably not precise/understandable enough. If this shuold be the case, I'm sorry. Please let me know. Thank you.

Ruedi

Yes, I did. I'm not yet very familar with macros, but I think I must have kind of an interactive macro to be able to run the sequence of geometric construction steps needed to draw a correct plank cut for each of my plank/station crossings. Each such crosing has its own set of points and a different angle of the y-axis - this means a dfferent work plane - as well.

Can this be done with a macro?
If yes, how? 

nikkipollard

Quote from: Alvin Gregorio on December 07, 2023, 04:33:10 AM
Quote from: Ruedi on November 24, 2023, 05:03:59 AM...
What I want to have is a drawing showing a cut thru each plank at each station and at both stems. This allows me to draw the outer lines of all stations cut out with CNC, and needed to create a building form needed to build the boat.
...
This leads to the wish, to be able to compute the corner points needed to draw correct plank cuts for each point on the station splines. To be able to make it, I want to create some code to compute a normal vector (means vertical) for each point (vertex) on a spline based on the directions of all edges (depending on the location of the point in the net 2,3, or 4) that meet in this vertex.

I'm aware of the fact that this requires some highly sophisticated/complex mathematics :-)
I suspect there is a non-math way that TurboCAD can further aid you in building this boat.

Perhaps you can continue this discussion in the "General Discussion" board, reference (link) to this thread, and restate you ultimate objective.
If you do so, please include the 2D DXF export file from Delftship.



That would be ideal. It is not the drawing of the ship that is the problem, it is the automation of the process that Ruedi is after.
Nikki
TC20 platinum, TC 2015 platinum
TC 2017 with lightworks
TC 2021 platinum
Windows 11 Home 22h

nikkipollard

Quote from: Ruedi on December 07, 2023, 04:51:13 AMDear Nikki,
thank you for your quick and useful answer.

I'll have alook onto your code (thank you for this too), and I'll give it a try.

I have two questions:

-the width of the planks on a lapstrake hull - means vertically overlapping planks - is not the same for all ten planks. Their overall width is not the same. This is true too for each single plank. Its width differs longitudinally. This means it has different widths at different stations (see yz views). This must be made to get a "harmonic" view of the hull in the end.
Is your code made to handle these differences of plank widths?

-the planks are bent longitudinally (see xy view). This means that the cut trough a plank has a different angle of the y axis at each station. To get a correct cut, one must adjust the workplane for each plank/station crossing accordingly.
Is your code made to handle these differences of plank angles?

As English is a foreign language for me, I'm probably not precise/understandable enough. If this shuold be the case, I'm sorry. Please let me know. Thank you.

Hi Ruedi,
My example isn't the whole solution to your problem, it just shows how I work with splines.
The first solution I showed was with equal distances. So I used a block.
Once I had a solution I realised that your loft would be wavy because the y(z in your case) wouldn't be equal. So the second solution divides the spline at fixed distances vertically.

I worked with splines on the world plane - because most of the maths functions I have are 2d.
So what I normally do is move and rotate the coordinates of the vertices of the splines' polyline so that they are on the world plane. Draw the profiles and then move and rotate the graphics back to the correct position.

My script is for 1 selected spline. You can iterate through all the Graphics in the current selection.  Selected graphics are in the order that they were drawn - So as long as they were drawn in sequence you should be fine.



 
Nikki
TC20 platinum, TC 2015 platinum
TC 2017 with lightworks
TC 2021 platinum
Windows 11 Home 22h

Ruedi

Dear Nikki,

thank you very much for your kind help. All of it is highly appreciated.

All the best, a very nice day, and kind regards,

Ruedi

nikkipollard

It is a pleasure. and Your English is fine.
The other question you had was finding the normal to the spline.
This is pretty easy.

The SDKs Graphic object has a method called GetDistance
This finds the shortest distance from a coordinate to the Graphic.
As a bonus, there is an option to get the point on the graphic.
Calculate angle between the 2 coordinates to find the normal.

Something like this




Dim PI
Dim Dist, norm

gSpline.GetDistance(Pa.x,Pa.y,Pa.z,PI)
norm = GetAngle(PI,Pa)


The only thing is the test point can't lie on the spline
Nikki
TC20 platinum, TC 2015 platinum
TC 2017 with lightworks
TC 2021 platinum
Windows 11 Home 22h

Ruedi

Nikki,
thank you.

I'm thinking ...

And here's another attempt to define what I mean. The attached files shows what's the base for the calculation of the normal vectors (of a certain lenght) END coordinates XYZ.

The result is used as a base to be able to draw a correct cut through the planks.

The starting point for the calculation of the normal vector is the vertex where lap edge(s) meet each other / or alone at a station or a stem respectively - the points marked with a star in the drawings. 

The angle of the normal vector starting at this vertex is determined by the splines meeting at its start vertex. The adjacent splines can be seen as straight lines - boat building has way more dimensions tolerance than rocket science :).

The end point of the normal vector defines the coordinates I'm looking for.
 

All the best, and kind regards,
Ruedi

Alvin Gregorio

Quote from: Ruedi on December 08, 2023, 01:09:03 PMNikki,
...
Ruedi-- May we ask of you that you share here the .dxf which you exported from Delftship.
Alvin Gregorio
TurboCAD: v2024_Plat (31.0.77.1); v2022_Plat; v2020_Plat; v2019_DL; v20.2_PP
Lenovo Thinkpad P20Y laptop; Windows 11 Pro; i7-11800H 2.30GHz, 8-core; 32GB RAM; NVIDIA T1200
3D_Printer: Ender-3 S1 (NOT Pro)

Ruedi

Alvin,
yes, of course.

Remark
Please be aware of the fact that this is a sample only. It shows the basic principle I'm talking about. And as such it is enough to develop the calculations needed to get the corner points of each plank including the rabbet in it at its lower end at all stations.

Please take into account too, that the problem has nothing to do with a certain software used to design or to construct a boat. This is only a tool to support the development process.
And, in my humble opinion, and as always, knowledge, expertise and common sense is not built in and delivered with any tool ;-).

But back to seriosity:

The dxf exported from delftship shows the crease edges at the inner side of the planks. This is all that can be created with Delftship (and, as far as I know, most of the few other serious hull design programs as well). It migh be that a highly sophisticated (and very expensive) hull design software offers the functions needed to construct the correct form of lapstrake planks, but I simply do not know.

Besides this the problem and its solution is not bound to a certain CAD software. The calculations to define the coordinates to draw the plank cuts - including the rabbets at their lower edge - trough the planks at all stations can be made "offline" on the base of a simple 3d net.

The base for the calculations needed for is a 3d net built from several surfaces with four corner points (usually the left half of the symmetric hull).

The coordinates of all corner points are known. The number of edges a certain corner point connects differs, based on its location within the net. Because of this the calculations needed differ depending on the "corner-type".

And just to say:
A full/real design looks a bit different. In it the plank's widths differ from plank to plank, and the width of each single plank changes over its entire lenght as well. This is made to get a "harmonic" view of the whole hull. And this is the art of elegant hull design.     

But the principle remains the same.

If I'm wrong, please tell me.

Ruedi

and this is the target ...

The drawing shows the top plank only as completed. All subsequent planks must have the rabbet as shown at the lower edge of the top plank. The rabbet is rectangular, and it has the same size along the whole plank. The gaps between adjacent planks are filled with epoxy during the build process. This creates the stiffness needed for a hull that is built with (relatively thin) lightweight planks.

nikkipollard

So it looks like you are working with, Line segments - not splines.
Nikki
TC20 platinum, TC 2015 platinum
TC 2017 with lightworks
TC 2021 platinum
Windows 11 Home 22h

Ruedi

Nikki,
yes, I fully agree. Delftship export delivers splines (e.g. for stations). For geometrical construction I connect the control points on a spline with straight lines. This reduces complexity and is by far precise enough to draw plank cuts, plank overlaps, and plank cutouts.

So calculating the points neede for drawing a plank cut with a simple straight polyline connecting these points by straight lines is by far precise enough too.

Alvin Gregorio

Nikki-- Are you clear on exactly what Ruedi's objective is?  And why just using TurboCAD's regular tools won't suffice to create 2D entities to send to the CNC to cut the plywood(?) to be the stations templates?

I'm not
Alvin Gregorio
TurboCAD: v2024_Plat (31.0.77.1); v2022_Plat; v2020_Plat; v2019_DL; v20.2_PP
Lenovo Thinkpad P20Y laptop; Windows 11 Pro; i7-11800H 2.30GHz, 8-core; 32GB RAM; NVIDIA T1200
3D_Printer: Ender-3 S1 (NOT Pro)

Alvin Gregorio

#23
Quote from: Ruedi on December 10, 2023, 02:19:27 AM overlap calculation sample 3d.dxf
85.57 KB
Does TC_Coordinate_Palette supply what Ruedi is after?

In the files below, the one with .csv near the end, delete the .xlsx after downloading.


3.0000;0.0000;0.0792;Start/End curve point
3.0000;0.0250;0.1367;Start/End curve point
3.0000;0.0250;0.1367;Start/End curve point
3.0000;0.2058;0.1762;Start/End curve point
3.0000;0.2058;0.1762;Start/End curve point
3.0000;0.3701;0.2464;Start/End curve point
3.0000;0.3701;0.2464;Start/End curve point
3.0000;0.5190;0.3397;Start/End curve point
3.0000;0.5190;0.3397;Start/End curve point
3.0000;0.6653;0.4546;Start/End curve point
3.0000;0.6653;0.4546;Start/End curve point
3.0000;0.7714;0.5894;Start/End curve point
3.0000;0.7714;0.5894;Start/End curve point
3.0000;0.8669;0.7607;Start/End curve point
3.6000;0.0000;0.1105;Start/End curve point
3.6000;0.0180;0.1750;Start/End curve point
3.6000;0.0180;0.1750;Start/End curve point
3.6000;0.1686;0.2104;Start/End curve point
3.6000;0.1686;0.2104;Start/End curve point
3.6000;0.3082;0.2994;Start/End curve point
3.6000;0.3082;0.2994;Start/End curve point
3.6000;0.4324;0.3975;Start/End curve point
3.6000;0.4324;0.3975;Start/End curve point
3.6000;0.5539;0.5165;Start/End curve point
3.6000;0.5539;0.5165;Start/End curve point
3.6000;0.6508;0.6522;Start/End curve point
3.6000;0.6508;0.6522;Start/End curve point
3.6000;0.7331;0.8219;Start/End curve point
4.2000;0.0000;0.2321;Start/End curve point
4.2000;0.0224;0.2992;Start/End curve point
4.2000;0.0224;0.2992;Start/End curve point
4.2000;0.0493;0.3059;Start/End curve point
4.2000;0.0493;0.3059;Start/End curve point
4.2000;0.1537;0.4051;Start/End curve point
4.2000;0.1537;0.4051;Start/End curve point
4.2000;0.2398;0.5007;Start/End curve point
4.2000;0.2398;0.5007;Start/End curve point
4.2000;0.3287;0.6212;Start/End curve point
4.2000;0.3287;0.6212;Start/End curve point
4.2000;0.4101;0.7542;Start/End curve point
4.2000;0.4101;0.7542;Start/End curve point
4.2000;0.4764;0.9124;Start/End curve point
2.7360;0.2139;0.1666;Start/End point of polyline
3.8543;0.0121;0.1983;Start/End point of polyline
4.8726;0.0000;1.0977;Start/End point of polyline
2.7858;0.8003;0.5713;Start/End point of polyline
2.7778;0.9017;0.7421;Start/End point of polyline
2.7858;0.8003;0.5713;Start/End point of polyline
4.0218;0.0148;0.2282;Start/End point of polyline
2.7990;0.6892;0.4381;Start/End point of polyline
2.7360;0.2139;0.1666;Start/End point of polyline
2.9321;0.0250;0.1343;Start/End point of polyline
2.7615;0.5396;0.3224;Start/End point of polyline
2.7666;0.3832;0.2306;Start/End point of polyline
4.2596;0.0250;0.3229;Start/End point of polyline
2.6662;0.0250;0.1255;Start/End point of polyline
3.2989;0.0250;0.1475;Start/End point of polyline
4.0270;0.0000;0.1550;Start/End point of polyline
4.4930;0.0250;0.4903;Start/End point of polyline
2.5612;0.0000;0.0639;Start/End point of polyline
4.8415;0.0250;1.0446;Start/End point of polyline
4.8726;0.0000;1.0977;Start/End point of polyline
4.6170;0.0250;0.6080;Start/End point of polyline
4.7350;0.0250;0.7559;Start/End point of polyline
2.7990;0.6892;0.4381;Start/End point of polyline
4.8295;0.0250;0.9063;Start/End point of polyline
4.8415;0.0250;1.0446;Start/End point of polyline
4.9080;0.0250;1.0510;Start/End point of polyline
4.8415;0.0000;1.0446;Start/End point of polyline
4.9080;0.0250;1.0510;Start/End point of polyline
2.7615;0.5396;0.3224;Start/End point of polyline
4.9080;0.0250;1.0510;Start/End point of polyline
2.6662;0.0250;0.1255;Start/End point of polyline
4.9080;0.0000;1.0510;Start/End point of polyline
2.7666;0.3832;0.2306;Start/End point of polyline

Alvin Gregorio
TurboCAD: v2024_Plat (31.0.77.1); v2022_Plat; v2020_Plat; v2019_DL; v20.2_PP
Lenovo Thinkpad P20Y laptop; Windows 11 Pro; i7-11800H 2.30GHz, 8-core; 32GB RAM; NVIDIA T1200
3D_Printer: Ender-3 S1 (NOT Pro)

Ruedi

Alvin,
I know how to create a dxf file from proper 2d drawings that can be used to create the machine program for cnc cutting. This is not what I'm looking for.

What I want to have now and first of all, this means before doing this, is a correct 3d drawing that shows the planks, their overlaps, and the stations needed to build the hull as well.

As the discussion here has helped me a lot - I highly appreciate the help of anybody here - to clarify the problem and potential solutions for it for myself, I think I know eonugh now to develop a program that is able to compute all the control points I need "offline" to be able to import all "corner points" needed in e.g. turbocad to draw what I want to have. It's way more easy to do this outside of any drawing program, and to import the result afterwards into one, than trying to use a plugin opprotunity (e.e. the Ruby-Console in turboCAD).

This process will allow me to create then the drawing I mentioned above with a CAD program.


Preparing CNC cutting:

This is not a aprt of my problem. I know how to do it.

The stations are rather simple 3d structures, that can easily be transferred into 2d drawings as the base for a DXF to be used to create the CNC cutter code.

 
The planks are a bit more complex. They must be unfold to 2d - but I will find out how to do this too.



Last but nor least:
Many thanks for all your contributions so far. They are highly appreciated.