CadQuery / CadQuery/cadquery

Cutting a Cylinder with a line (intersect)

Open
#1,334 3 comments 0 reactions 0 assignees View on GitHub
question
Dominant language
Python
Stars
5.8k
Forks
541
Avg merge
3d 2h
Merged PRs (30d)
5

Description

Hi everyone,

i am trying to change an existing script that calculates a quite complex geometry based on a FREECAD hook in python to use the cadquery package.

The biggest difference i saw was the information saved in the variables.
E.g. when i try to get information of my object i allways have to use functions and can't just use obj.BoundBox.

**My Problem:**
I am trying to intersect a line with a cylinder and get the start and end point of the intersection-line aswell as its length.
In my FREECAD python script version it was programmed as follows:

```
total_length=0
length=[]
for i in range(0,len(struts)):
line=Part.makeLine((struts[i][0],struts[i][1],struts[i][2]),(struts[i][3], struts[i][4], struts[i][5])) #create a FreeCAD Line
cut_line = cylinder.common(line) #cut with the cylinder to remove excess

if len(cut_line.Vertexes)==2:
# this saves the start and end point of the line which was cut by the cylinder
struts[i] = [cut_line.Vertexes[0].Point[0],cut_line.Vertexes[0].Point[1],cut_line.Vertexes[0].Point[2],cut_line.Vertexes[1].Point[0],cut_line.Vertexes[1].Point[1],cut_line.Vertexes[1].Point[2]]

length.append(cut_line.Length) #create vector with length of the lines
total_length+=cut_line.Length #add all these lengths
del line
del cut_line
```

I cannot find any functions to achieve the same with cadquery.

Thanks for your help!

Best regards,

Mischa

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.