C :: Calculating Distance Between Two Points (x And Y Vars)

Feb 23, 2013

As homework we were assigned to enter the following code to calculate the distance between two points on the x and y plane. The program should ask the user to enter two points then should calculate the distance between two points and print the distance on the screen.

My program will compile correctly but when attempting to run the actual program it doesnt do anything and some how completely skips over my main function...

Code:

#include <stdio.h>
#include <math.h>
struct point {
float x;
float y;

[Code] ....

View 2 Replies


ADVERTISEMENT

C++ :: Distance Between 2 Points Equation

Apr 14, 2013

Write a program that creates the output shown in the Output Layout section below. The program should create 2 points with x and y coordinates as integers, prompt the user to input the x and y values for one of the points and randomly set the other (-99 to 99 range) and output the length of the radius line segment and the area of the circle that radius defines. The program should then end. Include an SDM for the program and any other appropriate documentation.

Special Calculations:
Distance between 2 points equation:
√((p0x – p1x)2 + (p0y – p1y)2) (This requires use of the math library)

Output Layout: (bold text represents user input)

Please enter the location of your first point.
Enter a value from -99 to 99 for your x coordinate: -2
Enter a value from -99 to 99 for your y coordinate: 17

The location of your second randomly set point.
Your x coordinate: 45
Your y coordinate: -89

The length of the radius line segment from point one to point two is 115.
The area of the circle with a radius of 115 is 41546.33.

Other:

int pAx;
int pAy;
int pBx;
int pBy;

View 3 Replies View Related

C++ :: Calculate Distance Between Two Points

May 15, 2014

It ougth to calculate the distance between two point (p1,p2)

"main.cpp"
#include "distancia.h"
void main () {
Point p1,p2;

[code]....

View 4 Replies View Related

C++ :: Closest Distance 2D Points?

Oct 29, 2014

In the following code I don't understand why am I splitting the y left and y right.

(closest distance between 2 points in 2D)

Am I splitting the y left and y right so that I can concatenate them afterwards and then build the strip,only according to these concatenated halves ?

PS : Finding the min. distance between sorted x right and x left works fine , only problem is with the strip.

#ifndef CLOSESTPAIR_H_
#define CLOSESTPAIR_H_
#include <float.h>
#include <math.h>
typedef struct Point2D {
double x;
double y;

[code].....

View 4 Replies View Related

C++ :: Calculate Midpoint And Distance Between Two Points

Sep 25, 2013

I'm creating a quick program to calculate midpoint and distance between two points. I'm having a little trouble. This is the program:

//This program is a start to solve basic coordinatre plane distances and midpoints
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
using namespace std;
int main(int nNumberofArgs, char* pszArgs[]){
cout << "This is a calculator to find distance and the midpoint between two points. " ;

[Code]...

the problem is that the output for both equations is wrong, it doesn't do the math properly and I assume it has to do with the variable types I'm using but am not sure. P.S. I am using the latest version of DEV-C++

View 12 Replies View Related

C++ :: Function That Calculates Euclidean Distance Between Two Points

Feb 24, 2015

I am trying to write a function that calculates the Euclidean distance between two points described by
π‘‘π‘–π‘ π‘‘π‘Žπ‘›π‘π‘’ = √(π‘₯1 βˆ’ π‘₯2)2 + (𝑦1 βˆ’ 𝑦2)2
Input Prompt
Enter x1, y1, and x2, y2:
Output Prompt
The distance is XXXX.XXX

Replace XXXX.XXX with the calculated distance precise to three decimal points.

Will this be a smilier input to the same forum that wasted posted a few years ago on this site?

Here is the link... [URL]..

View 2 Replies View Related

C++ :: Calculating Distance - Cannot Find Directories

Oct 5, 2013

[URL] ....

I've been getting these errors on two computers through four different compilers. It seems the directories arnt set up. If that's the cause, I have no clue how to resolve that.

Its a very simple prog too; it just calculates a dist, using dist formula.

#include <cstdlib>
#include <iostream>
#include <math.h>
using namespace std;
void calcDistance (int x1, int y1, int x2, int y2);

[Code] ....

View 6 Replies View Related

C++ :: Program To Find Actual Distance Between Two Points On A Grid

Jul 3, 2013

Currently I am working on a program that will find the actual distance between two points on a grid. It also determines the angle of the line segment in degrees. Now, i need it to be able to find any other points on or near the line. It will be running in a loop to find each additional point sequentially until all the points have been plotted. Unfortunately, I am not entirely sure how this is done. So far, I think that I could develop an algorithm that converts the angle into a ratio of vertical movements to horizontal ones.

View 7 Replies View Related

C :: Calculate Distance Between Two Latitude And Longitude Points - Conflicting Types For Function

Mar 6, 2015

In my project i need to calculate the distance between two lattitude and longitude points. After compiling the code I am getting an error that "conflicting types for deg2rad". How to solve this? Seems the code looks ok. but...

Code:
#include <math.h>
#define pi 3.14159265358979323846
double distance(double lat1, double lon1, double lat2, double lon2, char unit) {
double theta, dist;

[Code] .....

View 4 Replies View Related

C++ :: Does Int Vars Automatically Get Assigned (0)

Feb 13, 2015

I am wondering if integers and unsigned integers automatically assigned to zero (0) upon declaration like so:

bool randomFunction() {
int i;
if (i == 0) {
return true; //Will most modern compilers return true here?
} else {
return false;
}
}

I am just curious as I have always initialized my ints/unsigned ints variables. Would save me a lot of typing if I didn't have to do this all of the time.

I know that floats and doubles you still have to initialize.

View 4 Replies View Related

C/C++ :: Find Maximal Points Among Given N Points

Nov 3, 2014

Example: In a 2-D space, point A=(a1,a2) is bigger than point B=(b1,b2), if a1>b1 and a2>b2.

How do I write a presudo code to find all the maximal points among the given n points?

View 14 Replies View Related

C :: How To Do Euclidian Distance

May 22, 2013

how would i go about writing up an equation for euclidian distance using c language. I am quite unfamiliar with the syntax's involved using squared and square roots.the equation for euclidian distance is: square root((Xv -Xu)^2 + (Yv-Yu)^2 +(Zv-Zu)^2)

The variables Xv, Yv and Zv represent the equation of vector 1 and then variables Xu, Yu and Zu represent the equation of vector 2. I have already put these into my program and i just need to know how to write that equation up there into the text file so that it works.

View 4 Replies View Related

C++ :: Manhattan Distance Between Two Vectors

Mar 25, 2014

I can't figure out the error in this code; it compiles but returns rubbish.

serge
#include <iostream>
#include <iterator>
#include <vector>
#include <algorithm>

[Code] ......

View 7 Replies View Related

C++ :: Relation Between Local Position And Distance

Feb 21, 2014

i have two point P1 and P2 where i want to move P1 and P2 with keeping the distance and the position of the P2 relative to P1 i thought that when i keep the distance between the two point that involve keep in the same time the local position of P2 but when tested it does not work initial position of P1=(10.0f, 00.0f, 00.0f) initila position of P2 relative to p1 =(50,10,-8) we can get the global position of p2 ----- final position of P1 =(50,10,-8) final position of P2 in the world space =(40.31,8.06,-6.45) then we calculate the distance before and after we found that there are equal but when we calculate the position of p2 relative to p1 after and before we found that there are not equal.

how i can keep the local position and distance ?

View 14 Replies View Related

C++ :: Display A Table With Seconds And Distance

Mar 4, 2014

I am trying to write a program that will display a table with "seconds" and "Distance". Where Seconds goes from 1-12 and the distance is displayed according to each second. However I am having trouble getting the distance variable to display any values. By the way I am also using a second function in this program besides main(), called FallingDistance(). Below is my code for the program so far.

#include <iostream>
using namespace std;
double FallingDistance(int, double);
int main() {
int Seconds;
double Distance=0;
int distance;

[Code].....

View 6 Replies View Related

C++ :: Find Distance Of 3 Dimensional Bodies

Nov 7, 2014

I am trying to find the distance of 3 dimensional bodies. I am able to find the two bodies furthest from each other, but i cannot find the bodies closest to each other.

it displays 0(it's body to itself). is there a way to negate the program from comparing it to itself?

The program works but it always find the closest body as itself. Part of the program.

for(int l=0; l<size; l++){
cout<<s[l].getName()<<endl;
int smallest=0;
for(int q=1;q<size;q++){

[Code] .....

View 1 Replies View Related

C :: Recursion For Finding Distance Between Root And Leaf?

Jun 19, 2013

I wrote the following recursion for finding the distance between a root and a leaf, but am not quite sure how to make it work.

Code:
int calc_depth(Node* tree, Node* zero) {
if (!tree)
return 0;
if (zero->right || zero->left == tree)
return 1;
return (zero->right ? calc_depth(tree, zero->right) : calc_depth(tree, zero->left));
}

View 14 Replies View Related

C/C++ :: Calculate Euclidean Distance To Origin For Each Point?

Apr 21, 2014

Calculate the Euclidean distance to the origin for each point in parallel on GPU.Assume that for each point i, its coordinate is X[i],Y[i] and given 1000000 points on 2d plane

[//
#include <iostream>
#include <stdio.h>
#include <cuda.h>
#include <assert.h>

[Code].....

View 1 Replies View Related

C/C++ :: Unable To Find The Distance Between Two Void Pointers

Jul 13, 2014

I am trying to find the distance between two void pointers, so I can follow this distance to a certain pointer in a vector when given only the previous element in that vector.

int distance = (char*) prev - (char*) first;
next = (char*) cv->elems + cv->elemsz + distance;

Basically, prev and first are void pointers. I am trying to cast them into a char, subtract the first element in the vector from the previous one, and then use this distance to determine what the next element in the vector is. However, it is not working. I am not sure how to do this. To complicate matters, prev is a const void *.

View 7 Replies View Related

C/C++ :: Using Values From Distance Array In Function To Be Used For Calculations

Mar 30, 2014

I know that the issue is around the array distance being of type double in the function get distance of type double. My question is how do i get around using the values from the distance array in the function to be used for calculations.

#include <stdio.h>/* initialization of preprocessor directives*/
#include <stdlib.h>
#include <math.h> /*preprocessor directive in order to use sqrt function*/
int calcSecondsvar(int,int,int ,double);
double getdistance(double,double,int,int,int);

[Code] ....

I forgot to mention that it keeps giving me the error cannot convert from 'double[8] to 'double' ....

View 2 Replies View Related

C# :: How To Assign Distance Values To Fixed Graph

Apr 28, 2014

I'm working on a Dijkstra's algorithm with a fixed graph. My question is, how should I go about assign distance values to the graph. The user can start from any node.

View 4 Replies View Related

Visual C++ :: Closest Distance Between Two Line Segments

Oct 29, 2014

Any good algorithm for calculating the closest points/distance between two line segments? I use some pretty general code: [URL] ....

which seems widely used and advertized on the web and works in most cases but seems to often fail horribly when line segments are nearly parallel. I've been messing with the SMALL_NUM value for division overflow to no avail. The calculated distance can still vary widely when nearly parallel.

I managed to isolate a specific incident where this happens in my code. The distance between segments P1P2 and Q1Q2 changed abruptly in one timestep from 1.05 mm to 0.90 mm (yarn radius = 1 mm), causing abrupt compression spikes. In reality the distance in the original timestep is definitely also around 0.90 mm but is not calculated as such. I find that the values of s and t (s=0 for P1, 1 for P2, t=0 for Q1, 1 for Q2) for the closest points are originally 0 and 0 (as well as in the previous time steps) and then change abruptly to 0 and around 0.29 in the new time step. What it should be, I still need to check out.

P1 = (0.012711 ,-0.000688 ,-0.001097);
P2 = (0.012895 ,-0.000686 ,-0.001133);
Q1 = (0.012676 ,-0.000689 ,-0.000999);
Q2 = (0.012859 ,-0.000687 ,-0.001034);

P1new = (0.012712, -0.000689, -0.001095);
P2new = (0.012895, -0.000687, -0.001131);
Q1new = (0.012676, -0.000690, -0.000996);
Q2new = (0.012859, -0.000688, -0.001032);

Results when calculating self contact of 15000 line segments in a few tens of fibers, one big mess:

Any better algorithm/corrections?

View 1 Replies View Related

C++ :: Binary Search Tree (Distance From Node To Root)

Jul 28, 2014

I have my tree, and I need to find the number in the tree (given by the user) and get the distance between the node found and the root.

What I've done so far is this, but I don't think it's correct.

void BinarySearchTree::find() {
system("cls");
BinarySearchTree b;
int num;
tree_node* cur;

[Code] ....

I founded the node, but I don't know how to determine the distance.

View 3 Replies View Related

C++ :: Specific Iterator Type - Find Distance By Simple Subtraction

Sep 24, 2014

I have a templated container that defines a forward iterator.

Calling std::distance on these iterators will generate code that will count the number of iterations it takes to get from the first parameter to the second, by repetitively incrementing.

Internally, the iterators can easily find the distance by a simple subtraction.

What I want to do is overload std::distance for these iterators so that it will take advantage of the simple calculation rather than repetitive increments.

The simple solution of course would be to make the iterators random access, but this would require that they support functionality that is not 'logical' for the container. Access to the container only makes logical sense when iterating one item at a time in the forward direction.

Code:
#include <iterator>
template <typename T>
class Container {
public:
class iterator : public std::iterator<std::forward_iterator_tag, T> {

[Code] .....

View 2 Replies View Related

C++ :: Parabolic Shot Program - Calculate And Graph Time Vs Distance

Nov 13, 2013

It is supposed to calculate and graph time vs. distance. The problem I have is graphing, if I put too small values for Vi, which is the initial velocity, it just graphs one or two points, because t is too small. I already tried to adjust t with 'if(t<10) t=t*10; if (t>100) t=t/10;', But it seems not to solve my problem.

Other truble I have is that, as the graph is parabola, core values ​​are very close together, and when plotted, these values ​​are in the same line on the screen.

Here is my code:
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main() {
float x, y, hmax, t, amax, vi, v, a, b, g, ang; /*x= x coordinate, y= y coordinate, hmax= maximum height,

[Code] .....

View 6 Replies View Related

C++ :: Angle Between Two Points

Apr 19, 2014

i'm working on a robotics project, to move the robot from it's current position to target position i need to calculate the angle first before i can move the robot.this the code I use to calculate the angle:

double cal_angle ( int current_x , int current_y , int tar_x , int tar_y )
{
return atan2(tar_y - current_y, tar_x - current_x);
}
int main ()

[code]....

as u can see the angle between x4,y4 to x1,y1 should be 3.14 (180)however , the result are correct as long as the distance from the current position to target position > 1 (not sure actually).

View 2 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved