473,785 Members | 2,167 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How can I determine if a point is a given distance from a secondpoint?

I am writing a drawing program but I want to keep the scale down
(there could end up being several hundred objects on the screen).

I want to limit the points collected to a certain distance from other
points already collected, in other words, if you're drawing a line it
will only record points on the line every 6 pixels. How do I determine
how far away one point is from another? if they are restricted to
straight lines that's fine but as soon as they draw at an angle I'm
faced with determining how far away one point is from another in co-
ordinate space.

Any help would be appreciated.

Tom P.
Mar 31 '08 #1
6 1694
On Mar 31, 1:24 pm, "Tom P." <padilla.he...@ gmail.comwrote:
I am writing a drawing program but I want to keep the scale down
(there could end up being several hundred objects on the screen).

I want to limit the points collected to a certain distance from other
points already collected, in other words, if you're drawing a line it
will only record points on the line every 6 pixels. How do I determine
how far away one point is from another? if they are restricted to
straight lines that's fine but as soon as they draw at an angle I'm
faced with determining how far away one point is from another in co-
ordinate space.

Any help would be appreciated.

Tom P.
Point x = new Point(1, 2);
Point y = new Point(3, 4);
double distance = Point.Distance( x, y);

I hope that helps.

goodluck,
-tom
Mar 31 '08 #2
On Mar 31, 1:58 pm, thomasnguyencom <thomasnguyen.. .@gmail.comwrot e:
On Mar 31, 1:24 pm, "Tom P." <padilla.he...@ gmail.comwrote:
I am writing a drawing program but I want to keep the scale down
(there could end up being several hundred objects on the screen).
I want to limit the points collected to a certain distance from other
points already collected, in other words, if you're drawing a line it
will only record points on the line every 6 pixels. How do I determine
how far away one point is from another? if they are restricted to
straight lines that's fine but as soon as they draw at an angle I'm
faced with determining how far away one point is from another in co-
ordinate space.
Any help would be appreciated.
Tom P.

Point x = new Point(1, 2);
Point y = new Point(3, 4);
double distance = Point.Distance( x, y);

I hope that helps.

goodluck,
-tom
You're kidding? All the crap I went through and it's already a
framework method? I could choke myself.

Thank you very much. I'm sorry I didn't look harder.

Tom P.
Mar 31 '08 #3
On Mar 31, 2:58*pm, thomasnguyencom <thomasnguyen.. .@gmail.comwrot e:
On Mar 31, 1:24 pm, "Tom P." <padilla.he...@ gmail.comwrote:
I am writing a drawing program but I want to keep the scale down
(there could end up being several hundred objects on the screen).
I want to limit the points collected to a certain distance from other
points already collected, in other words, if you're drawing a line it
will only record points on the line every 6 pixels. How do I determine
how far away one point is from another? if they are restricted to
straight lines that's fine but as soon as they draw at an angle I'm
faced with determining how far away one point is from another in co-
ordinate space.
Any help would be appreciated.
Tom P.

Point x = new Point(1, 2);
Point y = new Point(3, 4);
double distance = Point.Distance( x, y);

I hope that helps.

goodluck,
-tom
If the distance cutoff is constant you're going to be executing this
many times or for many points you might want to do the math manually
and then compare against distance squared instead e.g. distance^2 =
(x2-x1)^2 + (y2-y1)^2
Mar 31 '08 #4
On Mar 31, 1:58 pm, thomasnguyencom <thomasnguyen.. .@gmail.comwrot e:
On Mar 31, 1:24 pm, "Tom P." <padilla.he...@ gmail.comwrote:
I am writing a drawing program but I want to keep the scale down
(there could end up being several hundred objects on the screen).
I want to limit the points collected to a certain distance from other
points already collected, in other words, if you're drawing a line it
will only record points on the line every 6 pixels. How do I determine
how far away one point is from another? if they are restricted to
straight lines that's fine but as soon as they draw at an angle I'm
faced with determining how far away one point is from another in co-
ordinate space.
Any help would be appreciated.
Tom P.

Point x = new Point(1, 2);
Point y = new Point(3, 4);
double distance = Point.Distance( x, y);

I hope that helps.

goodluck,
-tom
On second thought... no it doesn't help.

I'm not finding that static method. Am I missing a namespace or
something?

Tom P.
Mar 31 '08 #5
On Mar 31, 2:15 pm, Israel <israeldip...@h otmail.comwrote :
On Mar 31, 2:58 pm, thomasnguyencom <thomasnguyen.. .@gmail.comwrot e:
On Mar 31, 1:24 pm, "Tom P." <padilla.he...@ gmail.comwrote:
I am writing a drawing program but I want to keep the scale down
(there could end up being several hundred objects on the screen).
I want to limit the points collected to a certain distance from other
points already collected, in other words, if you're drawing a line it
will only record points on the line every 6 pixels. How do I determine
how far away one point is from another? if they are restricted to
straight lines that's fine but as soon as they draw at an angle I'm
faced with determining how far away one point is from another in co-
ordinate space.
Any help would be appreciated.
Tom P.
Point x = new Point(1, 2);
Point y = new Point(3, 4);
double distance = Point.Distance( x, y);
I hope that helps.
goodluck,
-tom

