MathGroup Archive 2000

[Date Index] [Thread Index] [Author Index]

Search the Archive

point inside torus

  • To: mathgroup at smc.vnet.net
  • Subject: [mg25261] point inside torus
  • From: Wouter Meeussen <eu000949 at pophost.eunet.be>
  • Date: Sun, 17 Sep 2000 04:47:48 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

see notebook (12 kB)


(***********************************************************************

                    Mathematica-Compatible Notebook

This notebook can be used on any computer system with Mathematica 4.0,
MathReader 4.0, or any compatible application. The data for the notebook 
starts with the line containing stars above.

To get the notebook into a Mathematica-compatible application, do one of 
the following:

* Save the data starting with the line of stars above into a file
  with a name ending in .nb, then open the file inside the application;

* Copy the data starting with the line of stars above to the
  clipboard, then use the Paste menu command inside the application.

Data for notebooks contains only printable 7-bit ASCII and can be
sent directly in email or through ftp in text mode.  Newlines can be
CR, LF or CRLF (Unix, Macintosh or MS-DOS style).

NOTE: If you modify the data for this notebook not in a Mathematica-
compatible application, you must delete the line below containing the 
word CacheID, otherwise Mathematica-compatible applications may try to 
use invalid cache data.

For more information on notebooks and Mathematica-compatible 
applications, contact Wolfram Research:
  web: http://www.wolfram.com
  email: info at wolfram.com
  phone: +1-217-398-0700 (U.S.)

Notebook reader applications are available free of charge from 
Wolfram Research.
***********************************************************************)

(*CacheID: 232*)


(*NotebookFileLineBreakTest
NotebookFileLineBreakTest*)
(*NotebookOptionsPosition[      9657,        297]*)
(*NotebookOutlinePosition[     10339,        321]*)
(*  CellTagsIndexPosition[     10295,        317]*)
(*WindowFrame->Normal*)



