-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
22 changed files
with
173 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,10 @@ | |
/.nb-gradle/ | ||
VVecMath.iml | ||
|
||
/.classpath | ||
/.vscode | ||
/.project | ||
/.settings | ||
|
||
/bin | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,9 +10,8 @@ apply plugin: 'java' | |
apply from: 'gradle/publishing.gradle' | ||
|
||
|
||
task wrapper(type: Wrapper) { | ||
gradleVersion = '4.9' | ||
distributionUrl = "https://services.gradle.org/distributions/gradle-$gradleVersion-all.zip" | ||
wrapper { | ||
gradleVersion = '5.4' | ||
} | ||
|
||
apply plugin: 'java' | ||
|
@@ -30,7 +29,7 @@ repositories { | |
} | ||
|
||
dependencies { | ||
testCompile group: 'junit', name: 'junit', version: '4.11' | ||
testCompile group: 'junit', name: 'junit', version: '4.12' | ||
} | ||
|
||
|
||
|
@@ -43,7 +42,7 @@ license { | |
groovy = 'SLASHSTAR_STYLE' | ||
fxml = 'XML_STYLE' | ||
} | ||
ext.year = '2018' | ||
ext.year = '2019' | ||
ext.author = 'Michael Hoffer <[email protected]>' | ||
exclude '**/*.svg' | ||
} | ||
|
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
distributionBase=GRADLE_USER_HOME | ||
distributionPath=wrapper/dists | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-4.9-all.zip | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-5.4-bin.zip | ||
zipStoreBase=GRADLE_USER_HOME | ||
zipStorePath=wrapper/dists |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/* | ||
* Copyright 2017-2018 Michael Hoffer <[email protected]>. All rights reserved. | ||
* Copyright 2017-2019 Michael Hoffer <[email protected]>. All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without modification, are | ||
* permitted provided that the following conditions are met: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/* | ||
* Copyright 2017-2018 Michael Hoffer <[email protected]>. All rights reserved. | ||
* Copyright 2017-2019 Michael Hoffer <[email protected]>. All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without modification, are | ||
* permitted provided that the following conditions are met: | ||
|
@@ -32,7 +32,6 @@ | |
* authors and should not be interpreted as representing official policies, either expressed | ||
* or implied, of Michael Hoffer <[email protected]>. | ||
*/ | ||
|
||
package eu.mihosoft.vvecmath; | ||
|
||
import static eu.mihosoft.vvecmath.StoredVector3d.getStructSize; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/* | ||
* Copyright 2017-2018 Michael Hoffer <[email protected]>. All rights reserved. | ||
* Copyright 2017-2019 Michael Hoffer <[email protected]>. All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without modification, are | ||
* permitted provided that the following conditions are met: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/* | ||
* Copyright 2017-2018 Michael Hoffer <[email protected]>. All rights reserved. | ||
* Copyright 2017-2019 Michael Hoffer <[email protected]>. All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without modification, are | ||
* permitted provided that the following conditions are met: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/* | ||
* Copyright 2017-2018 Michael Hoffer <[email protected]>. All rights reserved. | ||
* Copyright 2017-2019 Michael Hoffer <[email protected]>. All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without modification, are | ||
* permitted provided that the following conditions are met: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/* | ||
* Copyright 2017-2018 Michael Hoffer <[email protected]>. All rights reserved. | ||
* Copyright 2017-2019 Michael Hoffer <[email protected]>. All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without modification, are | ||
* permitted provided that the following conditions are met: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/* | ||
* Copyright 2017-2018 Michael Hoffer <[email protected]>. All rights reserved. | ||
* Copyright 2017-2019 Michael Hoffer <[email protected]>. All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without modification, are | ||
* permitted provided that the following conditions are met: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/* | ||
* Copyright 2017-2018 Michael Hoffer <[email protected]>. All rights reserved. | ||
* Copyright 2017-2019 Michael Hoffer <[email protected]>. All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without modification, are | ||
* permitted provided that the following conditions are met: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/* | ||
* Copyright 2017-2018 Michael Hoffer <[email protected]>. All rights reserved. | ||
* Copyright 2017-2019 Michael Hoffer <[email protected]>. All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without modification, are | ||
* permitted provided that the following conditions are met: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/* | ||
* Copyright 2017-2018 Michael Hoffer <[email protected]>. All rights reserved. | ||
* Copyright 2017-2019 Michael Hoffer <[email protected]>. All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without modification, are | ||
* permitted provided that the following conditions are met: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/* | ||
* Copyright 2017-2018 Michael Hoffer <[email protected]>. All rights reserved. | ||
* Copyright 2017-2019 Michael Hoffer <[email protected]>. All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without modification, are | ||
* permitted provided that the following conditions are met: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/* | ||
* Copyright 2017-2018 Michael Hoffer <[email protected]>. All rights reserved. | ||
* Copyright 2017-2019 Michael Hoffer <[email protected]>. All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without modification, are | ||
* permitted provided that the following conditions are met: | ||
|
@@ -636,4 +636,74 @@ public default Vector3d project(Vector3d v) { | |
return this.times(pScale); | ||
} | ||
|
||
/** | ||
* Indicates whether the two given points are collinear with this | ||
* vector/point. | ||
* | ||
* @param p2 second point | ||
* @param p3 third point | ||
* | ||
* @return {@code true} if all three points are collinear; | ||
* {@code false} otherwise | ||
*/ | ||
default boolean collinear(Vector3d p2, Vector3d p3) { | ||
|
||
// The points p1, p2, p3 are collinear (are on the same line segment) | ||
// if and only if the largest of the lenghts of | ||
// | ||
// a = P1P2, | ||
// b = P1P2 | ||
// c = P2P3 | ||
// | ||
// is equal to the sum of the other two. | ||
// | ||
// Explanation: | ||
// | ||
// If p1, p2 and p3 are on the same line then the point in the 'middle' | ||
// cuts the line segment into two smaller pieces. That is the sum of the | ||
// lengths of the smaller pieces is equal to the largest one. | ||
// | ||
// That is, the following expression determines whether the three points | ||
// are collinear | ||
// | ||
// boolean collinear = largest > (second + third) | ||
|
||
double a = this.distance(p2); | ||
double b = this.distance(p3); | ||
double c = p2.distance(p3); | ||
|
||
double largest; | ||
double second; | ||
double third; | ||
|
||
if (a > b && a > c) { | ||
// a is largest | ||
largest = a; | ||
second = b; | ||
third = c; | ||
} else if (b > a && b > c) { | ||
// b is largest | ||
largest = b; | ||
second = a; | ||
third = c; | ||
} else if (c > a && c > b) { | ||
// c is largest | ||
largest = c; | ||
second = a; | ||
third = b; | ||
} else { | ||
// lengths are not distinct. | ||
// | ||
// there are two possibilities: | ||
// | ||
// a: they are vertices of a equilateral triangle -> false | ||
// b: they are zero, i.e., all points are identical -> true | ||
// | ||
return a == 0 && b == 0 && c == 0; | ||
} | ||
|
||
return Math.abs(largest - (second + third)) < Plane.TOL; | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/* | ||
* Copyright 2017-2018 Michael Hoffer <[email protected]>. All rights reserved. | ||
* Copyright 2017-2019 Michael Hoffer <[email protected]>. All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without modification, are | ||
* permitted provided that the following conditions are met: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/* | ||
* Copyright 2017-2018 Michael Hoffer <[email protected]>. All rights reserved. | ||
* Copyright 2017-2019 Michael Hoffer <[email protected]>. All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without modification, are | ||
* permitted provided that the following conditions are met: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/* | ||
* Copyright 2017-2018 Michael Hoffer <[email protected]>. All rights reserved. | ||
* Copyright 2017-2019 Michael Hoffer <[email protected]>. All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without modification, are | ||
* permitted provided that the following conditions are met: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/* | ||
* Copyright 2017-2019 Michael Hoffer <[email protected]>. All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without modification, are | ||
* permitted provided that the following conditions are met: | ||
* | ||
* 1. Redistributions of source code must retain the above copyright notice, this list of | ||
* conditions and the following disclaimer. | ||
* | ||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list | ||
* of conditions and the following disclaimer in the documentation and/or other materials | ||
* provided with the distribution. | ||
* | ||
* If you use this software for scientific research then please cite the following publication(s): | ||
* | ||
* M. Hoffer, C. Poliwoda, & G. Wittum. (2013). Visual reflection library: | ||
* a framework for declarative GUI programming on the Java platform. | ||
* Computing and Visualization in Science, 2013, 16(4), | ||
* 181–192. http://doi.org/10.1007/s00791-014-0230-y | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY Michael Hoffer <[email protected]> "AS IS" AND ANY EXPRESS OR IMPLIED | ||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND | ||
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL Michael Hoffer <[email protected]> OR | ||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | ||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON | ||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | ||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF | ||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
* | ||
* The views and conclusions contained in the software and documentation are those of the | ||
* authors and should not be interpreted as representing official policies, either expressed | ||
* or implied, of Michael Hoffer <[email protected]>. | ||
*/ | ||
package eu.mihosoft.vvecmath; | ||
|
||
import org.junit.Test; | ||
|
||
import junit.framework.Assert; | ||
|
||
public class Vector3dTest { | ||
|
||
@Test | ||
public void collinearityTest() { | ||
{ | ||
Vector3d p1 = Vector3d.xyz(1,1,1); | ||
Vector3d p2 = p1.times(5); | ||
Vector3d p3 = p1.times(10); | ||
|
||
Assert.assertTrue("p1, p2, p3 must be collinear", p1.collinear(p2, p3)); | ||
} | ||
{ | ||
Vector3d p1 = Vector3d.xyz(1,1,1); | ||
Vector3d p2 = p1.times(5,5,4); | ||
Vector3d p3 = p1.times(10); | ||
|
||
Assert.assertTrue("p1, p2, p3 must not be collinear", !p1.collinear(p2, p3)); | ||
} | ||
{ | ||
Vector3d p1 = Vector3d.xyz(10,10,10); | ||
Vector3d p2 = Vector3d.xyz(-1,-1,-1); | ||
Vector3d p3 = p1.times(5); | ||
|
||
Assert.assertTrue("p1, p2, p3 must be collinear", p1.collinear(p2, p3)); | ||
} | ||
{ | ||
Vector3d p1 = Vector3d.xyz(10,20,10); | ||
Vector3d p2 = p1.clone(); | ||
Vector3d p3 = p2.clone(); | ||
|
||
Assert.assertTrue("p1, p2, p3 must be collinear", p1.collinear(p2, p3)); | ||
} | ||
} | ||
} |