Bentley Communities
Bentley Communities
  • Site
  • User
  • Site
  • Search
  • User
  • Welcome
  • Products
  • Support
  • About
  • More
  • Cancel
MicroStation
  • Product Communities
  • More
MicroStation
MicroStation Wiki Introducing Segment3D Methods In MicroStation V8 2004 Edition
    • Sign in

    • +MicroStation Wiki
    • +Administration Wiki
    • +Annotations Wiki
    • +Bentley View Wiki
    • +MicroStation PowerDraft
    • -Programming Wiki
      • A class to help create and modify text element
      • A Complete Example
      • A MicroStation VBA Example With Bentley ProjectWise
      • AddIn Development Using VB.NET
      • C# .NET Template with IPrimitiveCommandEvents Class
      • Capturing Graphics in Dynamic Views
      • Compiling MDL Applications
      • Database Manipulation
      • Debugging Native Code MDL Applications
      • Developing Code in VBA
      • Developing MicroStation Applications For DWG Files
      • Drag and Drop in MicroStation
      • Error: "Cannot save changes to VBA project 'Support' because it is read-only"
      • Getting And Setting Elements Using Graphic Groups In VBA [CS]
      • Getting Started with Visual Basic
      • How To Write A Recursive Routine In MicroStation VBA [CS]
      • Introducing Segment3D Methods In MicroStation V8 2004 Edition
      • Known issues in MDL and MicroStationAPI
      • Launching VBA Applications As Initapps Or Dgnapps [CS]
      • Learning MicroStation Addins Step by Step
      • MDL - Getting Started With XAttributes In MicroStation V8 XM Edition
      • MDL - Native Code Application Development
      • MDL Or MicroStation BASIC Choosing The Right Tool [TN]
      • MFC Dialog And Native Window Support
      • Microsoft Office VBA Patch Utility
      • MicroStation BASIC FAQ
      • MicroStation BASIC Limits [FAQ]
      • MicroStation Developer Documentation and Example Code
      • MicroStation Programming Advice
      • MicroStation SDK
      • MicroStation V8 Programming Tools Readme
      • MicroStation V8 VBA Programming Resources [CS]
      • MicroStation V8 XM Edition View Code Updates
      • MicroStation VBA Resources Revisited [CS]
      • Migrating Dimension Code To MicroStation V8
      • Migrating MDL Applications To Native Code
      • Mouse Wheel Events And The Visual Basic 6.0 IDE
      • Porting MDL Applications To MicroStation V8
      • Reading Elements From A Microsoft Access Database With VBA [CS]
      • Running MDL Applications
      • Scanning For MicroStation V8 Elements In VBA [CS]
      • Unleash A Workspace Wizard Automating Workspace Creation With MicroStation V8 And VBA [CS]
      • Using VBA To Detect The Current Or Last Used Command
      • Using VBA To Programmatically Export A VBA Project [CS]
      • Using VBA To Programmatically Import A VBA Projects Components And References [CS]
      • VBA -- Creating A Complex Application
      • VBA Interface Error: failed creating the comp manager - 0x80040583
      • VBA interface error: unable to get IDE
      • vba recording
      • Working With Levels In MicroStation VBA [CS]
      • Writing An MDL Application To Output Custom Placemarks To Google Earth
      • [V8i C++] PointCloud IPointCloudChannelDisplayHandler
    • +Visualization Wiki

     
     Questions about this article, topic, or product? Click here. 

    Introducing Segment3D Methods In MicroStation V8 2004 Edition


     

    This Client Server article is republished in its entirety from 2004 for reference purposes.

    By Yuedong Bi, Developer Support Analyst, Bentley Corporate Office
    28 June 2004

    http://selectservices.bentley.com/files/clientserver/downloads/segment3D.zip

    In the Microstation 2004 Edition VBA Help (which can be found from Start > Programs > MicroStation > Documentation > Microstation VBA), you will find a brief introduction to the product's new features (Figure 1).

    There are 14 new Segment3d members. This article will introduce most of them.


    Figure 1: MVBA Help
    The Segment3d type definition can be found in MVBA help. It represents a line segment in a three-dimensional space. It has these members:

    Name

    Description

    StartPoint

    A Point3d value that represents the start of the segment.

    EndPoint

    A Point3d value that represents the end of the segment.

     

    The StartPoint/EndPoint values are measured in the model's coordinate system. When you have placed a Segment3d in 3D space, you may have some questions, such as:

    • How do I create a segment?
    • Is a Segment3d a kind of line element?
    • How do I find the relationships between two segments, such as intersect or parallel?
    • If it intersects, where is the intersection? If parallel, what is the offset?
    • How to find the closest point on a segment from a point in 3D space?

    How do I create a Segment?

    There are five Segment3d methods that can be used to create Segment3d objects:

    • Segment3dFromPoint3dStartEnd
    • Segment3dFromXYZXYZStartEnd
    • Segment3dFromPoint3dStartTangent
    • Segment3dFromRay3d
    • Segment3dFromTransform3dTimesSegment3d

    Example: Suppose there is a cube in 3D space (Figure 2). pointA to pointN are defined as the Point3d type. segmentAB, segmentBC etc., are defined as the Segment3d type.

    Dim pointA as Point3d

    pointA.X=0

    pointA.Y=0

    pointA.Z=0

    Dim segmentAB as Segment3d



    Figure 2: 3D cube
    segmentAB can be created by:

    segmentAB = Segment3dFromXYZXYZStartEnd(0, 0, 0, 0, 10, 0)

    or

    segmentAB = Segment3dFromPoint3dStartEnd(pointA, pointB)

    or

    segmentAB = Segment3dFromPoint3dStartTangent(pointA, tangentAB)

    Where tangentAB is a Point3d type, it is the extent from start point A.

    The value is (0, 10, 0).

    Q: To create segmentME with start point M(20,10,10), what is the tangent?

    A: It should be (-10, -10, -10). This is the vector from the start point to the end point. Segment3dFromRay3d () is demonstrated in the attached example code.

    Q: Are segmentAB and segmentBA same?

    A: No. According to definition, they are different. Their start and end points are stored in reverse order, and fractional coordinates (from 0 to 1) advance in opposing directions on segments with exchanged start and end points.

    Is a Segment3d a kind of line element?

    A Segment3d is a type in MVBA, not a MicroStation Element. You can map it to a line element, and you can translate them back and forth through vertices.

    For example:

    To create a line element from segmentAB in Microstation VBA:

    Dim LineElement as LineElement

    Set LineElement = CreateLineElement2 _

    (Nothing, segmentAB .StartPoint, segmentAB.EndPoint)

    To create a mySegment from a line element:

    Dim mySegment as Segment3d

    mySegment = Segment3dFromPoint3dStartEnd(myLine.startPoint, _

    myLine.endPoint)

    How do I find the relationships between two segments, such as intersect or parallel?

    The reason we create a Segment3d type is to allow the user to find the relationships between points, line segments, and planes.

    The Segment3dSegment3dIntersectXY method computes a point closest to a space point, and on an unbounded line, using only xy coordinates in projection calculation. This is the point at which the two segments appear to cross each other when viewed while looking directly at the xy plane. Because the two segments may be at different depths when they appear to cross, the method returns two intersection points: one is the point on the first segment, and the other is the point on the second segment. The xy parts of the two points will be identical, but the z parts may be different.

    The Segment3dPlane3dIntersect method computes the intersection of an unbounded segment and a plane. It returns "true" if there is an intersection point, or else "false" if a segment is parallel, or coincident to the plane.

    There is an output parameter fraction; this is the fractional position of the intersection point along a Segment. Fractional positions 0, ½ and 1 are (respectively) the start, midpoint, and endpoint. Fractional positions less than 0 are "before" the start, and fractional positions larger than 1 are "beyond" the endpoint.

    For example: In Figure 3, suppose segment AB and CD intersect at point E. The fraction for segment AB will be length(AE)/length(AB). The fraction for segment CD will be length(CE)/length(CD).


    Figure 3: Fraction Demo
    In Figure 2, we know the intersection of segmentAD and segmentDG is point D,

    So, the fraction for AD will be 1. For DG, it will be 0.

    To verify this, run:

    status = Segment3dSegment3dIntersectXY(segmentAD, segmentDG, point0, _

    fraction0, point1, fraction1)

    You will get point0 = point1 = (10, 0, 10), fraction0=1, fraction1=0.

    The detail is documented in the MVBA Help.

    The Segment3dSegment3dClosestApproach method will compute the closest approach of two lines in 3D, considering both lines unbounded. It returns false if parallel or coincident, otherwise it returns true.

    If you are looking for the true 3D intersection between segments, call the "closest approach" method and check if the two points it returns are identical. If so, this is the intersection. If not, your lines are "passing in space" and never intersect!!

    For example, in Figure 2 we know the closest approach between segmentAB and segmentDG is segmentAD. The following code will verify this:

    ' Closest approach of AB and DG

    status = Segment3dSegment3dClosestApproach(segmentAB, segmentDG, _

    point0, fraction0, point1, fraction1)

    'Result should be: point0 (0, 0, 0), point1 (0, 0, 10), fraction0=0, fraction1=0

    You should check the return status before reading closest approach points and fractions. If two segments are parallel or coincident, point0/point1, fraction0/fraction1 will be meaningless.

    To get the offset distance between two parallel segments, call method Segment3dClosestPoint to project a point from one segment onto the other segment.

    The relationship between segment and point

    Segment3dClosestPointBounded(),
    Segment3dClosestPoint(),
    Segment3dClosestPointBoundedXY(),
    Segment3dClosestPointXY()
    Compute a point (returned) closest to a space point (known) on a line (known).

    The differences are as follows:

    Function (Method)
    Consider the line as bounded?
    Project to XY plan?

    (Ignore Z Value)

    Segment3dClosestPointBounded
    Yes
    No

    Segment3dClosestPoint
    No
    No

    Segment3dClosestPointBoundedXY
    Yes
    Yes

    Segment3dClosestPointXY
    No
    Yes

     

    If the returned closest point (Figure 4), Point E is within a segment (segmentAB), Segment3dClosestPointBounded () and Segment3dClosestPoint (), it will return same result (Figure4), Point E.



    Figure 4: Closest point
    If the closest point (Figure 4), pointF is outside a segment (segmentAB), Segment3dClosestPointBounded () will return an end point (Figure 4), pointB,

    Segment3dClosestPoint () will return a point outside the segment (Figure 4), pointF.

    After an unbounded calculation, you can decide if the projected point is inside or outside the bounded segment by testing if the fractional position is between zero and one.

    For example (refer to Figure 2):

    Dim closestPoint As Point3d

    Dim closestFraction As Double

    Segment3dClosestPoint segmentAG, pointD, closestPoint, closestFraction

    Segment3dClosestPointBounded segmentAG, pointD, closestPoint, _

    closestFraction

    ‘Result: closestPoint (3.3, 3.3, 3.3), closestFraction=0.333

    Segment3dClosestPointXY segmentAG, pointD, closestPoint, closestFraction

    Segment3dClosestPointBoundedXY segmentAG, pointD, closestPoint, _

    closestFraction

    ‘ Result: closestPoint (0, 0, 0), closestFraction=0,

    ‘ Because we project pointD and segmentAG to XY plan.

     

    To demonstrate the difference between the bounded and unbounded method, let's compute a point on segmentME closest to pointA (Figure 2).

     

    Segment3dClosestPoint segmentME, pointA, closestPoint, closestFraction

    ' Result: closestPoint (6.667, -3.333, -3.333) closestFraction = 1.3333

    ‘ If fraction great then 1, which means it is out of the segment.

     

    Segment3dClosestPointBounded segmentME, pointA, closestPoint, _

    closestFraction

    ‘Result: closestPoint (10, 0, 0), closestFraction = 1

     

    As you can see, the bounded method returns a fraction between 0 and 1; if the computed point is outside of the segment, it returns the start or end point.

    See Also

    Client Server Archive

    MicroStation Desktop TechNotes and FAQs

    Comments or Corrections?

    Bentley's Technical Support Group requests that you please confine any comments you have on this Wiki entry to this "Comments or Corrections?" section. THANK YOU!

     

    • Archived Client Server
    • client server
    • client server 2004
    • Share
    • History
    • More
    • Cancel
    • Dan Koval Created by Bentley Colleague Dan Koval
    • When: Thu, Sep 5 2013 3:46 PM
    • Revisions: 1
    • Comments: 1
    Recommended
    Related
    Communities
    • Home
    • Getting Started
    • Community Central
    • Products
    • Support
    • Secure File Upload
    • Feedback
    Support and Services
    • Home
    • Product Support
    • Downloads
    • Subscription Services Portal
    Training and Learning
    • Home
    • About Bentley Institute
    • My Learning History
    • Reference Books
    Social Media
    •    LinkedIn
    •    Facebook
    •    Twitter
    •    YouTube
    •    RSS Feed
    •    Email

    © 2021 Bentley Systems, Incorporated  |  Contact Us  |  Privacy |  Terms of Use  |  Cookies