<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://communities.bentley.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Find intersection point of a line passing through a plane</title><link>https://communities.bentley.com/products/programming/microstation_programming/f/bdn-vba/117011/find-intersection-point-of-a-line-passing-through-a-plane</link><description>I would like to get the intersection point of a 3D line which passes through a plane using MicrostationVBA (Microstation Version : 08.05.01.25 Windows x86). 
 Attached image for reference. I want to obtain the point(3D) at which the line (green line element</description><dc:language>en-US</dc:language><generator>Telligent Community 12</generator><item><title>RE: Find intersection point of a line passing through a plane</title><link>https://communities.bentley.com/thread/364825?ContentTypeID=1</link><pubDate>Thu, 21 Apr 2016 10:38:20 GMT</pubDate><guid isPermaLink="false">6dad98f5-dbc9-4c4d-a9ba-e9da8dc6aa8e:b7a95626-711b-44f1-b5b3-a9f8d695210f</guid><dc:creator>Jan Šlegr</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;[quote user=&amp;quot;Dharma Rajan&amp;quot;]Is this may be the problem due to dgn file or something else?[/quote]&lt;/p&gt;
&lt;p&gt;Frankly, I am not sure why you are asking again if I provided my guess earlier already. The proven fact is that MDL function for area properties (mdlMeasure_areaProperties) provides different results than VBA IsPlanar method. In such situtaion, why do you want to discuss if it&amp;#39;s cause by dgn if two functions provide two different results?&lt;/p&gt;
&lt;p&gt;In my opinion the reason is MDL function is more strict and exact than IsPlanar, so in some tolerance VBA tells it&amp;#39;s &amp;quot;enough planar&amp;quot; but if MDL is used, the same element &amp;quot;is not enough planar&amp;quot;. The interpretation of the situation is up to you, you can e.g. take MDL as correct one, so consequently the problem is in DGN file, because the shape is not planar. Or you can say there is the bug in VBA API, because it tells the element is planar which is not.&lt;/p&gt;
&lt;p&gt;But there is closely related question what does it mean &amp;quot;to be planar&amp;quot;? To define the planarity is not big problem, also to implement own planarity test is not huge task, but to make precision decision (because calculation using decimal floating point is never precise) is not easy and is very implementation and situation dependent.&lt;/p&gt;
&lt;p&gt;In my opinion, because your original question was how to calculate shape / line intersection, is to use MDL for the planarity test and if it fails, to planarize the shape yourself, regardless VBA tells it&amp;#39;s planar already.&lt;/p&gt;
&lt;p&gt;With regards,&lt;/p&gt;
&lt;p&gt;&amp;nbsp; Jan&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Find intersection point of a line passing through a plane</title><link>https://communities.bentley.com/thread/364810?ContentTypeID=1</link><pubDate>Thu, 21 Apr 2016 09:27:05 GMT</pubDate><guid isPermaLink="false">6dad98f5-dbc9-4c4d-a9ba-e9da8dc6aa8e:1e344b91-2f01-45e1-b789-36a8413f5a0d</guid><dc:creator>Dharma Rajan</dc:creator><description>&lt;pre class="brush: applescript; fontsize: 100; first-line: 1; "&gt;Hi Jan&lt;/pre&gt;
&lt;p style="margin-left:30px;text-align:left;"&gt;I have attached a zip file with two dgn files &amp;#39;PlanarCheck_Dgn1.dgn&amp;#39; and &amp;#39;PlanarCheck_Dgn2.dgn&amp;#39;.&lt;/p&gt;
&lt;p style="margin-left:30px;text-align:left;"&gt;Both dgns contain same element (shape element). While testing the planarity property of the element using VBA in both dgns, we get different results between the two dgns. Is this may be the problem due to dgn file or something else? Kindly present your views on this.&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;The VBA Code block that I used to test planarity is given below.&lt;/p&gt;
&lt;p&gt;&lt;a href="https://communities.bentley.com/cfs-file/__key/communityserver-discussions-components-files/53220/PlanarityCheckDGNs.zip"&gt;communities.bentley.com/.../PlanarityCheckDGNs.zip&lt;/a&gt;&lt;/p&gt;
&lt;pre class="brush: applescript; fontsize: 100; first-line: 1; "&gt;Public Sub checkPlanarity()
    Dim elmEnum As ElementEnumerator
    Dim elm As Element
    Set elmEnum = ActiveModelReference.GetSelectedElements
    elmEnum.MoveNext
    Set elm = elmEnum.Current
    If elm.AsShapeElement.IsPlanar Then
        MsgBox &amp;quot;Planar&amp;quot;, vbInformation
    Else
        MsgBox &amp;quot;Non-Planar&amp;quot;, vbCritical
    End If
End Sub
&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Find intersection point of a line passing through a plane</title><link>https://communities.bentley.com/thread/362191?ContentTypeID=1</link><pubDate>Sat, 02 Apr 2016 12:05:10 GMT</pubDate><guid isPermaLink="false">6dad98f5-dbc9-4c4d-a9ba-e9da8dc6aa8e:ec47976c-df39-4441-bc19-3556e21745f5</guid><dc:creator>Jan Šlegr</dc:creator><description>&lt;p&gt;That&amp;#39;s both weird and interesting. I assume a math behind the area calculation and VBA planarity test is different, so this particular shape is &amp;quot;enough planar&amp;quot; for VBA, but not &amp;quot;enough planar&amp;quot; for area calculation.&lt;/p&gt;
&lt;p&gt;[quote user=&amp;quot;Dharma Rajan&amp;quot;]Is there any other alternative to confirm the planarity...[/quote]&lt;/p&gt;
&lt;p&gt;I tried to find some method/function in both VBA and MDL API and it seems there is no other direct method. But it&amp;#39;s possible to implement own one using area measurement MDL function, which as a side effect provides information about a shape planarity:&lt;/p&gt;
&lt;pre class="brush: vb; fontsize: 100; first-line: 1; "&gt;Declare Function mdlMeasure_areaProperties Lib &amp;quot;stdmdlbltin.dll&amp;quot; (ByRef perimeterP As Double, _
    ByRef areaP As Double, ByRef normalP As Point3d, ByRef centroidP As Point3d, _
    ByRef momentP As Point3d, ByRef iXYP As Double, ByRef iXZP As Double, _
    ByRef iYZP As Double, ByRef principalMomentsP As Point3d, _
    ByRef principalDirectionsP As Point3d, ByVal edP As Long, _
    ByVal tolerance As Double) As Long

Private Function IsShapePlanar(shape As ShapeElement) As Boolean
    
    Dim result As Long
    
    Dim perimeterP As Double, areaP As Double
    Dim normalP As Point3d, centroidP As Point3d, momentP As Point3d
    Dim iXYP As Double, iXZP As Double, iYZP As Double
    Dim principalMomentsP As Point3d, principalDirectionsP As Point3d
   
    result = mdlMeasure_areaProperties(perimeterP, areaP, normalP, centroidP, momentP, _
            iXYP, iXZP, iYZP, principalMomentsP, principalDirectionsP, shape.MdlElementDescrP, 0)
    
    If (result = -754) Then
        IsShapePlanar = False
    Else
        IsShapePlanar = True
    End If
    
End Function&lt;/pre&gt;
&lt;p&gt;I am not sure if it&amp;#39;s correct solution, but it works fine with your &amp;quot;maybe planar shape&amp;quot; (ID 202151) as it tells it&amp;#39;s not planar, while VBA tells it&amp;#39;s planar.&lt;/p&gt;
&lt;p&gt;With regards,&lt;/p&gt;
&lt;p&gt;&amp;nbsp;Jan&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Find intersection point of a line passing through a plane</title><link>https://communities.bentley.com/thread/362095?ContentTypeID=1</link><pubDate>Fri, 01 Apr 2016 08:32:22 GMT</pubDate><guid isPermaLink="false">6dad98f5-dbc9-4c4d-a9ba-e9da8dc6aa8e:c8a9a73d-ceb2-4e80-a034-5c01c9d74139</guid><dc:creator>Dharma Rajan</dc:creator><description>&lt;p&gt;&lt;a href="https://communities.bentley.com/cfs-file/__key/communityserver-discussions-components-files/53220/test_5F00_RayplaneIntersec_5F00_2.dgn"&gt;communities.bentley.com/.../test_5F00_RayplaneIntersec_5F00_2.dgn&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Hi Jan,&lt;/p&gt;
&lt;p&gt;In the attached dgn, there is a shape element. While checking its planarity manually, it also displayed&amp;nbsp;as &amp;quot;Non co-planar shapes&amp;quot; in Element information dialog as you said. But while checking using &amp;quot;IsPlanar&amp;quot;, I find the element as planar and Plane3dIntersectsRay3d works in this case. Is there any other alternative to confirm the planarity manually since &amp;quot;Non co-planar shapes&amp;quot; in Element information dialog is not helping to arrive at a conclusion?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Find intersection point of a line passing through a plane</title><link>https://communities.bentley.com/thread/361905?ContentTypeID=1</link><pubDate>Thu, 31 Mar 2016 06:37:24 GMT</pubDate><guid isPermaLink="false">6dad98f5-dbc9-4c4d-a9ba-e9da8dc6aa8e:e453e5f4-eaa6-4ff5-8c36-7ad346debcc7</guid><dc:creator>Jan Šlegr</dc:creator><description>Hi Dharma,&lt;br /&gt;
&lt;br /&gt;
element id 349743 is not planar (in Element information dialog an area is displayed as &amp;quot;Non co-planar shapes&amp;quot;), so the element is not valid for intersection calculation.&lt;br /&gt;
&lt;br /&gt;
In my opinion the code is fine, because based on test If shp.IsPlanar Then... the intersection calculation is skipped.&lt;br /&gt;
&lt;br /&gt;
With regards,&lt;br /&gt;
&lt;br /&gt;
  Jan&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Find intersection point of a line passing through a plane</title><link>https://communities.bentley.com/thread/361903?ContentTypeID=1</link><pubDate>Thu, 31 Mar 2016 06:18:08 GMT</pubDate><guid isPermaLink="false">6dad98f5-dbc9-4c4d-a9ba-e9da8dc6aa8e:3ac09075-dbc6-4fd5-b620-343707ba2670</guid><dc:creator>Dharma Rajan</dc:creator><description>&lt;p&gt;Plane3dIntersectsRay3d method fails for a particular element. How to fix this issue?&lt;/p&gt;
&lt;p&gt;Sample code is given below and the Sample DGN is also attached.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;pre class="brush: applescript; fontsize: 100; first-line: 1; "&gt;Option Explicit

Public Sub testPlaneIntersectRay()
    Dim shp As ShapeElement
    Dim lin As LineElement
    Dim plane As Plane3d
    Dim rayA As Ray3d
    Dim interPt As Point3d
    Dim param As Double
    
    Set shp = ActiveModelReference.GetElementByID(DLongFromLong(349743))
    Set lin = ActiveModelReference.GetElementByID(DLongFromLong(349761))
    
    If shp.IsPlanar Then
        plane.Normal = shp.Normal
        plane.Origin = shp.Vertex(1)
    
    
        rayA.Origin = lin.StartPoint
        rayA.Direction = Point3dSubtract(lin.EndPoint, lin.StartPoint)

        If Plane3dIntersectsRay3d(interPt, param, plane, rayA) Then
            Debug.Print interPt.X &amp;amp; &amp;quot;,&amp;quot; &amp;amp; interPt.Y &amp;amp; &amp;quot;,&amp;quot; &amp;amp; interPt.Z
        Else
            MsgBox &amp;quot;Intersection fails.&amp;quot;
        End If
    End If
End Sub
&lt;/pre&gt;
&lt;p&gt;&lt;a href="https://communities.bentley.com/cfs-file/__key/communityserver-discussions-components-files/53220/Test_5F00_Plane3dIntersectsRay3d.dgn"&gt;communities.bentley.com/.../Test_5F00_Plane3dIntersectsRay3d.dgn&lt;/a&gt;&lt;/p&gt;
&lt;pre class="brush: applescript; fontsize: 100; first-line: 1; "&gt;&lt;/pre&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Find intersection point of a line passing through a plane</title><link>https://communities.bentley.com/thread/359915?ContentTypeID=1</link><pubDate>Tue, 15 Mar 2016 11:20:17 GMT</pubDate><guid isPermaLink="false">6dad98f5-dbc9-4c4d-a9ba-e9da8dc6aa8e:9ab6ec8a-37a7-49d0-a68d-50538ca4b08a</guid><dc:creator>Dharma Rajan</dc:creator><description>Thanks Jan!&lt;br /&gt;
It worked.&lt;br /&gt;
&lt;br /&gt;
The shape element is indeed a planar one and using Plane3dIntersectsRay3d, I could get its intersection point with the line.&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Find intersection point of a line passing through a plane</title><link>https://communities.bentley.com/thread/359864?ContentTypeID=1</link><pubDate>Tue, 15 Mar 2016 05:52:24 GMT</pubDate><guid isPermaLink="false">6dad98f5-dbc9-4c4d-a9ba-e9da8dc6aa8e:7844ad6a-66a3-4eb2-98b8-0ce71370d895</guid><dc:creator>Jan Šlegr</dc:creator><description>Hi,&lt;br /&gt;
&lt;br /&gt;
I guess you can use Plane3dIntersectsRay3d method to calcualte the intersection point between a plane and line segment. You have to check if the shape element IsPlanar and if this condition is accomplished, it&amp;#39;s possible to create Plane3d element from Shape.&lt;br /&gt;
&lt;br /&gt;
If your shape is not planar, your question cannot be answered, because there is no exact definition what is inside the non planar shape element.&lt;br /&gt;
&lt;br /&gt;
With regards,&lt;br /&gt;
&lt;br /&gt;
  Jan&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>