-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow user to define a vector for the extrusion direction #81
Comments
Hi @gonuke thanks for the suggestion. It makes a lot of sense and would be a nice upgrade. This is not exactly what you asked for but perhaps of interest import paramak
test_shape = paramak.SweepStraightShape(
points=[(-10, 10), (10, 10), (10, -10), (-10, -10)],
path_points=[(50, 0), (50, 150)]
)
test_shape.show() I'm going to dig into the CadQuery documentation a bit and see what can be done to enhance the extrude shapes and see if how to go about accepting a unit vector |
Will the working plane of the shape be rotated to be normal to this path? |
Unfortunately not. |
I think I would need to add some new args based on the cadquery vector class https://cadquery.readthedocs.io/en/latest/classreference.html#cadquery.Vector |
That may be one approach, but someone on my team was already doing some rotation math to work around thus by calculating the rotation operations to convert from one of those convenient forms to the rotation system already supported |
Interesting, @RemDelaporteMathurin will be interested in that, he made a point rotation function and recently raised an issue requested rotation methods |
@shimwell @gonuke this is indeed a feature that - i think - is not yet implemented in the Paramak. I think this behaviour could be obtained with sweep shapes but that's maybe using a sledgehammer to beat a fly. Cadquery natively provides a method to achieve this. The class |
Not exactly. The parametric shapes are either extruded or rotated. The first step is to give a bunch of points describing a 2D shape (eg the black square I draw above). This 2D shape is then extruded or rotated around a rotation axis (according to The |
This seems to do the job. I shall integrate it asap in a new PR. from paramak import ExtrudeMixedShape, Shape
from paramak.utils import calculate_wedge_cut
from cadquery import Vector, Solid
class ExtrudeMixedShapeBis(ExtrudeMixedShape):
def __init__(self, extrusion_vector='ortho', **kwargs):
super().__init__(**kwargs)
self.extrusion_vector = extrusion_vector
def create_solid(self):
"""Creates an extruded 3d solid using points connected with straight
and spline edges.
Returns:
A CadQuery solid: A 3D solid volume
"""
workplane = Shape.create_solid(self)
if not self.extrude_both:
extrusion_distance = -self.distance
else:
extrusion_distance = -self.distance / 2.0
wire = workplane.close()
self.wire = wire
if type(self.extrusion_vector) is str and self.extrusion_vector == 'ortho':
solid = wire.extrude(
distance=extrusion_distance,
both=self.extrude_both)
else:
wireSets = [list(wire.ctx.pendingWires)]
solid = Solid.extrudeLinear(
outerWire=wireSets[0][0],
innerWires=[],
vecNormal=self.extrusion_vector,
taper=0
)
# filleting rectangular port cutter edges
# must be done before azimuthal placement
if hasattr(self, "add_fillet"):
solid = self.add_fillet(solid)
solid = self.rotate_solid(solid)
cutting_wedge = calculate_wedge_cut(self)
solid = self.perform_boolean_operations(solid, wedge_cut=cutting_wedge)
self.solid = solid
return solid
points = [
(0, 0, "straight"),
(1, 0, "straight"),
(1, 1, "straight"),
(0, 1, "straight"),
]
my_shape = ExtrudeMixedShapeBis(points=points, distance=1, extrusion_vector=Vector((1, 1, 1))) #
my_shape.export_stl('out.stl') |
@gonuke pytransform3d may help. Check pytransform3d's documentation. As mentioned in it's README.md, you can easily extract the relevant code for your purpose. |
@gonuke I think I've now understood what you wanted to do: extrude a 2D shape in the workplane normal direction but define the workplane from a normal vector. Can you please confirm? If so, I've managed to achieve this with minimal changes to the code. In red below is the rotated_solid with extrusion direction (1, 1, 1). Code: import paramak
from cadquery import Plane
points = [
(0, 0),
(1, 0),
(1, 1),
(0, 1)
]
shape_1 = paramak.ExtrudeStraightShape(points=points, distance=1)
normal_vec = (1, 1, 1)
shape_2 = paramak.ExtrudeStraightShape(
points=points, distance=1,
workplane=Plane(origin=(0, 0, 0), xDir=(-1, 1, 0), normal=normal_vec),
rotation_axis=[(0, 0, 0), normal_vec])
shape_1.export_stl('non_rotated.stl')
shape_2.export_stl('rotated.stl') |
solved in PR #84 |
As far as I can tell, the extruded shapes are all derived from
Shape
and extruded in a direction normal to theworkplane
and then rotated according to the definition of therotation_axis
and theazimuth_placement_angle
.However, a user frequently knows the unit vector along which they want the extrusion to occur, so it would be convenient if the various extruded shape classes could automatically calculate the
rotation_axis
andazumuth_placement_angle
from that unit vector and the originalworkplane
normal. Perhaps this is howpath_workplane
should work (?) but I can't find much documentation on that.Even better would be a way to define this data in a number of ways:
The text was updated successfully, but these errors were encountered: