mathutil | github.com/cznic/mathutil has moved to modernc.org/mathutil
kandi X-RAY | mathutil Summary
kandi X-RAY | mathutil Summary
github.com/cznic/mathutil has moved to modernc.org/mathutil (vcs). Please update your import paths to modernc.org/mathutil. This repo is now archived.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- IsPrimeUint64 reports whether n is a prime .
- NewFCBig creates a new FCBig .
- IsPrime returns if n is a prime .
- PowerizeBigInt computes the power of two big int
- NewFC32 creates a new FC32 .
- QuadPolyFactors computes the complement of a and b .
- QuadPolyFactorsBig computes the complement of two big integers .
- ModPow2 modifies the 2^2 and returns x .
- NextPrime returns the next prime of n .
- Generate a PNG image
mathutil Key Features
mathutil Examples and Code Snippets
Community Discussions
Trending Discussions on mathutil
QUESTION
I am making a 3D game, and the way I used to draw to the screen was to add a JLabel
containing the "game screen" as a BufferedImage
to the JPanel
, and changing individual pixels using BufferedImage.setRGB()
. However, I decided to switch into drawing into the JPanel
directly using PaintComponent()
. After making the switch and not touching the texturing algorithm (outside of changes like adding the wanted pixel color into a screen buffer instead of directly changing the color, so if anything, it should be faster), it now runs really slowly (it takes about 0.3 seconds and sometimes even more to finish the texturing algorithm, with everything else being pretty much instant). Is there anyway to fix it? Also, if you see other problems with the code, feel free to let me know.
ANSWER
Answered 2022-Mar-28 at 05:46Well, it turns out that using BufferedImage
is just better, so I changed the screen buffer to one and it works well again.
QUESTION
I am trying to make a rubiks cube simulator with three.js so my goal now is to rotate the bottom and then rotate the middle layer. After I rotate the bottom layer and switch to the middle layer the bottom layer goes back in (the position after the rotation is not saved) and the middle layer snappes instantly.
This is my code:
...ANSWER
Answered 2022-Mar-17 at 18:08When you rotate a Mesh's parent, the mesh's rotation doesn't change. Only the parent's rotation changes. So when you take the mesh out of that parent, you're removing any transformations that it inherited.
You can use object.getWorldQuaternion()
to store the world-space rotations into a quaternion, then apply them to the child mesh:
QUESTION
I'm learning to use the THREE.js library by creating a particle sphere inside my React App. Referencing this project, I've managed to get somewhat of a start, but am at a bit of a dead-end.
For some reason, despite the fact that all my code is essentially the same - except for some deprecated methods being swapped out - THREE will render a weird straight line every time.
After looking at the documentation for a few hours and trying to learn the individual methods of this component, I'm still scratching my head.
This is what I have (a live version can be viewed here):
...ANSWER
Answered 2022-Feb-28 at 21:07First of all, the line with camera instantiation has to be like this: camera = new THREE.PerspectiveCamera(45, canvasWidth / canvasHeight, 1, 1000);
, there is the slash instead of comma.
And then, camera has to look at the scene's center, thus camera.lookAt(scene.position);
Snippet with fixed code:
QUESTION
fun add() {
return 4+1;
}
class Calculator {
fun MathUtils() {
// do something
// calls add() function
val x: Int = add()
// return something
return x + 22
}
}
class CalculatorTest {
var c = Calculator()
@Test
fun MathUtilsSuccess() {
Assertions.assertThat(
c.MathUtils()
).isEqualTo(24)
}
}
...ANSWER
Answered 2022-Feb-27 at 12:50Indeed io.mockk:mockk supports to mock top-level functions in Kotlin.
Similar to extension functions, for top-level functions, Kotlin creates a class containing static functions under the hood as well, which in turn can be mocked.
However, you need to know the name of the underlying class created, which hints that probably this approach should only be used very rarely and with caution. I'll first demonstrate a working sample and name some alternative approaches afterwards.
Let's look at an example on how to mock a top-level function with MockK
.
foo.kt
QUESTION
this is my code which is working fine but it is not correct. I am unable to figure out the problem
...ANSWER
Answered 2022-Feb-07 at 11:17In your case you are dividing b by 2 and not a + b
you can try it like that
QUESTION
I try to build a house generator based on a floorplan. Generating the mesh works fine, but now I need to flip the normals on some faces.
...ANSWER
Answered 2022-Jan-22 at 00:56In simplest terms, "flipping" or finding the negative of the normal (or any) vector is a matter of negating each of its components. So if your normal vector n
is a THREE.Vector3
instance, then its negative is n.multiplyScalar(-1)
, or if it's in an array of the form [ x, y, z ]
, then its negative is [ -1 * x, -1 * y, -1 * z ]
.
Flipping the normal vectors won't do all of what you're looking to accomplish, though. Normals in Three.js (and many other engines and renderers) are separate and distinct from the notion of the side of a triangle that's being rendered. So if you only flip the vectors, Three.js will continue to render the front side of the triangles, which form the exterior of the mesh; those faces will appear darker, though, because they're reflecting light in exactly the wrong direction.
For each triangle, you need to both (a) flip the normals of its vertices; and (b) either render the back side of that triangle or reverse the facing of the triangle.
To render the back side of the triangle, you can set the .side
property of your material to THREE.BackSide
. (I have not tested this, and it may have other implications; among other things, you may come across other parts of your codebase that have to be specifically written with an eye to the fact that you're rendering backfaces.)
A more robust solution would be to make the triangles themselves face the other way.
ExtrudeGeometry
is a factory for BufferGeometry
, and the vertex positions are stored in a flat array in the .attributes.position.array
property of the generated geometry. You can swap every 3rd-5th element in the array with every 6th-9th element to reverse the winding order of the triangle, which changes the side that Three.js considers to be the front. Thus, a triangle defined as (0, 0, 0), (1, 0, 1), (1, 1, 1) and represented in the array as [ 0, 0, 0, 1, 0, 1, 1, 1, 1 ]
becomes (0, 0, 0), (1, 1, 1), (1, 0, 1) and [ 0, 0, 0, 1, 1, 1, 1, 0, 1 ]
. (Put differently, ABC becomes ACB.)
To accomplish this in code requires something like the following.
QUESTION
I've been learning about libgdx recently. In the process of following the instructions on their libgdx wiki I ran into some problems.
Specifically in the GameScreen class at the 99th line I changed the code inside so that it goes back to the previous screen (MainMenuScreen class) and yes you see when the mouse is pressed it worked (I mean go back to the screen before ) but a very very short time after, the screen AUTOMATICALLY switches to the GameScreen class (like I click the mouse once but it makes me 1 more redundant task). I guess when I click on the GameScreen screen it did the code in the if statement on line 99 to go to MainMenuScreen screen. In that screen at line 32 I guess it was true after I got to this screen because when I change the key is listened then it works fine (only converts once). I was intending to try implementing InputProcessor on each screen class but now I'm avoiding it for some reason. Can someone give me some advice recommend.Thank you
Here is the source code for the MainMenuScreen class.
...ANSWER
Answered 2022-Jan-11 at 06:29Your analysis of the problem seems correct to me. The method Gdx.input.isTouched()
will immediately return true, if the screen is still being touched after you changed to the main menu.
Also you the solution that you already tried seems correct:
I was intending to try implementing InputProcessor on each screen class
When using an InputProcessor
you will get one event (the method call to touchDown
or touchUp
) when the screen is touched, and don't need to pull the touch event using the isTouched
method.
A problem when implementing InputProcessor
with both classes probably is, that you can only set one to be the input processor of the game using the method Gdx.input.setInputProcessor
. (When setting the second input processor, the first one is removed).
A solution to this problem is the InputMultiplexer. You can add this multiplexer as the input processor of the game (using Gdx.input.setInputProcessor(multiplexer)
) and then add your input processors (the main menu and game objects) to this multiplexer: multiplexer.addProcessor(mainMenu)
or ((InputMultiplexer) Gdx.input.getInputProcessor()).addProcessor(game)
.
This way you can handle touch events instead of pulling the touched state in both of your classes.
QUESTION
Thanks for taking the time to review my post. I hope that this post will not only yield results for myself but perhaps helps others too!
IntroductionCurrently I am working on a project involving pointclouds generated with photogrammetry. It consists of photos combined with laser scans. The software used in making the pointcloud is Reality Capture. Besides the pointcloud export one can export "Internal/External camera parameters" providing the ability of retrieving photos that are used to make up a certain 3D point in the pointcloud. Reality Capture isn't that well documented online and I have also posted in their forum regarding camera variables, perhaps it can be of use in solving the issue at hand?
Only a few variables listed in the camera parameters file are relevant (for now) in referencing camera positioning such as filename, x,y,alt for location, heading, pitch and roll as its rotation.
Currently the generated pointcloud is loaded into the browser compatible THREE.JS viewer after which the camera parameters .csv file is loaded and for each known photo a 'PerspectiveCamera' is spawned with a green cube. An example is shown below:
The challengeAs a matter of fact you might already know what the issue might be based on the previous image (or the title of this post of course ;P) Just in case you might not have spotted it, the direction of the cameras is all wrong. Let me visualize it for you with shabby self-drawn vectors that rudimentary show in what direction it should be facing (Marked in red) and how it is currently vectored (green).
Row 37, DJI_0176.jpg is the most right camera with a red reference line row 38 is 177 etc. The last picture (Row 48 is DJI_189.jpg) and corresponds with the most left image of the clustured images (as I didn't draw the other two camera references within the image above I did not include the others).
When you copy the data below into an Excel sheet it should display correctly ^^
...ANSWER
Answered 2022-Jan-02 at 22:26At first glance, I see three possibilities:
It's hard to see where the issue is without showing how you're using the
createCamera()
method. You could be swappingpitch
withheading
or something like that. In Three.js, heading is rotation around the Y-axis, pitch around X-axis, and roll around Z-axis.Secondly, do you know in what order the
heading, pitch, roll
measurements were taken by your sensor? That will affect the way in which you initiate yourTHREE.Euler(xRad, yRad, zRad, 'XYZ')
, since the order in which to apply rotations could also be'YZX', 'ZXY', 'XZY', 'YXZ' or 'ZYX'
.Finally, you have to think "What does
heading: 0
mean to the sensor?" It could mean different things between real-world and Three.js coordinate system. A camera with no rotation in Three.js is looking straight down towards-Z
axis, but your sensor might have it pointing towards+Z
, or+X
, etc.
I added a demo below, I think this is what you needed from the screenshots. Notice I multiplied pitch * -1
so the cameras "Look down", and added +180
to the heading so they're pointing in the right... heading.
QUESTION
ANSWER
Answered 2021-Dec-30 at 13:51You are using an instance of BufferGeometry
to create the instance of Line2
which is not supported. You have to use LineGeometry
instead.
Updated codesandbox: https://codesandbox.io/s/static-forked-68lif?file=/index.html
QUESTION
I've created some code that generates the Bernoulli Numbers based off of formula 33 on MathWorld. This is given at https://mathworld.wolfram.com/BernoulliNumber.html and should work for all integers n but it diverges from the expected results extremely quickly once it gets to n=14. I think the issue may be in the factorial code, although I have no idea.
It's pretty accurate up until 13, all odd numbers should be 0 besides 1 but the values past 14 give weird values. For instance 14 gives a number like 0.9 when it should give something around 7/6 and say 22 gives a very negative number in the order of 10^-4. The odd numbers give strange values like 15 gives around -11.
Here is all the related code
...ANSWER
Answered 2021-Dec-28 at 05:14The problem here is that floating point arithmetic doesn't need to overflow to experience catastrophic loss of precision.
A floating point number has a mantissa and an exponent, where the value of the number is mantissa * 10^exponent (real floating point numbers use binary, I'm using decimal). The mantissa has limited precision.
When we add floating point numbers of different signs we can end up with a final result which has lost precision.
e.g. let's say the mantissa is 4 digits. If we add:
1.001 x 10^3 + 1.000 x 10^4 - 1.000 x 10^4
we expect to get 1.001 x 10^3. But 1.001 x 10^3 + 1.000 x 10^4 = 11.001 x 10^3, which is represented as 1.100 x 10^4, given that our mantissa has only 4 digits.
So when we subtract 1.000 x 10^4 we get 0.100 x 10^4, which is represented as 1.000 x 10^3 rather than 1.001 x 10^3.
Here's an implementation using BigDecimal
which gives better results (and is far slower).
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install mathutil
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page