Intersection Ray/Plane

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
arch_studentin
Posts: 10
Joined: Mon Jan 06, 2020 1:43 pm

Intersection Ray/Plane

Post by arch_studentin »

Hey,

I am trying to find a python script to help me do the following:

I have a FreeCad line/ray from which i know the starting point and the direction where it points in degrees. Additionally, I have a wall (from an architectural project). So the line represents the viewing direction from a camera, with which I took a photo.

I would like to find a script that prints out the point, where the line meets the wall.
Does someone maybe have any idea on how to do that? Code examples are greatly appreciated, since i am very new to all this.

Thanks a lot!
mario52
Veteran
Posts: 4698
Joined: Wed May 16, 2012 2:13 pm

Re: Intersection Ray/Plane

Post by mario52 »

hi

try Macro_WorkFeatures Points > Point 1/3 > Point=(Line,Face)

or this script (the line should touch the face(s))

Code: Select all

#!/usr/bin/env python
# -*- coding: utf-8 -*-

# example for intersection of shape(Solid) & line(Edge)
# Usage: select a line and a solid, then run this macro
# http://www.forum.freecadweb.org/viewtopic.php?f=22&t=5456

import FreeCAD
import Part

s = FreeCADGui.Selection.getSelection()
if len(s) < 2:
    print( "not enough objects selected - ", len(s))
else:
    try:
        s1 = s[0].Shape
        s2 = s[1].Shape       
      
        cs = s1.common(s2)
        if cs.Vertexes:
            for v in cs.Vertexes:
                point = App.ActiveDocument.addObject("Part::Vertex","Vertex")
                point.Placement=Base.Placement(Base.Vector(v.Point),Base.Rotation(0.0000,0.0000,0.0000,1.0000))
                print( "intersection point : ", v.Point)
    except Exception:
        print( "can't find an intersection point")

mario
Maybe you need a special feature, go into Macros_recipes and Code_snippets, Topological_data_scripting.
My macros on Gist.github here complete macros Wiki and forum.
arch_studentin
Posts: 10
Joined: Mon Jan 06, 2020 1:43 pm

Re: Intersection Ray/Plane

Post by arch_studentin »

hi, thanks for the tips! Unfortunetly, even though i have a line and a plane crossing in one point, the script always says "can't find an intersection point". So that couldnt help.
I searched a lot and couldnt really find a helpful script. So that makes me think is there not an easy way to do that? In my project it should work without finding the points by hands, that is what my professor wants.

Anyone any other ideas? Thanks
mario52
Veteran
Posts: 4698
Joined: Wed May 16, 2012 2:13 pm

Re: Intersection Ray/Plane

Post by mario52 »

hi

give an example file with your objects for testing

mario
Maybe you need a special feature, go into Macros_recipes and Code_snippets, Topological_data_scripting.
My macros on Gist.github here complete macros Wiki and forum.
arch_studentin
Posts: 10
Joined: Mon Jan 06, 2020 1:43 pm

Re: Intersection Ray/Plane

Post by arch_studentin »

FreeCAD0.19SampleFile.FCStd
Sample File
(411.79 KiB) Downloaded 19 times
Ok so here is the sample file.
Basically i made a macro that shows the camera direction and then creates a wall where i can put the image as a texture. (25@001.01.Teil2.FCMacro)
Sorry, i experiment a lot xD
The orange line in the middle passes through the wall, thats where i want to know at which exact point that happens.
Thanks a lot
mario52
Veteran
Posts: 4698
Joined: Wed May 16, 2012 2:13 pm

Re: Intersection Ray/Plane

Post by mario52 »

hi

try this i adding "from FreeCAD import Base"

Code: Select all

#!/usr/bin/env python
# -*- coding: utf-8 -*-

# example for intersection of shape(Solid) & line(Edge)
# Usage: select a line and a solid, then run this macro
# http://www.forum.freecadweb.org/viewtopic.php?f=22&t=5456

import FreeCAD
import Part
from FreeCAD import Base

s = FreeCADGui.Selection.getSelection()
if len(s) < 2:
    print( "not enough objects selected - ", len(s))
else:
    try:
        s1 = s[0].Shape
        s2 = s[1].Shape       
        
        cs = s1.common(s2)
        if cs.Vertexes:
            for v in cs.Vertexes:
                point = App.ActiveDocument.addObject("Part::Vertex","Vertex")
                point.Placement=Base.Placement(Base.Vector(v.Point),Base.Rotation(0.0000,0.0000,0.0000,1.0000))
                print( "intersection point : ", v.Point)
    except Exception:
        print( "can't find an intersection point")
ps:do you want to change the macro name and supp @ (mozilla open the my hotmail)

mario
Maybe you need a special feature, go into Macros_recipes and Code_snippets, Topological_data_scripting.
My macros on Gist.github here complete macros Wiki and forum.
arch_studentin
Posts: 10
Joined: Mon Jan 06, 2020 1:43 pm

Re: Intersection Ray/Plane

Post by arch_studentin »

hi,

mario you are a genius, thank you so much, now it works :D you dont even know how much i appreciate your help :) that will help my project a lot! Much love
Post Reply