Comments (2)
PS - I wrote the following brute force code, based on formulas from Wikipedia, to test against Angle2d and Angle3d. This code appears to give the correct answer, but it seems always to return an angle of 180 deg or less whereas Angle2d and Angle3d will return values of 360 deg or less. This code does seem to run about 50% faster than the current Angle2d and Angle3d code:
/**
* Calculate the angle at the vertex between two vectors formed by three 2d points.
*
* @param a A 2d point.
* @param vertex The vertex point.
* @param b A 2d point.
*
* @return The angle, from 0 to 2 * PI, in radians.
*/
public static double calculateAngle(Coord2d a, Coord2d vertex, Coord2d b) {
double lengthAB = Math.sqrt(Math.pow(a.x - b.x, 2) + Math.pow(a.y - b.y, 2));
double lengthAV = Math.sqrt(Math.pow(a.x - vertex.x, 2) + Math.pow(a.y - vertex.y, 2));
double lengthBV = Math.sqrt(Math.pow(b.x - vertex.x, 2) + Math.pow(b.y - vertex.y, 2));
double numerator = Math.pow(lengthAV, 2) + Math.pow(lengthBV, 2) - Math.pow(lengthAB, 2);
double denominator = 2 * lengthAV * lengthBV;
return Math.acos(numerator / denominator);
}
/**
* Calculate the angle at the vertex between two rays formed by three 3d points.
*
* @param a A 3d point.
* @param vertex The vertex point.
* @param b A 3d point.
*
* @return The angle, from 0 to 2 * PI, in radians.
*/
public static double calculateAngle(Coord3d a, Coord3d vertex, Coord3d b) {
double lengthAB = Math.sqrt(Math.pow(a.x - b.x, 2) + Math.pow(a.y - b.y, 2) + Math.pow(a.z - b.z, 2));
double lengthAV = Math.sqrt(Math.pow(a.x - vertex.x, 2) + Math.pow(a.y - vertex.y, 2) + Math.pow(a.z - vertex.z, 2));
double lengthBV = Math.sqrt(Math.pow(b.x - vertex.x, 2) + Math.pow(b.y - vertex.y, 2) + Math.pow(b.z - vertex.z, 2));
double numerator = Math.pow(lengthAV, 2) + Math.pow(lengthBV, 2) - Math.pow(lengthAB, 2);
double denominator = 2 * lengthAV * lengthBV;
return Math.acos(numerator / denominator);
}
Thanks,
Lloyd
from jzy3d-api.
Thank you Lloyd.
Looks like method angle() in Angle2d and Angle3d is not called by any class of the framework, so you might change the contract without breaking the framework.
Almost ready for a pull request? :)
from jzy3d-api.
Related Issues (20)
- Contact HOT 1
- jGL matrix inversion get full of NaN values on XZ or YZ projections
- 2D charts should support reverse axis directions
- 2D charts improvements
- Rendering hangs on macOS (crashes on Ubuntu) after few thousands of calls to render() HOT 2
- Let PERSPECTIVE projections work without needing to manually set View.factorViewPointDistance to 3.
- Constant 2D functions are not rendered
- Swing charts with a translucent surface let the previous view content appear under the surface
- Enabling 2D views in Jzy3D App prevent from enabling the 3D view later
- Can't run demos on M1 HOT 1
- Add LWJGL as alternative OpenGL binding to EmulGL and JOGL
- Allow hiding dashed lines of the axis cube from the axis layout
- Allow rendering dashed lines with smoothLine setting on M1 HOT 1
- Add triangle tesselator
- Screenshots of AWT Canvas on Win10 are not scaled on HiDPI screens
- Tooltips and post renderers aren't scaled properly when {AWT, Win10, Java9+, HiDPI}
- 2D overlay : EmulGL and native should have the same code when dealing with HiDPI HOT 1
- Volume Visualization issue : can't bind texture HOT 1
- Test and bump to the new JOGL 2.4.0
- Fatal Error Log using DrawableVBO HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jzy3d-api.