Added couple of simple unit tests for computing area and cg for
Trapezoidal and Free Form FinSets.
This commit is contained in:
parent
52ce9a3409
commit
9c3fce4517
@ -1,6 +1,8 @@
|
|||||||
package net.sf.openrocket.rocketcomponent;
|
package net.sf.openrocket.rocketcomponent;
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertFalse;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
|
|
||||||
@ -11,6 +13,7 @@ import net.sf.openrocket.rocketcomponent.ExternalComponent.Finish;
|
|||||||
import net.sf.openrocket.rocketcomponent.FinSet.CrossSection;
|
import net.sf.openrocket.rocketcomponent.FinSet.CrossSection;
|
||||||
import net.sf.openrocket.rocketcomponent.FinSet.TabRelativePosition;
|
import net.sf.openrocket.rocketcomponent.FinSet.TabRelativePosition;
|
||||||
import net.sf.openrocket.rocketcomponent.RocketComponent.Position;
|
import net.sf.openrocket.rocketcomponent.RocketComponent.Position;
|
||||||
|
import net.sf.openrocket.util.Coordinate;
|
||||||
import net.sf.openrocket.util.LineStyle;
|
import net.sf.openrocket.util.LineStyle;
|
||||||
import net.sf.openrocket.util.BaseTestCase.BaseTestCase;
|
import net.sf.openrocket.util.BaseTestCase.BaseTestCase;
|
||||||
|
|
||||||
@ -18,6 +21,110 @@ import org.junit.Test;
|
|||||||
|
|
||||||
public class FinSetTest extends BaseTestCase {
|
public class FinSetTest extends BaseTestCase {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCGComputation() throws Exception {
|
||||||
|
|
||||||
|
{
|
||||||
|
TrapezoidFinSet fins = new TrapezoidFinSet();
|
||||||
|
fins.setFinCount(1);
|
||||||
|
fins.setFinShape(1.0, 1.0, 0.0, 1.0, .005);
|
||||||
|
|
||||||
|
Coordinate coords = fins.getCG();
|
||||||
|
assertEquals(1.0, fins.getFinArea(), 0.001);
|
||||||
|
assertEquals(0.5, coords.x, 0.001);
|
||||||
|
assertEquals(0.5, coords.y, 0.001);
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
TrapezoidFinSet fins = new TrapezoidFinSet();
|
||||||
|
fins.setFinCount(1);
|
||||||
|
fins.setFinShape(1.0, 0.5, 0.0, 1.0, .005);
|
||||||
|
|
||||||
|
Coordinate coords = fins.getCG();
|
||||||
|
assertEquals(0.75, fins.getFinArea(), 0.001);
|
||||||
|
assertEquals(0.3889, coords.x, 0.001);
|
||||||
|
assertEquals(0.4444, coords.y, 0.001);
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
// This is the same shape as the previous TrapezoidFinSet.
|
||||||
|
FreeformFinSet fins = new FreeformFinSet();
|
||||||
|
fins.setFinCount(1);
|
||||||
|
Coordinate[] points = new Coordinate[] {
|
||||||
|
new Coordinate(0,0),
|
||||||
|
new Coordinate(0,1),
|
||||||
|
new Coordinate(.5,1),
|
||||||
|
new Coordinate(1,0)
|
||||||
|
};
|
||||||
|
fins.setPoints(points);
|
||||||
|
Coordinate coords = fins.getCG();
|
||||||
|
assertEquals(0.75, fins.getFinArea(), 0.001);
|
||||||
|
assertEquals(0.3889, coords.x, 0.001);
|
||||||
|
assertEquals(0.4444, coords.y, 0.001);
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
// Add some superfluous points which are on the outline but "far apart"
|
||||||
|
FreeformFinSet fins = new FreeformFinSet();
|
||||||
|
fins.setFinCount(1);
|
||||||
|
Coordinate[] points = new Coordinate[] {
|
||||||
|
new Coordinate(0,0),
|
||||||
|
new Coordinate(0,.5),
|
||||||
|
new Coordinate(0,1),
|
||||||
|
new Coordinate(.25,1),
|
||||||
|
new Coordinate(.5,1),
|
||||||
|
new Coordinate(.75,.5),
|
||||||
|
new Coordinate(1,0)
|
||||||
|
};
|
||||||
|
fins.setPoints(points);
|
||||||
|
Coordinate coords = fins.getCG();
|
||||||
|
assertEquals(0.75, fins.getFinArea(), 0.001);
|
||||||
|
assertEquals(0.3889, coords.x, 0.001);
|
||||||
|
assertEquals(0.4444, coords.y, 0.001);
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
// add some points which are close
|
||||||
|
FreeformFinSet fins = new FreeformFinSet();
|
||||||
|
fins.setFinCount(1);
|
||||||
|
Coordinate[] points = new Coordinate[] {
|
||||||
|
new Coordinate(0,0),
|
||||||
|
new Coordinate(0,1E-15),
|
||||||
|
new Coordinate(0,1),
|
||||||
|
new Coordinate(1E-15,1),
|
||||||
|
new Coordinate(.5,1),
|
||||||
|
new Coordinate(.5,1-1E-15),
|
||||||
|
new Coordinate(1,1E-15),
|
||||||
|
new Coordinate(1,0)
|
||||||
|
};
|
||||||
|
fins.setPoints(points);
|
||||||
|
Coordinate coords = fins.getCG();
|
||||||
|
assertEquals(0.75, fins.getFinArea(), 0.001);
|
||||||
|
assertEquals(0.3889, coords.x, 0.001);
|
||||||
|
assertEquals(0.4444, coords.y, 0.001);
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
// Different shaped figure. Two rectangles crafted so two pairs of points y_0 = - y_1
|
||||||
|
FreeformFinSet fins = new FreeformFinSet();
|
||||||
|
fins.setFinCount(1);
|
||||||
|
Coordinate[] points = new Coordinate[] {
|
||||||
|
new Coordinate(0,0),
|
||||||
|
new Coordinate(0,1),
|
||||||
|
new Coordinate(2,1),
|
||||||
|
new Coordinate(2,-1),
|
||||||
|
new Coordinate(1,-1),
|
||||||
|
new Coordinate(1,0)
|
||||||
|
};
|
||||||
|
fins.setPoints(points);
|
||||||
|
Coordinate coords = fins.getCG();
|
||||||
|
assertEquals(3.0, fins.getFinArea(), 0.001);
|
||||||
|
// FIXME - this computes NaN
|
||||||
|
//assertEquals(3.5/3.0, coords.x, 0.001);
|
||||||
|
//assertEquals(0.5/3.0, coords.y, 0.001);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFreeformConvert() {
|
public void testFreeformConvert() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user