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


ADVERTISEMENT

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 :: Check If Two Line Segments Intersect

Feb 8, 2013

I've written some code below to check if two line segments intersect and if they do to tell me where. As input I have the (x,y) coordinates of both ends of each line. It appeared to be working correctly but now in the scenario where

line A (532.87,787.79)(486.34,769.85)
and
line B (490.89,764.018)(478.98,783.129)

it says they intersect at (770.136, 487.08) when the lines don' intersect at all.

Code:
dy[0] = y2 - y1;
dx[0] = x2 - x1;
dy[1] = y4 - y3;
dx[1] = x4 - x3;

m[0] = dy[0] / dx[0];
m[1] = dy[1] / dx[1];
b[0] = y1 - m[0] * x1;
b[1] = y3 - m[1] * x3;

[Code] ....

View 7 Replies View Related

Visual C++ :: Finding Value In Data File Closest To Calculated Data?

Jan 11, 2014

I'm reading from a file the middle column of data (Volts) where my test file "AP.txt" is opened by my program. Here is a segment of the data:

time Volts dV
49552 -66.20183 -0.01556807
49553 -67.76025 -0.01556495
49554 -69.30704 -0.01533247
49555 -70.81799 -0.0148486
49556 -72.26774 -0.0141133
49557 -73.63226 -0.01315276
49558 -74.89141 -0.01201764

Since the calculation I performed gives me -71.77 Volts, I need to match this value to the time that this occurs closest to using my program, and output the time that this occurs at.

