Skip to content

Commit e81228d

Browse files
committed
Added cq.Vector.projectToLine() for projecting a Vector to a line represented by another Vector
1 parent 8fccc0c commit e81228d

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

cadquery/occ_impl/geom.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,18 @@ def getAngle(self, v: "Vector") -> float:
175175
def distanceToLine(self):
176176
raise NotImplementedError("Have not needed this yet, but OCCT supports it!")
177177

178-
def projectToLine(self):
179-
raise NotImplementedError("Have not needed this yet, but OCCT supports it!")
178+
def projectToLine(self, line: "Vector") -> "Vector":
179+
"""
180+
Returns a new vector equal to the projection of this Vector onto the line
181+
represented by Vector <line>
182+
183+
:param args: Vector
184+
185+
Returns the projected vector.
186+
"""
187+
lineLength = line.Length
188+
189+
return line * (self.dot(line) / (lineLength * lineLength))
180190

181191
def distanceToPlane(self):
182192
raise NotImplementedError("Have not needed this yet, but OCCT supports it!")

0 commit comments

Comments
 (0)