If the distance cutoff is constant you're going to be executing this
many times or for many points you might want to do the math manually
and then compare against distance squared instead e.g. distance^2 =
(x2-x1)^2 + (y2-y1)^2
This is what I'm going to be using. I'll just do the math myself. I
never did find the method referred to, I don't know where tom got it
but he's got me beat.

Thanks for the help guys.

Tom P.
Mar 31 '08 #6

"Tom P." <pa***********@ gmail.comwrote in message
news:bc******** *************** ***********@s13 g2000prd.google groups.com...
On Mar 31, 1:58 pm, thomasnguyencom <thomasnguyen.. .@gmail.comwrot e:
>On Mar 31, 1:24 pm, "Tom P." <padilla.he...@ gmail.comwrote:
I am writing a drawing program but I want to keep the scale down
(there could end up being several hundred objects on the screen).
I want to limit the points collected to a certain distance from other
points already collected, in other words, if you're drawing a line it
will only record points on the line every 6 pixels. How do I determine
how far away one point is from another? if they are restricted to
straight lines that's fine but as soon as they draw at an angle I'm
faced with determining how far away one point is from another in co-
ordinate space.
Any help would be appreciated.
Tom P.

Point x = new Point(1, 2);
Point y = new Point(3, 4);
double distance = Point.Distance( x, y);

I hope that helps.

goodluck,
-tom

On second thought... no it doesn't help.

I'm not finding that static method. Am I missing a namespace or
something?

Tom P.
Distance between (x1,y1) and (x2,y2)
= sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2))

(Pythagoras's theorem).
Apr 1 '08 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
4682
by: some one | last post by:
Does anyone know the algorithm or a function out there that will compute the offset location given the following: inputs: 1) x,y coordinate of starting point 2) angle (bearing) 3) distance to offset point outputs: 1) x,y coordinate of destination thanks
15
3933
by: michael.mcgarry | last post by:
Hi, I have a question about floating point precision in C. What is the minimum distinguishable difference between 2 floating point numbers? Does this differ for various computers? Is this the EPSILON? I know in float.h a FLT_EPSILON is defined to be 10^-5. Does this mean that the computer cannot distinguish between 2 numbers that differ by less than this epsilon?
65
12617
by: Skybuck Flying | last post by:
Hi, I needed a method to determine if a point was on a line segment in 2D. So I googled for some help and so far I have evaluated two methods. The first method was only a formula, the second method was a piece of C code which turned out to be incorrect and incomplete but by modifieing it would still be usuable. The first method was this piece of text:
29
5115
by: garyusenet | last post by:
I'm trying to investigate the maximum size of different variable types. I'm using INT as my starting variable for exploration. I know that the maximum number that the int variable can take is: 65,535. But i'm trying to write a program to test this, assuming I didn't know this number in advance. I came up with the following but have two questions. Maybe someone can help? using System; using System.Collections.Generic; using System.Text;
13
3847
by: softwaredoug | last post by:
I can't see to easily find this on google or in a newsgroup Is there a standard function/macro/whatever you can call and determine the distance in a C program how deep one is in the C call stack from main. Something along the lines: int main() {
39
3113
by: DanielJohnson | last post by:
I wrote a simply program with a 3 D coordinate called point. I am adding two points, taking their distance etc. gcc compiler is not identifying the struct. Here is the code. I get bunch of errors. The main ones are : useless storage class specifier in empty declaration, 'point' undeclared (first use in this function), 'p1' undeclared (first use in this function) etc. Any help will be appreciated. Thanks #include <stdio.h> #include...
14
2515
by: nw | last post by:
Hi, I'd like to compare 2 floating point numbers within a given error. I'd rather not use a absolute error but one related to the number of values that can be represented between the two floats. I've been reading: http://www.cygnus-software.com/papers/comparingfloats/comparingfloats.htm where the following function is provided to do this: bool AlmostEqual2sComplement(float A, float B, int maxUlps) { // Make sure maxUlps is...
3
1923
by: pjmulla | last post by:
I am nes to python and need some help. Can anyone lead me in the right direction to create and print a Point object, and then use id to print the object's unique identifier. Translate the hexadecimal form into decimal and confirm that they match. Any help woul be much appreciated. Pete
3
9811
by: illusion.admins | last post by:
I am trying to code something to tell me if a selected point is in a particular ellipse. For the ellipse I know how it was constructed (know the x,y, and width, height). But if I just check to see if the point is in the rectangle making up the ellipse wouldn't that possibly give me a false answer? Eg if the point is the upper left coordinate of the rectangle...this point is in the rectangle making up ellipse but NOT the ellipse itself. ...
0
10356
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10162
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9959
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8988
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7509
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5396
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5528
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3665
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2893
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.