Click here to Skip to main content
15,913,941 members
Home / Discussions / Visual Basic
   

Visual Basic

 
GeneralRe: writing a timestamp to a xml file. Pin
freakyit11-Oct-09 23:57
freakyit11-Oct-09 23:57 
GeneralRe: writing a timestamp to a xml file. Pin
malcomhfc12-Oct-09 10:44
malcomhfc12-Oct-09 10:44 
QuestionExport Data to Excel Pin
Puffsss10-Oct-09 23:22
Puffsss10-Oct-09 23:22 
AnswerRe: Export Data to Excel Pin
Andy_L_J10-Oct-09 23:28
Andy_L_J10-Oct-09 23:28 
AnswerRe: Export Data to Excel Pin
The Man from U.N.C.L.E.12-Oct-09 4:18
The Man from U.N.C.L.E.12-Oct-09 4:18 
QuestionNumerical accuracy in calculation Pin
A.Najafi10-Oct-09 21:55
A.Najafi10-Oct-09 21:55 
AnswerRe: Numerical accuracy in calculation Pin
Andy_L_J10-Oct-09 23:11
Andy_L_J10-Oct-09 23:11 
GeneralRe: Numerical accuracy in calculation Pin
A.Najafi11-Oct-09 0:13
A.Najafi11-Oct-09 0:13 
Certinly I have been used Double data type for this calculation. The code inserted in below is the same
story that I have been explained.


Private Sub btnCalc_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click<br />
<br />
        Dim xint, yint, zint As Double<br />
        Dim ob, oc, ratio As Double<br />
        Dim havint, intree As Boolean<br />
        Dim x0, x1, x2, xb As Double<br />
        Dim y0, y1, y2, yb As Double<br />
        Dim z0, z1, z2, zb As Double<br />
        '3 Points of plane formed triangle too.<br />
        x0 = 2<br />
        x1 = 2<br />
        x2 = 2<br />
        y0 = 0<br />
        y1 = 2<br />
        y2 = 2<br />
        z0 = 2<br />
        z1 = 2<br />
        z2 = 0<br />
        'Points of line, other point is [0 0 0]<br />
        xb = 1.5<br />
        yb = 1<br />
        zb = 0.5<br />
        Line_PlaneIntersection(x0, x1, x2, xb, y0, y1, y2, yb, z0, z1, z2, _<br />
                              zb, xint, yint, zint, ob, oc, ratio, havint, intree)<br />
    End Sub<br />
<br />
<br />
    Public Shared Sub Line_PlaneIntersect(ByVal X0 As Double, ByVal X1 As Double, ByVal X2 As Double, _<br />
                                         ByVal Xb As Double,ByVal Y0 As Double, ByVal Y1 As Double, _<br />
                                         ByVal Y2 As Double,ByVal Yb As Double,ByVal Z0 As Double, _ <br />
                                         ByVal Z1 As Double, ByVal Z2 As Double, ByVal Zb As Double, _<br />
                                         ByRef Xint As Double, ByRef Yint As Double, ByRef Zint As _<br />
                                         Double, ByRef OB As Double, ByRef OC As Double, ByRef Ratio As _<br />
                                         Double,ByRef HaveIntersect As Boolean, ByRef InTriangle As _<br />
                                         Boolean) <br />
                                        <br />
                                         <br />
        '***This formulation is based on the assumption that the line starts from origin***<br />
        Dim t, u, v As Single<br />
        Dim A, B, C, D As Double<br />
        Dim A1, A2, A3 As Double<br />
        Dim B1, B2, B3 As Double<br />
        Dim C1, C2, C3 As Double<br />
        Dim D1, D2, D3, D4, D5, D6 As Double<br />
        Dim Det As Double<br />
        Dim Det1, Det2, Det3, Det4, Det5, Det6 As Double<br />
        Det1 = +Xb * ((Y2 - Y0) * (Z1 - Z0))<br />
        Det2 = +Yb * ((X1 - X0) * (Z2 - Z0))<br />
        Det3 = +Zb * ((X2 - X0) * (Y1 - Y0))<br />
        Det4 = -Xb * ((Y1 - Y0) * (Z2 - Z0))<br />
        Det5 = -Yb * ((X2 - X0) * (Z1 - Z0))<br />
        Det6 = -Zb * ((X1 - X0) * (Y2 - Y0))<br />
        Det = Det1 + Det2 + Det3 + Det4 + Det5 + Det6<br />
        If Det <> 0 Then<br />
            HaveIntersect = True<br />
            A1 = X0 * ((Y1 - Y0) * (Z2 - Z0) - (Y2 - Y0) * (Z1 - Z0))<br />
            A2 = Y0 * ((X2 - X0) * (Z1 - Z0) - (X1 - X0) * (Z2 - Z0))<br />
            A3 = Z0 * ((X1 - X0) * (Y2 - Y0) - (X2 - X0) * (Y1 - Y0))<br />
            A = A1 + A2 + A3<br />
            B1 = X0 * ((Y2 - Y0) * Zb - (Z2 - Z0) * Yb)<br />
            B2 = Y0 * ((Z2 - Z0) * Xb - (X2 - X0) * Zb)<br />
            B3 = Z0 * ((X2 - X0) * Yb - (Y2 - Y0) * Xb)<br />
            B = B1 + B2 + B3<br />
            C1 = X0 * ((Z1 - Z0) * Yb - (Y1 - Y0) * Zb)<br />
            C2 = Y0 * ((X1 - X0) * Zb - (Z1 - Z0) * Xb)<br />
            C3 = Z0 * ((Y1 - Y0) * Xb - (X1 - X0) * Yb)<br />
            C = C1 + C2 + C3<br />
            D1 = +(X1 - X0) * (Y2 - Y0) * Zb<br />
            D2 = +(X2 - X0) * (Z1 - Z0) * Yb<br />
            D3 = +(Y1 - Y0) * (Z2 - Z0) * Xb<br />
            D4 = -(X1 - X0) * (Z2 - Z0) * Yb<br />
            D5 = -(X2 - X0) * (Y1 - Y0) * Zb<br />
            D6 = -(Y2 - Y0) * (Z1 - Z0) * Xb<br />
            D = D1 + D2 + D3 + D4 + D5 + D6<br />
            t = A / D<br />
            u = B / D<br />
            v = C / D<br />
            Xint = Xb * t<br />
            Yint = Yb * t<br />
            Zint = Zb * t <br />
            Dim Bool1, Bool2 As Boolean<br />
            Bool1 = u >= 0 And u <= 1<br />
            Bool2 = v >= 0 And v <= 1<br />
            If Bool1 And Bool2 And (u + v) <= 1 Then<br />
                'means that the intersection point lies in triangle wroughted from 3 points of the plane  <br />
                InTriangle = True<br />
                OB = Math.Sqrt(Xb ^ 2 + Yb ^ 2 + Zb ^ 2)<br />
                OC = Math.Sqrt(Xint ^ 2 + Yint ^ 2 + Zint ^ 2)<br />
                Ratio = OB / OC<br />
            End If<br />
        Else<br />
            HaveIntersect = False<br />
            InTriangle = False<br />
        End If<br />
    End Sub

