Re: Challenge(?): Intersection curve between two cylinders in a specific position Message #6 Posted by peacecalc on 17 Sept 2013, 3:09 p.m., in response to message #5 by Pier Aiello
Okay Pier,
%%HP: T(3)A(R)F(,);
\<< \> SPANT1xUMR SPANT2xUMR SPANT1xHULL SPANT2xHULL
\<< SPANT2xHULL BODY DUP SIZE SWAP SPANT1xHULL SPANT2xHULL  BODY
SPANT2xHULL TAIL SPANT2xHULL BODY 
SPANT1xHULL BODY SPANT1xHULL TAIL
SPANT1xHULL BODY 
SPANT2xHULL TAIL SPANT1xHULL BODY 
SPANT1xUMR DUP SIZE SWAP SPANT2xUMR SPANT1xUMR 
\> HULLxNUM TRAEGxHULL2 RICHT1xHULL2 RICHT2xHULL2
TRAEGxHULL1 RICHT1xHULL1 RICHT2xHULL1
UMxNUM TRAEGxUM RICHTxUM
\<< RICHT1xHULL2 RICHT2xHULL2 CROSS RICHT1xHULL1 RICHT2xHULL1 CROSS { } { }
\> NORMxHULL2 NORMxHULL1 SCHNITTxHULL2 SCHNITTxHULL1
\<< 1 HULLxNUM
FOR j 1 UMxNUM
FOR i RICHTxUM i GET NORMxHULL2 j GET DUP ROT DOT DUP
IF 0, \=/
THEN SWAP TRAEGxHULL2 j GET TRAEGxUM i GET  DOT SWAP / DUPDUP
IF 0, \>= SWAP 1, \<= AND
THEN TRAEGxUM i GET
RICHTxUM i GET ROT * + DUP
TRAEGxHULL2 j GET
RICHT1xHULL2 j GET
RICHT2xHULL2 j GET
NORMxHULL2 j GET
\> SCHNITTxPKT TRAEGxHULL RICHTxHULLx1 RICHTxHULLx2 NORMxHULL
\<< SCHNITTxPKT TRAEGxHULL  DUP RICHTxHULLx2 CROSS
SWAP RICHTxHULLx1 CROSS NORMxHULL DOT
SWAP NORMxHULL DOT
NORMxHULL NORMxHULL DOT
DUP ROT SWAP / UNROT NEG /
\>> \> KOEFFxRICHTx1 KOEFFxRICHTx2
\<< KOEFFxRICHTx1 DUP
IF 0, \>= SWAP 1, \<= AND
THEN KOEFFxRICHTx2 DUP
IF 0, \>= SWAP 1, KOEFFxRICHTx1  \<= AND
THEN j 2 \>LIST SCHNITTxHULL2 SWAP + 'SCHNITTxHULL2' STO
ELSE DROP
END
ELSE DROP
END
\>>
ELSE DROP
END
ELSE DROP DROP
END
NEXT
NEXT 1 HULLxNUM
FOR j 1 UMxNUM
FOR i RICHTxUM i GET NORMxHULL1 j GET DUP ROT DOT DUP
IF 0, \=/
THEN SWAP TRAEGxHULL1 j GET TRAEGxUM i GET  DOT SWAP / DUPDUP
IF 0, \>= SWAP 1, \<= AND
THEN TRAEGxUM i GET
RICHTxUM i GET ROT * + DUP
TRAEGxHULL1 j GET
RICHT1xHULL1 j GET
RICHT2xHULL1 j GET
NORMxHULL1 j GET
\> SCHNITTxPKT TRAEGxHULL RICHTxHULLx1 RICHTxHULLx2 NORMxHULL
\<< SCHNITTxPKT TRAEGxHULL  DUP RICHTxHULLx2 CROSS
SWAP RICHTxHULLx1 CROSS
NORMxHULL DOT
SWAP NORMxHULL DOT
NORMxHULL NORMxHULL DOT
DUP ROT SWAP / UNROT NEG /
\>> \> KOEFFxRICHTx1 KOEFFxRICHTx2
\<< KOEFFxRICHTx1 DUP
IF 0, \>= SWAP 1, \<= AND
THEN KOEFFxRICHTx2 DUP
IF 0, \>= SWAP 1, KOEFFxRICHTx1  \<= AND
THEN j 2 \>LIST SCHNITTxHULL1 SWAP + 'SCHNITTxHULL1' STO
ELSE DROP
END
ELSE DROP
END
\>>
ELSE DROP
END
ELSE DROP DROP
END
NEXT
NEXT SCHNITTxHULL1 DUP SIZE 1  SCHNITTxHULL1 SWAP GET SWAP 1 GET
IF ==
THEN SCHNITTxHULL1 BODY BODY 'SCHNITTxHULL1' STO
END SCHNITTxHULL2 'U1' STO SCHNITTxHULL1 'U2' STO
\>>
\>>
\>>
\>>
So you get what you want (YGWYW ;))
The input are four lists with 3D vectors, the first two list discribe f. example the blue cylinder (there are only the coordinates needed in form of the bottom and top circle (the frames or formers of the cylinder)), the next two lists describe f. example the black cylinder (in the same form).
The user decides how fine (how many intersections points should be find), by the size of the lists. The lists of the different shapes can have a different size, but the pair itself must have the same size.
The user gets after some time two lists back "U1" and "U2", these two lists contain the intersections points in 3D vectors.
It is not a analytical solution, it's numerical, but it works for all different shapes, which could be generated by two frames (two 3D polygons).
It is a very clumsy piece of program, but you have to imagine, the calculator has to find out, if there are common points and where they are.
Greetings
peacecalc