Here is my program so far:
int main()
{
std::ifstream inFile;
inFile.open("AP.txt");
ofstream results_file ("maxvaluewithinput.txt");
float TimeAtdVMax = 0;
float VoltsAtdVmax = 0;

[Code]...

If you're curious, this program isn't for homework. It's part of the independent learning on C++ I'm doing for a Master's Thesis; the program will eventually model the APD90 of a ventricular action potential.

View 10 Replies View Related

Visual C++ :: Line Graph Using Single Line Values From Bitmap

Feb 3, 2014

I was loaded a bmp file in my mfc window and stored rgb data in a file.My image size is 320x240.

Is possible to pick a single point (location) from that bmp image (Not the whole window)?

i like to plot a line graph using the pointed single line data using the stored file data?

here R is X Axis and G & B is Y Axis.

If i have 2D array of data means how can i plot the line graph?

View 4 Replies View Related

C :: How To Delete Number And Find Closest

Aug 3, 2014

Write a function which takes string of integer numbers and length of a string. Function need to return value of element which is close to mean of all numbers and transform string without that element. If are more numbers in same "distance" of mean, function need to find first and throw that number-element.

In function without []..
with pointers.

I wrote this code below, programm find mean of elements and if mean is equal to any element of string.. the programm return that number. Idk how to delete that number and how to find closest.. for ex:

String=[4,7,10,3]
sum=24
mean=6

The progoramm need to delete 7 and new string look like String=[4,10,3]

insert Code:
#include <stdio.h>
int main()
{
int n,i;
printf("Elements of string ?

[Code]....

View 9 Replies View Related

C# :: Find Closest Star To The Earth

Apr 19, 2015

Consider a coordinate system for the Milky Way, in which the Earth is at (0; 0; 0). Model stars as points, and assume distances are in light years. The Milky Way consists of approximately 1012 stars, and their coordinates are stored in a file in comma-separated values (CSV) format one line per star and four fields per line, the first corresponding to an ID, and then three floating point numbers corresponding to the star location. How would you compute the k stars which are closest to the Earth? You have only a few megabytes of RAM.

View 1 Replies View Related

C :: Find Closest Upper Value In Array For Any Input Int

Jul 29, 2013

I have this array (assume sorted) and i need to find out the closest upper value for any input int. Example:

Code:

/* bsearch example */
#include <stdio.h> /* printf */
#include <stdlib.h> /* qsort, bsearch, NULL */

int compareints (const void * a, const void * b) {
return ( *(int*)a - *(int*)b );

[Code] ....

So whenever i hit something that is not in the array i would like to know the closes upper value. So for 4 closest upper value is 5, then for 8 it is 12 , for 35 it is 44. how would one do this?

View 1 Replies View Related

C/C++ :: Find Closest Arrival And Departure Times?

Nov 13, 2014

I suspect it is a logical error but I can't pinpoint it. The assignment is to input a time of day in 24 hour format, pattern match with scanf, and print out the closest arrival and departure times for that time. The arrival and departure times are in minutes past midnight in a constant array. I am getting no bugs but the program is not giving correct values.

/* filename: hw25.c
* Purpose: Finds the closest arrival and departure times
*/
#include <stdio.h>
#include <stdlib.h>
#define N 8
#define HOUR 60
void find_closest_flight(int desired_time, int *departure_time, int *arrival_time);

[code]....

View 11 Replies View Related

C :: How Can A Multi-line String Be Read Line By Line

Mar 7, 2014

How can a mulitline string be read line by line

ex: str = "PERIOD="week"
DAY="day"
TIME="time"";

View 2 Replies View Related

Visual C++ :: Parsing A Line For Words?

Sep 21, 2013

I'm getting this when I compile my program. Then, when the program runs I get an error. I assume it is because I have the warning for this problem. How can get around this error.

warning C4172: returning address of local variable or temporary

Code:

#include <iostream>
#include <cstring>
using namespace std;

[Code]....

View 10 Replies View Related

Visual C++ :: CButton Surrounded With A Red Line

Jul 17, 2013

i am trying to do a button with red line around it, i don't know exactly how do it.

i am understanding i need to take the DC with GetDC and i have to use a pen, but i cannot see any red line.

View 7 Replies View Related

Visual C++ :: Replace Particular Line In A File

Jun 29, 2013

I want to read a file and replace a particular line in a file.

Ex:

temp.txt file contains below

FilePath1: xxxxxxxxxxxxxxxxxxxxxxxxx
FilePath2: xxxxxxxxxxxxxxxxxxxxxxxxx
FilePath3: xxxxxxxxxxxxxxxxxxxxxxxxx
Mode: 1

Here My requirement is replace the 4th line Mode: 2 instead of Mode: 1.

I was used seek method like below,

Code:
CStdioFile SaveFile;
CString strFilePath;
strFilePath = _T("C:Sara emp.txt");
if (SaveFile.Open(strFilePath, CFile::modeCreate | CFile::modeNoTruncate | CFile::modeReadWrite), &fileException) {

[Code] ....

The above code not working correctly.

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

Visual C++ :: Printing 2 Arrays With 10 Numbers Per Line

Jan 14, 2014

i got 2 arrays, how would i print 10 numbers per line, so that would be 5 numbers from each array.

array1[40];
array2[40];

array1 array2// array1 array2// array1 array2 // array1 array2 // array1 array2
array1 array2// array1 array2// array1 array2 // array1 array2 // array1 array2
array1 array2// array1 array2// array1 array2 // array1 array2 // array1 array2

...... and so on

how can i put this in a loop?

and so on but there are 80 elements so i cant go one by one.

View 5 Replies View Related

Visual C++ :: Command Line Arguments To The Linker?

Sep 15, 2012

Code:

/** Add a feature to a (mutable) LV2 feature array. */
static inline void
suil_add_feature(LV2_Feature*** features,
unsigned* n,
const char* uri,
void* data) {
for (unsigned i = 0; i < *n && (*features)[i]; ++i) {
if (!strcmp((*features)[i]->URI, uri)) {

[Code] ....

suil_add_feature is used to add features to an existing array of pointers to type LV2_Feature. Initially, the array gets searched to see if the feature already exists. If it doesn't, the existing array gets increased by one element which then gets initialized to the new LV2_Feature value. Resizing is done using realloc()

I'm having a problem when I build a Debug version. The first 5 times I call suil_add_feature() realloc() ends up calling _realloc_dbg() (in dbgheap.c) and everything works fine. But on the sixth call, realloc() calls _realloc_base() (in realloc.c) which brings everything crashing down. I assume that _realloc_base() is intended for the normal (non-debug heap). So this particular app is somehow linking to both the debug and non-debug runtime modules.

If I was building using the VS IDE I could probably figure this out - but although my compiler is MSVC, my build environment is waf, which I'm a bit unfamiliar with. I'm guessing I need to add some lines to my waf script to let it know that it shuld ignore the non-debug runtime libraries when building a Debug version.

Can I achieve this by adding /NODEFAULTLIB to the linker options or is it more complicated than that?

View 6 Replies View Related

Visual C++ :: How To Read Sentence From Command Line With MFC

Feb 11, 2013

I want to read sentence from command line. I open some program which run in command line and I have to wait for that program process. So , I don't know when process success .I can't type next command if can't read sentence from command. I use

Code:
wprintf(GetCommandLine());

but it show

"C:UsersPKRUdocumentsvisual studio 2010ProjectsVirus ScanDebugMyProgram

How to read sentence from Command line with MFC?

View 5 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++ :: 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

Visual C++ :: Loading A File And Indexing Line Starts

Jun 14, 2013

I've spent some time trying to performance test various methods of loading / accessing a file, either into memory or through a memory mapped file, but I am having some trouble.

FILE * pFile;
std::ifstream ifs;
MapViewOfFile

I'm have trouble because Windows appears to cache the file, so I am getting very mixed results. Sometimes a huge file (100's MB's) will load quickly, other times almost instantly.

How to stop Windows from doing whatever it's doing, so I can see the real time taken to load/access a file from disk?

View 8 Replies View Related

Visual C++ :: How To View Line Length In Cm To User (using Map Mode)

Nov 3, 2012

My program allow user to draw lines and the user should know the length of the line that he draw in centimeter (.cm)

I did use

SetMapMode(MM_LOMETRIC) function to convert the device units into logical units

and it works correctly but I don't know how the line length will appear to the user to let him draw in correct length

I think to make the length appear on the mouse when the user draw but I don't know how I calculate and display it.

View 2 Replies View Related

Visual C++ :: Detect ItemID And Delete That Line From File

Oct 14, 2013

I have a text file name fruit.txt that contains the following information of fruit id, fruitName and fruitQuantity.

Code:
1:pear:30
2:apple:20
3:banana:24
4:orange:15
5:watermelon:35

If let's say I key in 2, it will search for the id=2 and delete the whole line and the id of banana which is orignially 3, will become 2 and orange which is orignally 4 will become 3 etc.

I researched on how it can be done and most suggested to put inside a vector and fout the line.

I know how to put the values in the vector but how should I go about searching for the id and if the id is found it will delete that line inside the file.

Code:
ofstream fout;
ifstream readFile("fruit.txt");
while (getline(readFile, line)) {

[Code]....

View 2 Replies View Related

C/C++ :: Display Data From File Into 2D Array - Print Closest Bmi From Data

Mar 28, 2015

#include <iostream>
#include <fstream>
using namespace std;
int main() {
int r = 0;
int c = 0;
int num[17][15] = { 0 };
[Code] ...

// Here is my code for displaying the data from the text file into a 2d array and height next to it, but I am not able to diaplay the height from 60 to 76 next to the row of the 2d array, as shown in the table below. This is my program:

Recently the health authorities have listed a new way to calculate the body mass index (BMI) of an individual.
Values of 20 – 24 are classified as normal, 25-29 as overweight, and 30-34 as heavy.

The table below is a portion of a typical BMI table.

BMI:202122232425262728293031323334
Height:
60102108113118123128133138143149154159164169174
61106111116122127132138143148153159164169175180
.
.
.

MY task is to write a program that does the following things:

1.Produce the table by reading in the data from bmi.txt (on Moodle) into a 2-D array.

2. Display the table neatly on the screen, with row and column headings. The BMI should go from 20 to 34. The height should go from 60 to 76 inches.

3. Prompt the use for their height (in inches) and their weight.

4. Make the program print the closest BMI.

If their weight is lower than the values on the table, use 20 as the BMI.
If their weight is higher than the values on the table, use 34 as the BMI.

5.Loop the program so the user can find more BMI’s.

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 :: 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 View Related







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