|
|
Le 13/03/2010 22:05, Kene nous fit lire :
> I am working on a math problem with POV-Ray where I am trying to calculate the
> slope of a line. I have located two points on the line with the coordinates
> (9000, -8022) and (-5000, -1792). Let us assume the first set of coordinates are
> identified as Ref1_Pos.x, Ref1_Pos.z while the second set are Ref2_Pos.x and
> Ref2_Pos.z. The slope formula will be:
>
> Slope = ( Ref1_Pos.z - Ref2_Pos.z )/( Ref1_Pos.x - Ref2_Pos.x )
>
> In manual calculation the above problem gives the result: -0.304862
> With POV-Ray I get: -0
Maybe we can see actual code ?
#declare Ref1_Pos=<9000,-8022>;
For instance, you get a .x and a .y (and .z=0)
Post a reply to this message
|
|
|
|
Le_Forgeron <jgr### [at] freefr> wrote:
>
> Maybe we can see actual code ?
>
Below is the actual macro. Basically all variables are vectors and y is the
height so remains the same for all variables.
#macro ConnRSide( SName, SRef1, Ref2, Thickness, Angle, Sender )
// Get object name and snap Id
Get_SnapId( SName, 1 )
#local Obj_Name = Found_Object_Name;
#local Obj_Snap_Name = Found_Snap_Name;
// find object name
Find_Object( Obj_Name )
#local Obj_Index = Found_Object_Index;
// get ref1 name
Get_SnapId( SRef1, 1 )
#local Ref1_Name = Found_Object_Name;
#local Ref1_Snap_Name = Found_Snap_Name;
// find ref1 and Change angle according to sender
Find_Object( Ref1_Name )
#local Ref1_Index = Found_Object_Index;
#local Ref1_Type = kobldes_Objects_Id[ Ref1_Index ][1];
#local Ref1_Angle = kobldes_Objects_Pt[ Ref1_Index ][0][2];
// before we manipulate the angle, let get a second point along the new line
CalcCurvePoint( Angle, 1000 )
#local AngleL = SnapCoords[0];
#if( strcmp( Sender, "RConnRSide" )=0 )
#local Angle = Angle + Ref1_Angle;
#end
// get ref1 coords
Get_Snap_Location( Ref1_Snap_Name, Ref1_Index, Ref1_Name )
#local Ref1_Pos = Found_Snap_Location + kobldes_Objects_Pt[ Ref1_Index
][1][1];
// get ref2 name
Get_SnapId( Ref2, 1 )
#local Ref2_Name = Found_Object_Name;
#local Ref2_Snap_Name = Found_Snap_Name;
#local Ref2_Snap1 = concat( Ref2_Snap_Name, "1" );
// find ref2
Find_Object( Ref2_Name )
#local Ref2_Index = Found_Object_Index;
#local Ref2_Type = kobldes_Objects_Id[ Ref2_Index ][1];
#local Ref2_Angle = kobldes_Objects_Pt[ Ref2_Index ][0][2];
Get_Snap_Location( Ref2_Snap1, Ref2_Index, Ref2_Name )
#local Ref2_Snap1_Pos = Found_Snap_Location + kobldes_Objects_Pt[ Ref2_Index
][1][1];
//nDebug( "Ref2"
// test if the angle of ref2 is 0/180/360 or 90/270
// use switch
#if( Ref2_Angle = 0 | Ref2_Angle = 180 | Ref2_Angle = 360 )
// here we know that the slope is undefined
// In the following calculations, y is z
// 1. Horizontal distance: Ref2 - Ref1
// 2. Length of new side: hyp = adj/cos Angle
// 3. Make side
// 4. Place it
//#local HorLength = Ref2_Snap1_Pos.x - Ref1_Pos.x; //1.
#local HorLength = vlength( Ref2_Snap1_Pos - Ref1_Pos ); //1.
#local SideLength = HorLength / cos( radians( 90 - Angle )); //2.
RSide( Obj_Name, SideLength, Thickness, Angle ) //3.
// place the side in the scene
SOffset( SName, SRef1, 0,0,0 ) //4.
#else
// In the following calculations, y is z
// 1. Find a point from SRef1 to 1000 at the provided angle
// 2. Find the slope of line from 1.
// 3. Get start and mid-point of Ref2
// 4. Find the slope of line from 3.
// 5. Pick a point in line from 1. (x,y), find the y-intercept (b): y - mx =
b
// 6. Pick a point in line from 3. (x,y), find the y-intercept (b): y - mx =
b
// 7. find the common x point in both lines: x = (5. - 6.)/(4. + 2.)
// 8. find the common y point in both lines: y = 2. * 7. + 5. (or y = 4. *
7. + 6.)
#local AngleL = AngleL + kobldes_Objects_Pt[ Ref1_Index ][1][1]; //1.
nDebug( "Calculated X length of line", AngleL.x )
nDebug( "Calculated Y length of line", AngleL.y )
nDebug( "Calculated Z length of line", AngleL.z )
nDebug( "X Origin of new line", Ref1_Pos.x )
nDebug( "Y Origin of new line", Ref1_Pos.y )
nDebug( "Z Origin of new line", Ref1_Pos.z )
#local SlopeL1 = (( AngleL.z ) - ( Ref1_Pos.z ))/(( AngleL.x )-( Ref1_Pos.x
)); //2.
nDebug( "SlopeL1", SlopeL1 )
// 3.
#local Ref2_Snap2 = concat( Ref2_Snap_Name, "2" );
Get_Snap_Location( Ref2_Snap2, Ref2_Index, Ref2_Name )
#local Ref2_Snap2_Pos = Found_Snap_Location + kobldes_Objects_Pt[
Ref2_Index ][1][1];
#local SlopeL2 = ( Ref2_Snap2_Pos.z - Ref2_Snap1_Pos.z )/( Ref2_Snap2_Pos.x
-
Ref2_Snap1_Pos.x ); //4.
#local BL1 = AngleL.z - ( SlopeL1 * AngleL.x );
//5.
#local BL2 = Ref2_Snap2_Pos.z - ( SlopeL2 * Ref2_Snap2_Pos.x ); //6.
#local CommonX = ( BL1 - BL2 )/( SlopeL2 + SlopeL1 ); //7.
#local CommonYa = SlopeL1 * CommonX + BL1; //8a.
#local CommonYb = SlopeL2 * CommonX + BL2; //8b
#if( CommonYa = CommonYb )
//create new side here
#local SideXYZ = < CommonX, 0, CommonYa >;
Find_Length_Angle( SideXYZ, Ref1_Pos ) // Y value is ignored in this
function
#local SideLength = Found_Length;
RSide( Obj_Name, SideLength, Thickness, Angle )
// place the side in the scene
SOffset( SName, SRef1, 0,0,0 )
#else
sDebug( "ConnRSide: New side does not intersect existing side", Obj_Name )
#end
#end
Post a reply to this message
|
|
|
|
Le 14/03/2010 12:30, Kene nous fit lire :
> Answer from POV-Ray to the following math:
>
> #local SL = 8 / 12;
>
> is the number 1.
>
> Is there another way to formulate this so POV-Ray can provide the right answer?
>
>
These are not the droids you are looking for:
#local SL = 8 / 12;
#debug concat(str(SL,0,0),"\n")
#debug concat(str(SL,8,8),"\n")
Post a reply to this message
|
|