Notebook[{
Cell[BoxData[
    \(<< Graphics`Shapes`\)], "Input"],

Cell[BoxData[
    \(plane2 = 
      Compile[{{u, _Real, 2}, {v, _Real, 1}}, 
        Det[{\((v - u[\([1]\)])\), \((u[\([1]\)] - 
                u[\([2]\)])\), \ \((u[\([2]\)] - u[\([3]\)])\)}]]\)], "Input"],

Cell[BoxData[
    \(\(?Torus\)\)], "Input"],

Cell[BoxData[
    \(\(tor = Torus[1.6, 1.3, 29, 23];\)\)], "Input"],

Cell[BoxData[
    \(Length[tor]\)], "Input"],

Cell[BoxData[{
    \(Position[tor, tor[\([1, 1, 1]\)]]\), "\[IndentingNewLine]", 
    \(segmentlength = \(Position[tor, tor[\([1, 1, 1]\)]]\)[\([2, 
          1]\)]\)}], "Input"],

Cell[BoxData[
    \(segmentcount = Length[tor]/segmentlength\)], "Input"],

Cell[TextData[{
  "the torus consits of (",
  StyleBox["segmentlength",
    FontSlant->"Italic"],
  " * ",
  StyleBox["segmentcount",
    FontSlant->"Italic"],
  ") polygons, or  ",
  StyleBox["segmentcount",
    FontSlant->"Italic"],
  " convex polyhedrons, each consisting of ",
  StyleBox["segmentlength",
    FontSlant->"Italic"],
  " polygons plus 2 capping lids.\nThis is one lid-less segment :"
}], "Text"],

Cell[BoxData[
    \(<< Realtime3D`\)], "Input"],

Cell[BoxData[
    \( (*\ << Default3D`\ *) \)], "Input"],

Cell[BoxData[
    \(\(Take[tor, segmentlength];\)\)], "Input"],

Cell[BoxData[
    \(Show[Graphics3D[%], PlotRange \[Rule] All]\)], "Input"],

Cell["\<\
this is one of the lids : the set of first points in each polygon;
the other lid is the set of last points. (Other programs might have \
differently structured data for a torus)\
\>", "Text"],

Cell[BoxData[
    \(Polygon[\ 
      Part[Take[tor, segmentlength], All, All, 1] /. 
        Polygon \[Rule] Identity]\)], "Input"],

Cell["\<\
the top lid needs reversing in order to get the correct circulation;
below is the entire torus as a list of well oriented convex polyhedrons:\
\>", "Text"],

Cell[BoxData[
    \(\(mytorus = \(Flatten[{Polygon[
                  Reverse at \ Part[#, All, All, 1] /. 
                    Polygon \[Rule] Identity], #, 
                Polygon[\ 
                  Part[#, All, All, \(-1\)] /. 
                    Polygon \[Rule] Identity]}] &\) /@ \ 
          Partition[Take[tor, segmentlength*\((segmentcount)\)], 
            segmentlength]\ ;\)\)], "Input"],

Cell[BoxData[
    \(Length[mytorus]\)], "Input"],

Cell[BoxData[
    \(Show[Graphics3D[mytorus], PlotRange \[Rule] All]\)], "Input"],

Cell["\<\
for any segment, the circulation of the polygons con be checked from its \
barycentre:\
\>", "Text"],

Cell[BoxData[
    \(\(segmi = mytorus[\([5]\)];\)\)], "Input"],

Cell[BoxData[
    \(loci = \(\((Plus @@ #)\)/
            Length[#] &\)@\((Flatten[\((segmi /. Polygon \[Rule] Identity)\), 
              1] // Union)\)\)], "Input"],

Cell[BoxData[
    \(\(a =  .5;\)\)], "Input"],

Cell[BoxData[
    \(Show[
      Graphics3D[{segmi, 
          Cuboid[\(-a\)/2 {1, 1, 1} + loci, a/2 {1, 1, 1} + loci]}], 
      PlotRange \[Rule] All]\)], "Input"],

Cell[BoxData[
    \(\(Sign[Chop[plane2[Take[#, 3]\ , \ loci]]] &\) /@ \((segmi /. 
          Polygon \[Rule] Identity)\)\)], "Input"],

Cell["\<\
for any segment, the above checks wether the point 'loci' is outside (as \
opposed to inside or on) the segment :\
\>", "Text"],

Cell[BoxData[
    \(FreeQ[\(Sign[
            Chop[plane2[
                Take[#, 3]\ , \ {\(-8. \), 0. , 0. } + 
                  0*loci]]] &\) /@ \((segmi /. 
            Polygon \[Rule] Identity)\), \(-1\)]\)], "Input"],

Cell[BoxData[
    RowBox[{"Timing", "[", 
      RowBox[{\(z = \(q = 0\)\), ";", 
        RowBox[{"{", 
          RowBox[{
            RowBox[{
              RowBox[{"Do", "[", 
                RowBox[{
                  RowBox[{"it", "=", 
                    RowBox[{"FreeQ", "[", 
                      RowBox[{
                        RowBox[{\(z++\), ";", 
                          
                          StyleBox[\(\(Sign[\(q++\); 
                                  Chop[plane2[Take[#, 3]\ , 
                                      1*\ \ {0. , 0. , 8. } + 
                                        0*loci]]] &\) /@ \((segmi /. 
                                  Polygon -> Identity)\)\),
                            FontColor->RGBColor[0, 0, 1]]}], ",", \(-1\)}], 
                      "]"}]}], ",", \({100}\)}], "]"}], ";", "it"}], ",", "q",
             ",", "z"}], "}"}]}], "]"}]], "Input"],

Cell["\<\
programming for speed instead of clarity, we try to abort the calculation as \
soon as the testpoint lies on the wrong side of any polygon :\
\>", "Text"],

Cell[BoxData[
    RowBox[{"Timing", "[", 
      RowBox[{\(z = \(q = 0\)\), ";", 
        RowBox[{"{", 
          RowBox[{
            RowBox[{
              RowBox[{"Do", "[", 
                RowBox[{
                  RowBox[{"it", "=", 
                    RowBox[{
                      RowBox[{
                        
                        StyleBox[\(FreeQ[\(z++\); 
                            Sign[Chop[
                                plane2[Take[#, 3]\ , 
                                  1*\ {0. , 0. , 8. } + 0*loci]]], \(-1\)]\),
                          FontColor->RGBColor[0, 0, 1]], "&"}], 
                      "/@", \((\(q++\); 
                        And @@ \ \((segmi /. Polygon -> Identity)\))\)}]}], 
                  ",", \({100}\)}], "]"}], ";", "it"}], " ", ",", "q", ",", 
            "z"}], "}"}]}], "]"}]], "Input"],

Cell["\<\
and finally, we can verify if if the point loci is inside *any* of the convex \
polyhedrons :\
\>", "Text"],

Cell[BoxData[{
    \(z = \(q = 0\); 
    Timing[Or @@ \((\(\(FreeQ[\(z++\); 
                    Sign[Chop[
                        plane2[Take[#, 3]\ , \ 
                          0*\ \ {\(-8. \), 0. , 0. } + 
                            1*loci]]], \(-1\)] &\) /@ \((\(q++\); 
                  And @@ \((# /. Polygon :> Identity)\))\) &\) /@ 
            mytorus)\)]\), "\[IndentingNewLine]", 
    \({z, q}\)}], "Input"],

Cell["\<\
we can abort as soon as the testpoint lies inside any polyhedron:\
\>", "Text"],

Cell[BoxData[{
    \(z = \(q = 0\); 
    Timing[\ \((\(\(FreeQ[\(z++\); 
                  Sign[Chop[
                      plane2[Take[#, 3]\ , 
                        0*{\(-8. \), 0. , 0. } + 
                          1*loci]]], \(-1\)] &\) /@ \((\(q++\); 
                And @@ \((# /. Polygon :> Identity)\))\) &\) /@ \((Or @@ 
              mytorus)\))\)]\), "\[IndentingNewLine]", 
    \({z, q}\)}], "Input"],

Cell[TextData[{
  "Now we calculate a \"ray\" through the torus : (0.22 seconds per point on \
average,",
  " Version Number: ",
  
  ValueBox["$VersionNumber"],
  ".",
  
  ValueBox["$ReleaseNumber"],
  ".",
  
  ValueBox["$MinorReleaseNumber"],
  ", Win'98, 32Mb, 100MHz",
  ")\nIf the testpoint lies outside, all 29 (=segmentcount) polyhedral \
segments have to be checked;\nif it's inside, less segments until a hit, but \
then a hit is only shure after checking all 25 (=segmentlength+2) polygons :"
}], "Text"],

Cell[BoxData[
    \(Timing[
      Table[z = \(q = 
            0\); {\((\(\((\(FreeQ[\(z++\); 
                        Sign[Chop[
                            plane2[
                              Take[#, 3]\ , \ {w/4, w, 
                                w/10}]]], \(-1\)] &\) /@ \((\(q++\); 
                      And @@ \ \((# /. 
                            Polygon -> Identity)\))\)\ \ )\) &\) /@ \((Or @@ 
                  mytorus)\))\), q, z}, {w, \(-16. \), 
          16. ,  .5}]\ ]\)], "Input"],

Cell[BoxData[
    \(Timing[
      Table[\((\(\((\(FreeQ[
                      Sign[Chop[
                          plane2[
                            Take[#, 3]\ , \ {w/4. , w, 
                              w/10. }]]], \(-1\)] &\) /@ \((And @@ \ \((# /. 
                          Polygon :> Identity)\))\)\ \ )\) &\) /@ \((Or @@ 
                mytorus)\))\), {w, \(-16. \), 16. ,  .5}]\ ]\)], "Input"],

Cell[BoxData[
    \(First[%]/Length[Last[%]]\)], "Input"]
},
FrontEndVersion->"4.0 for Microsoft Windows",
ScreenRectangle->{{0, 1024}, {0, 723}},
AutoGeneratedPackage->None,
WindowSize->{1015, 696},
WindowMargins->{{0, Automatic}, {Automatic, 0}}
]


(***********************************************************************
Cached data follows.  If you edit this Notebook file directly, not using
Mathematica, you must remove the line containing CacheID at the top of 
the file.  The cache data will then be recreated when you save this file 
from within Mathematica.
***********************************************************************)

(*CellTagsOutline
CellTagsIndex->{}
*)

(*CellTagsIndex
CellTagsIndex->{}
*)

(*NotebookFileOutline
Notebook[{
Cell[1717, 49, 52, 1, 30, "Input"],
Cell[1772, 52, 207, 4, 30, "Input"],
Cell[1982, 58, 43, 1, 30, "Input"],
Cell[2028, 61, 67, 1, 30, "Input"],
Cell[2098, 64, 44, 1, 30, "Input"],
Cell[2145, 67, 178, 3, 50, "Input"],
Cell[2326, 72, 73, 1, 30, "Input"],
Cell[2402, 75, 413, 14, 52, "Text"],
Cell[2818, 91, 47, 1, 30, "Input"],
Cell[2868, 94, 56, 1, 30, "Input"],
Cell[2927, 97, 62, 1, 30, "Input"],
Cell[2992, 100, 75, 1, 30, "Input"],
Cell[3070, 103, 201, 4, 52, "Text"],
Cell[3274, 109, 131, 3, 30, "Input"],
Cell[3408, 114, 165, 3, 52, "Text"],
Cell[3576, 119, 399, 8, 70, "Input"],
Cell[3978, 129, 48, 1, 30, "Input"],
Cell[4029, 132, 81, 1, 30, "Input"],
Cell[4113, 135, 110, 3, 33, "Text"],
Cell[4226, 140, 62, 1, 30, "Input"],
Cell[4291, 143, 166, 3, 30, "Input"],
Cell[4460, 148, 45, 1, 30, "Input"],
Cell[4508, 151, 163, 4, 30, "Input"],
Cell[4674, 157, 133, 2, 30, "Input"],
Cell[4810, 161, 137, 3, 33, "Text"],
Cell[4950, 166, 224, 5, 30, "Input"],
Cell[5177, 173, 902, 20, 70, "Input"],
Cell[6082, 195, 164, 3, 33, "Text"],
Cell[6249, 200, 851, 20, 70, "Input"],
Cell[7103, 222, 117, 3, 33, "Text"],
Cell[7223, 227, 423, 9, 110, "Input"],
Cell[7649, 238, 89, 2, 33, "Text"],
Cell[7741, 242, 417, 9, 90, "Input"],
Cell[8161, 253, 516, 16, 71, "Text"],
Cell[8680, 271, 503, 11, 90, "Input"],
Cell[9186, 284, 407, 8, 70, "Input"],
Cell[9596, 294, 57, 1, 30, "Input"]
}
]
*)




(***********************************************************************
End of Mathematica Notebook file.
***********************************************************************)



Dr. Wouter L. J. MEEUSSEN
w.meeussen.vdmcc at vandemoortele.be
eu000949 at pophost.eunet.be


  • Prev by Date: Re: RowReduce of badly conditioned matrix
  • Next by Date: Newbie question
  • Previous by thread: Re: List of Interpolated functions inside plot
  • Next by thread: Re: point inside torus