a=ashft(i)
i : | number between 1 and 25 |
a : | angle to turn |
A=SGbox([30 20 10]); B=SGcylinder(1,20); GPLauxgridpointsCPS2(CPLbuffer(PLsquare([30,20]),-1.5),10); PL=ans; CPSplot(PLsquare([30,20]))
%% FAILS
C=A; for i=1:size(PL,1); Bi=SGtransP(B,[PL(i,:) -10]); C=SGsubtract(C,Bi); end; cla; SGplotalpha(C); view(-30,30);
%% NO PROBLEMS
C=A; for i=1:size(PL,1); Bi=SGtransR(B,rot(0,0,ashft(i))); Bi=SGtransP(Bi,[PL(i,:) -10]); C=SGsubtract(C,Bi); end; cla; SGplotalpha(C); view(-30,30);
The function ashft
is designed to generate an irrational angle based on a combination of mathematical constants and prime numbers. This is useful in scenarios where repeated boolean operations are performed on the same geometry, and unique angles are needed to avoid repetitive patterns.
The function begins by calculating a constant zz
, which is defined as 2 * pi / exp(1)
. This value is a fixed irrational number derived from the mathematical constants pi and e.
Next, the function generates a list of prime numbers up to 100 using the primes
function. This list is stored in the variable pp
.
The core calculation of the function is performed by dividing zz
by a specific prime number from the list pp
. The index of the prime number is determined by the input parameter i
. Specifically, the function uses the prime number at the position end + 1 - i
in the list pp
. This ensures that the angle a
is unique for each value of i
and avoids repetition.
The result is an irrational angle a
that can be used to rotate geometric objects in a way that minimizes the likelihood of repeated patterns.
The example provided in the comments demonstrates how the ashft
function can be used in conjunction with other functions from the SolidGeometry library to perform boolean operations on geometric shapes without encountering issues related to repeated angles.