The subject says it all, I have a sketch and need a vector normal-to. I searched and didn't get much.
Thanks
How to get a vector normal to a Sketch?
Re: How to get a vector normal to a Sketch?
Code: Select all
sketch = App.ActiveDocument.Sketch
plm = sketch.Placement
vec = App.Vector(0,0,1)
plm.Rotation.multVec(vec)
Re: How to get a vector normal to a Sketch?
don't really know, but could be as simple as
at least that works for the one case I tested with just a sketch.
if you have nested placements, attachments - suppose that has to be un-nested as well before one arrives at the "global" normal
theoretically, if your matrix is
the normal should be
no harm in reducing the 4x4 to a 3x3 first...
btw, believe the matrix here is a fc-implemented one, so for convenience it really ought to have a .normal() method imho.
Code: Select all
sketch.Placement.Matrix.col(2)
if you have nested placements, attachments - suppose that has to be un-nested as well before one arrives at the "global" normal
theoretically, if your matrix is
Code: Select all
[[r1],
[r2],
[r3},
[r4]]
Code: Select all
[[r2 x r3],
[r3 x r1],
[r1 x r2]]
btw, believe the matrix here is a fc-implemented one, so for convenience it really ought to have a .normal() method imho.
Re: How to get a vector normal to a Sketch?
Thanks wmayer, I always forget that.
I wanted it in Global coords. Changed this:
plm = sketch.Placement
to
plm = sketch.getGlobalPlacement()
I wanted it in Global coords. Changed this:
plm = sketch.Placement
to
plm = sketch.getGlobalPlacement()
That would be good. I will verify "sketch.Placement.Matrix.col(2)" to the multVec approach. Thank youbtw, believe the matrix here is a fc-implemented one, so for convenience it really ought to have a .normal() method imho.
Re: How to get a vector normal to a Sketch?
I learned from someone else
- normal = Sketch.getGlobalPlacement().Rotation.multVec(FreeCAD.Vector(0,0,1))
Wondering what is different if it is
- normal = Sketch.Placement().Rotation.multVec(FreeCAD.Vector(0,0,1))
?
Thanks
- normal = Sketch.getGlobalPlacement().Rotation.multVec(FreeCAD.Vector(0,0,1))
Wondering what is different if it is
- normal = Sketch.Placement().Rotation.multVec(FreeCAD.Vector(0,0,1))
?
Thanks
Re: How to get a vector normal to a Sketch?
This is just the local (0,0,0,1)normal = Sketch.Placement.Rotation.multVec(FreeCAD.Vector(0,0,1))
Below I did a test; #1) I took a sketch and created an offset (normal) version, then took the difference between the two as a vector. #2) used the standard multVec. I suppose the difference could be a problem if I was plotting a path to Mars

Code: Select all
sketchgplbase = sketch.getGlobalPlacement().Base
sketch2 = sketch
sketch2.AttachmentOffset.Base.z += 5
sketch2gplbase = sketch2.getGlobalPlacement().Base
direction = sketch2gplbase - sketchgplbase
direction.normalize()
print("1",direction)
print("2",sketch.getGlobalPlacement().Rotation.multVec(FreeCAD.Vector(0,0,1)))
1 Vector (0.02497325279932969, -0.007005166641426478, 0.9996635755517687)
2 Vector (0.024973252799321794, -0.007005166641426546, 0.9996635755517689)