calculate sqrt using nested intervals in c [closed] - c

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 months ago.
Improve this question
I have to write a script in C where the sqrt of an positive number is calculated using nested intervals and call by reference (no structs or math.h allowed)
I tried for like 5 days but I'm kina depressed now. Can anyone help?

I can show you how to calculate the square root of 5. From there you'll know what to do:
First, you know that the square root of a number is generally smaller than the number itself, so you start with the interval [0,5], and you calculate the middle (which is 2.5, whose square is 6.25. So, the square root of 5 should be between 0 and 2.5. So you get:
interval : [0, 2.5]. Middle=1.25. Square(middle)=1.5625. Square(middle)<5 => this becomes the lower bound:
interval : [1.25, 2.5]. Middle=1.875. Square(middle)=±3.5. Square(middle)<5 => this becomes the lower bound:
interval : [1.875, 2.5]. ...

Related

Azure Maps - How to increase the max text size/avoid word wrap? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
When I create a symbol layer the text field is wrapped if the text becomes too long. I'm not able to figure out why/when the text is to long. It seems to depend on different things e.g. font type, text size and text length.
I tested the text length by using this example code. I replace Cafeteria with the alphabet with space between each character. It then wraps to a second line between m and n and that's to few letters on one line for our use case. https://azuremapscodesamples.azurewebsites.net/Symbol%20Layer/Formatted%20text%20field.html
I have been working with mapbox. They have a setting "text-max-width" that solves this issue.
I have checked the javascript code that comes with the npm package azure-maps-control and it doesn't implement support for "text-max-width".
Do anyone know how to fix the wrapping issue or if the package azure-maps-control are going to implement support for the "text-max-width" setting?
There is no option for this today, but I've added it to the feature request list. As a work around, you could do the following:
var layer = new atlas.layer.SymbolLayer(datasource);
map.map.setPaintProperty(layer.getId(), 'text-max-width', 15);

Model 3D spring from points [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
I have generated points like this and now I what to connect all these points into one model - spring. How can I achieve this? I've tried iterating through each point and build it from polygons or triangles but I have failed.
I have set of rings where each ring was build from points which coords I have.
You probably want to treat these as generalized cylinders and tessellate a triangle mesh. This can be done by sweeping a circle along the path. Some of the details are tricky since undefined tangents can lead to unexpected twists in your triangle mesh. You might want to study the GLE library or the TubeGeometry implementation in ThreeJS.
For simplestic rendering, note that OpenGL has GL_LINE_STRIP. It also has glLineWidth, although many platforms have a max width of 1. You would need to take care to use separate draw calls for seperate springs, otherwise they'll be connected.

Writing a law of cosines calculation [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 years ago.
Improve this question
I'm trying to make a function in C that returns the length of the side of a triangle that is opposite to a given angle, using the Law of cosines.
Now I got the formula to work in excel and it gave the correct results. However when I tried it in C I am getting the wrong results, and I can not work out why.
For the test I have sideA as 21.1, sideB as 19 and the angle between them as 40 degrees. Now the answer should be 14.9 like I get in excel. however in C I'm getting 23.735. Please some one help me work out where I went wrong
// Find the length of a side of a triangle that is oppisit a given angle using the Law Of Cosine
// for example using an triangle that is 21.1cm on one side, 19 cm on the other and an angle of 40 degreese inbetween then....
// in excel it worked and the formuler was =SQRT(POWER(23.1;2)+POWER(19;2)-2*(23.1)*(19)*COS(40*(3.14159/180))) = 14.9 cm
float my_Trig_LawOfCos_OppSideLength(float centerAngle, float sideA, float sideB)
{
float sideLengthPow2= (pow(sideA,2) + pow(sideB,2))) - ((2*sideA*sideB)*cos(centerAngle*(3.14159/180));
float sideLength = sqrt(sideLengthPow2);
return sideLength;
}
This happens if you pass the arguments in the wrong order. You put the side length 23.1 in the position of the angle.
def oppside(ang, lA, lB): return (lA**2+lB**2-2*(lA)*(lB)*cos(ang*(pi/180)))**0.5
oppside(40,19,23.1)
>>> 14.905575729577208
oppside(19,23.1,40)
>>> 19.65430416708927
oppside(23.1,19,40)
>>> 23.72490935854042
Quite often you can find such errors by producing a minimal executable example that shows the wrong result, because then you would also document the erroneous function call (and perhaps even see it for yourself).

How to implement bit error based on percentage in C? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I'm stuck at trying to simulate an Binary Symmetric Channel in C.
It should work like this: the user enters a number (for example 0.01 = 1%) which represents error rate. So, for instance, if i read 1001 from file every bit has a chance to change its value to 0/1 respectively depending on the entered percent.
Reading from file and writing into another is already working, but I just don't know how to make these percentage-based errors happen.
Any help is much appreciated, thanks in advance.
For generating the percentage-based error, you could do something like this:
double rate = get_rate(); // userinput between 0.0 and 1.0 for 0% - 100%
do {
double nr = drand48(); // Generates a number between 0.0 and 1.0
if (nr < rate) {
// Generate biterror here
}
} while (some_more_bits_to_check);

Camera calibration across multiple images [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
Taking one camera and moving it around to take two images of the same object, from a different viewpoint, one should be able to compute a matrix that relates these two scenes. In OpenCV, how is this accomplished?
If said object is a calibration pattern like the chessboard used by OpenCV, then the camera calibration routine mentioned by ChrisO would give you both the camera intrinsics (focal length, principal point, and lens distortion) as well as the camera extrinsics (where they are relatively in space).
If you have general object, then you need to establish a set of 2D correspondences which you can feed into cvFindFundamentalMat. This finds the fundamental matrix which relates the two perspectives. Namely, for each point x in camera 1 and corresponding point x' in camera 2, x'Fx = 0. You can similarly find the epipoles, etc. This uses the 8 point algorithm which requires at least 8 point pairs of point correspondences.
You can get the correspondences either manually or with a robust feature extractor and matcher along the lines of MSER/Affine Harris + SIFT.

Resources