Generating wires from an imported float array. #35
-
Hi Jimy/community Firstly, thanks for your work on pymadcad! Secondly, I'm quite a novice with python but have exhausted google/stack-exchange so I hope you'll forgive me if this is a trivial problem: I have a list of 3d points that I'm pulling from a csv and parsing into a 3n float array using numpy. Could you give me some guidance on how best to achieve the points-to-wire conversion? I assume there's some way of forming a points buffer to use in generating the wire but I can find any examples where the points are imported from an external source (apart from meshes). Many thanks. |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 8 replies
-
Welcome there @tim-rastall-reveal ! Step by stepI will suppose that you have an array of sourcepoints = np.empty((n,3), dtype='f8')
# if it's comming in a different number type, do the following
sourcepoints = mysource.astype('f8') Once you have it, you can cast it into an array of points = typedlist(sourcepoints, dtype=vec3) Note that creating a Then you can simply build a mywire = wire(points) In shortSo more directly you can do mywire = wire(typedlist(sourcepoints.astype('f8', copy=False), dtype=vec3)) Then you can generate surfaces from it # for instance
mysurface = extrusion(vec3(1,2,3), mywire) |
Beta Was this translation helpful? Give feedback.
-
Hi again Jimy Firstly, that hint for using 'Wire' instead of 'wire' worked perfectly and I've now been able to move on to building some geometry. My next challenge is to create blended surfaces between 2 wires: To achieve this, I've been using the 'blendpair' function on 2 wires as follows: blendpair(wireA,wireB, match='length', tangents='straight') This yields some interesting results where I blend a series of pairs of 12-sided Ngons and 4 sided rectangles as you can see in the image below - the sections are appended into a single mesh that then has end-caps added to form a manifold surface. I initially thought this issue was a result of the 'handedness' of the vertex order in the wires being inverted but when I checked, everything is right-hand-rule, so in the case of the series of 12 sided Ngons that make up the first 4 sections (from the top) of the mesh shown in the image below, the vertex order and handedness is consistent - with vert index0 on the first wire being directly above vert index0 on the wire below it and so on. In the case of the 12 sided ngons in the object shown below, the vertices between wires are being linked as follows 0-0, 1-11, 2-10, 3-9, 4-8, 5-7, 6-6 etc I had assumed that setting the 'match' parameter value to 'closest' would fix this but unfortunately, an error is returned from blending.py as follows:
Any thoughts? It feels like it could be a bug but equally, I could be miss-understanding something. I've also attached a csv with the coordinate strings for the object shown in the image below. I hope this makes sense and thanks for your continued support! Tim |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
Welcome there @tim-rastall-reveal !
Thanks for your thanks ;)
A question is only trivial when you already know the answer
Step by step
I will suppose that you have an array of
float64
, else you should first convert it.Once you have it, you can cast it into an array of
vec3
, so madcad will know that it is points, not just a matrix. That operation won't copy anything, this is just a type reinterpretation.Note that creating a
typedlist
in that way doesn't check for the input type, so it can be error-prone…