'***************************************************************************************************

%MAtlab syntax
clear<br />
%Data of line's points<br />
xa=0; ya=0; za=0;<br />
xb=1.5; yb=1; zb=1/2;<br />
Ia=[xa<br />
    ya<br />
    za];<br />
Ib=[xb<br />
    yb<br />
    zb];<br />
%Data of plane<br />
x0=2; y0=0; z0=2;<br />
x1=2; y1=2; z1=2;<br />
x2=2; y2=2; z2=0;<br />
A=      [xa-xb x1-x0 x2-x0<br />
         ya-yb y1-y0 y2-y0<br />
         za-zb z1-z0 z2-z0];<br />
B=[xa-x0<br />
   ya-y0<br />
   za-z0];<br />
<br />
C=A^-1*B<br />
<br />
Iint=Ia+(Ib-Ia).*C(1)<br />

after running
Iint =

2.0000
1.3333
0.6667
GeneralRe: Numerical accuracy in calculation Pin
Andy_L_J11-Oct-09 0:34
Andy_L_J11-Oct-09 0:34 
GeneralRe: Numerical accuracy in calculation Pin
A.Najafi11-Oct-09 1:42
A.Najafi11-Oct-09 1:42 
GeneralRe: Numerical accuracy in calculation Pin
Dave Kreskowiak11-Oct-09 6:57
mveDave Kreskowiak11-Oct-09 6:57 
GeneralRe: Numerical accuracy in calculation Pin
Luc Pattyn11-Oct-09 8:13
sitebuilderLuc Pattyn11-Oct-09 8:13 
Questioninserting input into matlab and run m-file from vb Pin
waiting 4 some110-Oct-09 21:17
waiting 4 some110-Oct-09 21:17 
QuestionHow to add headings to a dataset Pin
Dhruva Hein10-Oct-09 9:27
Dhruva Hein10-Oct-09 9:27 
AnswerRe: How to add headings to a dataset Pin
Henry Minute10-Oct-09 11:18
Henry Minute10-Oct-09 11:18 
GeneralRe: How to add headings to a dataset Pin
Dhruva Hein10-Oct-09 12:49
Dhruva Hein10-Oct-09 12:49 
GeneralRe: How to add headings to a dataset Pin
Henry Minute10-Oct-09 13:38
Henry Minute10-Oct-09 13:38 
GeneralRe: How to add headings to a dataset Pin
Dave Kreskowiak10-Oct-09 16:15
mveDave Kreskowiak10-Oct-09 16:15 
QuestionOpen File with my application Pin
Anubhava Dimri10-Oct-09 0:24
Anubhava Dimri10-Oct-09 0:24 
AnswerRe: Open File with my application Pin
Steven J Jowett10-Oct-09 0:41
Steven J Jowett10-Oct-09 0:41 
QuestionNeed Help Pin
Purish Dwivedi9-Oct-09 22:53
Purish Dwivedi9-Oct-09 22:53 
AnswerRe: Need Help PinPopular
Andy_L_J9-Oct-09 23:03
Andy_L_J9-Oct-09 23:03 
GeneralRe: Need Help Pin
Mycroft Holmes10-Oct-09 1:26
professionalMycroft Holmes10-Oct-09 1:26 
GeneralRe: Need Help Pin
Richard MacCutchan10-Oct-09 2:48
mveRichard MacCutchan10-Oct-09 2:48 
Questionmouse over form border event problem Pin
faith4ever4u9-Oct-09 12:12
faith4ever4u9-Oct-09 12:12 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.