Skip to content

Commit

Permalink
v0.3.34
Browse files Browse the repository at this point in the history
Cross product adjustments and optimizations
Implements #2
Implements #4
  • Loading branch information
BurksEngineering committed Apr 18, 2023
1 parent 8a0f938 commit 82810e3
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 19 deletions.
26 changes: 26 additions & 0 deletions TcTransform/TcTransform/POUs/Functions/Vector3_CrossProduct.TcPOU
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="utf-8"?>
<TcPlcObject Version="1.1.0.1" ProductVersion="3.1.4024.9">
<POU Name="Vector3_CrossProduct" Id="{990310ce-9c42-010b-20d8-ae0eb67dd696}" SpecialFunc="None">
<Declaration><![CDATA[//Specialized, optimized version of the generic vector cross product specifically for vector 3
//Thanks to captain-yoshi for the algorithm and idea
//see https://github.com/BurksEngineering/TcTransform/issues/4
FUNCTION Vector3_CrossProduct
VAR_IN_OUT CONSTANT
A : Vector3;
B : Vector3;
END_VAR
VAR_IN_OUT
Res : Vector3;
END_VAR]]></Declaration>
<Implementation>
<ST><![CDATA[// Complexity : 6M+3A
Res.SetI(0, A.GetI(1)*B.GetI(2) - A.GetI(2)*B.GetI(1));
Res.SetI(1, A.GetI(2)*B.GetI(0) - A.GetI(0)*B.GetI(2));
Res.SetI(2, A.GetI(0)*B.GetI(1) - A.GetI(1)*B.GetI(0));]]></ST>
</Implementation>
<LineIds Name="Vector3_CrossProduct">
<LineId Id="30" Count="2" />
<LineId Id="7" Count="0" />
</LineIds>
</POU>
</TcPlcObject>
16 changes: 2 additions & 14 deletions TcTransform/TcTransform/POUs/Vector3.TcPOU
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,9 @@ GetReversed.Reverse();]]></ST>
METHOD PUBLIC GetVector3CrossProduct : Vector3
VAR_INPUT
M_V : Vector3;
END_VAR
VAR
Vs : ARRAY[0..1] OF POINTER TO Matrix;
END_VAR]]></Declaration>
<Implementation>
<ST><![CDATA[Vs[0] := THIS;
Vs[1] := ADR(M_V);
Vector_CrossProduct(GetVector3CrossProduct,Vs);]]></ST>
<ST><![CDATA[Vector3_CrossProduct(This^,M_V,GetVector3CrossProduct);]]></ST>
</Implementation>
</Method>
<Method Name="GetVector3Difference" Id="{a8cdd625-bd8e-03da-2caa-b18f9cf600a9}" FolderPath="Getters\">
Expand Down Expand Up @@ -173,10 +168,7 @@ VAR
Vs : ARRAY[0..1] OF POINTER TO MATRIX;
END_VAR]]></Declaration>
<Implementation>
<ST><![CDATA[Vs[0] := ADR(A);
Vs[1] := ADR(B);
Vector_CrossProduct(THIS^,Vs);]]></ST>
<ST><![CDATA[Vector3_CrossProduct(A,B,This^);]]></ST>
</Implementation>
</Method>
<Method Name="SetFromComponents" Id="{cfb8f7f5-c7d4-45fd-bf85-30fd34a78de9}" FolderPath="Setters\">
Expand Down Expand Up @@ -321,7 +313,6 @@ END_VAR
<LineId Id="5" Count="1" />
</LineIds>
<LineIds Name="Vector3.GetVector3CrossProduct">
<LineId Id="17" Count="1" />
<LineId Id="10" Count="0" />
</LineIds>
<LineIds Name="Vector3.GetVector3Difference">
Expand All @@ -346,9 +337,6 @@ END_VAR
<LineId Id="12" Count="0" />
</LineIds>
<LineIds Name="Vector3.SetAsCrossProduct">
<LineId Id="10" Count="0" />
<LineId Id="12" Count="0" />
<LineId Id="11" Count="0" />
<LineId Id="5" Count="0" />
</LineIds>
<LineIds Name="Vector3.SetFromComponents">
Expand Down
8 changes: 6 additions & 2 deletions TcTransform/TcTransform/TcTransform.plcproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<Company>Burks Engineering</Company>
<Released>false</Released>
<Title>TcTransform</Title>
<ProjectVersion>0.3.34</ProjectVersion>
<ProjectVersion>0.3.36</ProjectVersion>
<LibraryCategories>
<LibraryCategory xmlns="">
<Id>{d5875a41-817d-44f3-8af7-6c59eaddc95f}</Id>
Expand Down Expand Up @@ -63,6 +63,7 @@
<Folder Include="POUs" />
<Folder Include="POUs\AngleSequence" />
<Folder Include="POUs\AngleSequence\MatrixAccessors" />
<Folder Include="POUs\Functions" />
<Folder Include="Version" />
</ItemGroup>
<ItemGroup>
Expand Down Expand Up @@ -99,6 +100,9 @@
<Compile Include="POUs\ATAN2.TcPOU">
<SubType>Code</SubType>
</Compile>
<Compile Include="POUs\Functions\Vector3_CrossProduct.TcPOU">
<SubType>Code</SubType>
</Compile>
<Compile Include="POUs\HMatrix.TcPOU">
<SubType>Code</SubType>
</Compile>
Expand All @@ -119,7 +123,7 @@
</ItemGroup>
<ItemGroup>
<PlaceholderResolution Include="TcMatrix">
<Resolution>TcMatrix, 1.4.2 (Burks Engineering)</Resolution>
<Resolution>TcMatrix, 1.4.3 (Burks Engineering)</Resolution>
</PlaceholderResolution>
</ItemGroup>
<ProjectExtensions>
Expand Down
2 changes: 1 addition & 1 deletion TcTransform/TcTransform/Version/Global_Version.TcGVL
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
// This function has been automatically generated from the project information.
VAR_GLOBAL CONSTANT
{attribute 'const_non_replaced'}
stLibVersion_TcTransform : ST_LibVersion := (iMajor := 0, iMinor := 3, iBuild := 34, iRevision := 0, nFlags := 0, sVersion := '0.3.34');
stLibVersion_TcTransform : ST_LibVersion := (iMajor := 0, iMinor := 3, iBuild := 36, iRevision := 0, nFlags := 0, sVersion := '0.3.36');
END_VAR
]]></Declaration>
</GVL>
Expand Down
42 changes: 41 additions & 1 deletion TcTransformTest/TcTransformTest/TESTs/FB_Vector3_Test.TcPOU
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ END_VAR
<ST><![CDATA[WhenSetExpectValuesRetained();
WhenReversedExpectValuesReversed();
WhenCrossedExpectVectorOrthogonal();
WhenParallelCrossedExpectCleared();
WhenDottedExpectResult();]]></ST>
</Implementation>
<Method Name="WhenCrossedExpectVectorOrthogonal" Id="{77217c58-9dca-41bd-bf6e-dd652b36e1c1}">
Expand Down Expand Up @@ -61,6 +62,30 @@ Dot := V1.GetVector3DotProduct(V2);
// @TEST-ASSERT
AssertTrue(Dot = 14,'dot product did not work');
TEST_FINISHED();]]></ST>
</Implementation>
</Method>
<Method Name="WhenParallelCrossedExpectCleared" Id="{26b6e7b2-0fd1-05df-0e33-19e6d7a942cd}">
<Declaration><![CDATA[METHOD PRIVATE WhenParallelCrossedExpectCleared
VAR_INPUT
END_VAR
VAR
V1 : Vector3;
V2 : Vector3;
V3 : Vector3;
END_VAR
]]></Declaration>
<Implementation>
<ST><![CDATA[TEST('WhenParallelCrossedExpectCleared');
// @TEST-RUN
V1.SetFromComponents(1,0,0);
V2.SetFromComponents(1,0,0);
V3 := V1.GetVector3CrossProduct(V2);
// @TEST-ASSERT
AssertTrue(V3.IsCleared,'parallel cross product is not zero');
TEST_FINISHED();]]></ST>
</Implementation>
</Method>
Expand Down Expand Up @@ -117,7 +142,9 @@ TEST_FINISHED();]]></ST>
</Implementation>
</Method>
<LineIds Name="FB_Vector3_Test">
<LineId Id="9" Count="3" />
<LineId Id="9" Count="2" />
<LineId Id="20" Count="0" />
<LineId Id="12" Count="0" />
</LineIds>
<LineIds Name="FB_Vector3_Test.WhenCrossedExpectVectorOrthogonal">
<LineId Id="5" Count="0" />
Expand Down Expand Up @@ -145,6 +172,19 @@ TEST_FINISHED();]]></ST>
<LineId Id="24" Count="0" />
<LineId Id="23" Count="0" />
</LineIds>
<LineIds Name="FB_Vector3_Test.WhenParallelCrossedExpectCleared">
<LineId Id="5" Count="0" />
<LineId Id="7" Count="0" />
<LineId Id="6" Count="0" />
<LineId Id="10" Count="0" />
<LineId Id="17" Count="0" />
<LineId Id="21" Count="0" />
<LineId Id="18" Count="0" />
<LineId Id="11" Count="0" />
<LineId Id="19" Count="0" />
<LineId Id="24" Count="0" />
<LineId Id="23" Count="0" />
</LineIds>
<LineIds Name="FB_Vector3_Test.WhenReversedExpectValuesReversed">
<LineId Id="5" Count="0" />
<LineId Id="7" Count="0" />
Expand Down
2 changes: 1 addition & 1 deletion TcTransformTest/TcTransformTest/TcTransformTest.plcproj
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
</ItemGroup>
<ItemGroup>
<PlaceholderResolution Include="TcMatrix">
<Resolution>TcMatrix, * (Burks Engineering)</Resolution>
<Resolution>TcMatrix, 1.4.3 (Burks Engineering)</Resolution>
</PlaceholderResolution>
<PlaceholderResolution Include="TcUnit">
<Resolution>TcUnit, * (www.tcunit.org)</Resolution>
Expand Down

0 comments on commit 82810e3

Please sign in to comment.