Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Math “expert” wanted… Algorithm for finding line of two crossing areas

Math “expert” wanted… Algorithm for finding line of two crossing areas

Scheduled Pinned Locked Moved C / C++ / MFC
c++algorithmstutorial
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    anderslundsgard
    wrote on last edited by
    #1

    I’m going to create a shape-class containing a lot of flat polygon areas. I will make it possible to subtract one shape from another and then I need an algorithm to se if two polygon-areas in the 3D-space crosses each other, and if in which line the crossing is. I see there should bee some kind of linear algebra calculations but I do not really know how to start constructing my c++ shape classes. :doh: _____________________________ ...and justice for all APe

    V 1 Reply Last reply
    0
    • A anderslundsgard

      I’m going to create a shape-class containing a lot of flat polygon areas. I will make it possible to subtract one shape from another and then I need an algorithm to se if two polygon-areas in the 3D-space crosses each other, and if in which line the crossing is. I see there should bee some kind of linear algebra calculations but I do not really know how to start constructing my c++ shape classes. :doh: _____________________________ ...and justice for all APe

      V Offline
      V Offline
      vmaltsev
      wrote on last edited by
      #2

      Well, hail there again. Why don't you stick to one thread? Anyway, you sholdn't be a math "expert" to solve this one, but you have to know basics of geometry at least. I'll give you solution for intersection bitween line and plane, the rest you can do yourself. We have three points and a normal vector (N). The equation of a plane is Ax+By+Cz+D=0. We have two points P1 and P2. The equation of a line is P(t)=P1+t*Pd where Pd=(P2-P1), t>0. To determine if there is an intersection with the plane, substitute for P(t) into the plane equation and get A(P1x+t*Pdx)+B(P1y+t*Pdy)+C(P1z+t*Pdz)+D=0, which yields t = -(Dot(N,P1)+D)/Dot(N,Pd). Now find divisor Vd=Dot(N, Pd), if Vd=0 then the line is parallel to the plane and if Vd>0 then the normal N of the plane is pointing away from the ray (that can be useful for one-sided faces). Now we can find t, if t<0 then the line intersects the plane behind origin, i.e. no intersection of interest, otherwise we can put t in the equation of a line to find intersection point. Enjoy.

      A 1 Reply Last reply
      0
      • V vmaltsev

        Well, hail there again. Why don't you stick to one thread? Anyway, you sholdn't be a math "expert" to solve this one, but you have to know basics of geometry at least. I'll give you solution for intersection bitween line and plane, the rest you can do yourself. We have three points and a normal vector (N). The equation of a plane is Ax+By+Cz+D=0. We have two points P1 and P2. The equation of a line is P(t)=P1+t*Pd where Pd=(P2-P1), t>0. To determine if there is an intersection with the plane, substitute for P(t) into the plane equation and get A(P1x+t*Pdx)+B(P1y+t*Pdy)+C(P1z+t*Pdz)+D=0, which yields t = -(Dot(N,P1)+D)/Dot(N,Pd). Now find divisor Vd=Dot(N, Pd), if Vd=0 then the line is parallel to the plane and if Vd>0 then the normal N of the plane is pointing away from the ray (that can be useful for one-sided faces). Now we can find t, if t<0 then the line intersects the plane behind origin, i.e. no intersection of interest, otherwise we can put t in the equation of a line to find intersection point. Enjoy.

        A Offline
        A Offline
        anderslundsgard
        wrote on last edited by
        #3

        va`Lery wrote: Why don't you stick to one thread? Well no excuses. I Rebuilded the question… I’m not bad at either math or c++ but it’s the thing hat implement the algostuff into code that, for me is difficult. Small problems with both of them (math and c++) makes things hard for me. Thanks _____________________________ ...and justice for all APe

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups