Menu
Menu
DaniWeb
Log In
Sign Up
Read
Contribute
Meet
Search
Search
About 83 results for
pythagoras
- Page 1
Pythagoras?
Programming
Software Development
14 Years Ago
by gangster88
I have to get pthagaros to get the distance between 2 points. so the function distanceBetweenPoints(Point(1, 2), Point(4, 6)) should result in 5.0. the parameters are supposed to be P1, P2, which i think i have done?. The get an error when i try to execute this?.. help please def distanceBetweenPoints(p1, p2): return float(math.sqrt((p2-p1…
Re: Pythagoras?
Programming
Software Development
14 Years Ago
by mn_kthompson
What error are you getting? It seems to run fine for me. [CODE="python"] >>> import math >>> def distance(p1, p2): ... return float(math.sqrt((p2-p1)**2+(p2-p1)**2)) ... >>> print distance(1,6) 7.07106781187 >>> [/CODE]
Re: Pythagoras?
Programming
Software Development
14 Years Ago
by woooee
[QUOTE]The get an error when i try to execute this?[/QUOTE] Not enough info for anyone to help (could be an indentation error, or could be in the calcs). First add some print statements for the individual calcs to isolate the error, and post the specific error message. [CODE]def distance_between_points(p1, p2): p2subp1 = p2-p1 p1subp2 = p1…
Re: Pythagoras?
Programming
Software Development
14 Years Ago
by jaison2
..
Re: Pythagoras?
Programming
Software Development
14 Years Ago
by gangster88
but the thing is we need it in this form.. distanceBetweenPoints(Point(1, 2), Point(4, 6)), so when we call the function and type it in we get the answer...
Re: Pythagoras?
Programming
Software Development
14 Years Ago
by Gribouillis
According to your previous post, I think that you are using the "graphics.py" module [url=http://mcsp.wartburg.edu/zelle/python/]like this one[/url]. In that case, since p1 and p2 are not numbers but Points, you must use first p1.getX() and p1.getY() to get the coordinates of the points.
Re: Pythagoras?
Programming
Software Development
14 Years Ago
by gangster88
yeah but how do you do that?.. any examples you got?
Re: Pythagoras?
Programming
Software Development
14 Years Ago
by Gribouillis
For example [code=python] def myfunction(pointA, pointB): xa, ya = pointA.getX(), pointA.getY() xb, yb = pointB.getX(), pointB.getY() do_something_with(xa, ya, xb, yb) [/code]
Re: Pythagoras?
Programming
Software Development
14 Years Ago
by gangster88
anything around these lines? def distanceBetweenPoints(p1, p2): x1, y1 = P1.getX(), P1.getY() x2, y2 = P2.getX(), P2.getY() distance = float(math.sqrt((x2-x1)**2+(y2-y1)**2))
Re: Pythagoras?
Programming
Software Development
14 Years Ago
by Gribouillis
[QUOTE=gangster88;1040676]anything around these lines? def distanceBetweenPoints(p1, p2): x1, y1 = P1.getX(), P1.getY() x2, y2 = P2.getX(), P2.getY() distance = float(math.sqrt((x2-x1)**2+(y2-y1)**2))[/QUOTE] The parameters p1 and p2 should not become P1 ad P2 the next line. Also, what does pyhon say ?
Re: Pythagoras?
Programming
Software Development
14 Years Ago
by gangster88
[QUOTE=Gribouillis;1040690]The parameters p1 and p2 should not become P1 ad P2 the next line. Also, what does pyhon say ?[/QUOTE] def distanceBetweenPoints(p1, p2): x1, y1 = p1.getX(), p1.getY() x2, y2 = p2.getX(), p2.getY() distanceBetweenPoints=float(math.sqrt((x2-x1)**2+(y2-y1)**2)) what about nw?.. python gives an error says "…
Re: Pythagoras?
Programming
Software Development
14 Years Ago
by Gribouillis
[QUOTE=gangster88;1040708] what about nw?.. python gives an error says "the name Point is not defined"[/QUOTE] add [code=python] from graphics import * [/code] at the top of your file. Also please use [url=http://www.daniweb.com/forums/announcement114-3.html]code tags[/url] to post your python code. And also post python error …
Re: Pythagoras?
Programming
Software Development
14 Years Ago
by jaison2
[QUOTE=Gribouillis;1040726]add [code=python] from graphics import * [/code] at the top of your file. Also please use [url=http://www.daniweb.com/forums/announcement114-3.html]code tags[/url] to post your python code. And also post python error tracebacks if there is one.[/QUOTE] This is my code at the moment and when i type in …
Re: Pythagoras?
Programming
Software Development
14 Years Ago
by Gribouillis
you forgot the return statement. This is python, not pascal :) [code] from graphics import * import math def distanceBetweenPoints(p1, p2): x1, y1 = p1.getX(), p1.getY() x2, y2 = p2.getX(), p2.getY() return math.sqrt((x2-x1)**2+(y2-y1)**2) [/code]
Re: Pythagoras?
Programming
Software Development
14 Years Ago
by vegaseat
When you post a question like that, give as much pertinent information as you can. You needed to tell us right from the start that you are using the Zelle module graphics. Also, read the code that folks respond with and check it against the errors in your code. I have to give Gribouillis and A+ for patience! Try this code, it seems to work now …
Re: Pythagoras?
Programming
Software Development
14 Years Ago
by gangster88
yup.. thankyou so much "Gribouillis"... it wrks... cheers..
Re: Pythagoras?
Programming
Software Development
14 Years Ago
by gangster88
[QUOTE=vegaseat;1040939]When you post a question like that, give as much pertinent information as you can. You needed to tell us right from the start that you are using the Zelle module graphics. Also, read the code that folks respond with and check it against the errors in your code. I have to give Gribouillis and A+ for patience! Try this …
Pythagoras Theorem in C++
Programming
Software Development
16 Years Ago
by DOrmisher
I was wondering if anyone could help me with this little problem. What I am actually trying to do is implement 'picking' into a game I'm doing, but I'm actually stuck with some of the maths, thats why this isn't in the game forum. I'm trying to work out a field of view for a camera. If you look at the picture below, I'm trying to work out …
Re: Pythagoras Theorem in C++
Programming
Software Development
16 Years Ago
by bilgehakan89
what do you want exactly to find a relationship for x: if you so x = tan-1(b/a)
Re: Pythagoras Theorem in C++
Programming
Software Development
16 Years Ago
by VernonDozier
[QUOTE=DOrmisher;568907]I was wondering if anyone could help me with this little problem. What I am actually trying to do is implement 'picking' into a game I'm doing, but I'm actually stuck with some of the maths, thats why this isn't in the game forum. I'm trying to work out a field of view for a camera. If you look at the picture below, I'm …
Re: Pythagoras Theorem in C++
Programming
Software Development
16 Years Ago
by DOrmisher
cheers man, great help!
school task help
Programming
Software Development
19 Years Ago
by Elektro
… = (x2, y2) is given by the distance formula, derived from
Pythagoras
' Theorem: What to do: You are required to design and…
Re: school task help
Programming
Software Development
19 Years Ago
by rickste_r
… = Double.parseDouble(x2Cord); double y2 = Double.parseDouble(y2Cord); //do the
pythagoras
maths a = y2 - y1; b = x2 - x1; diff = Math.sqrt…
Triangle Problem
Programming
Software Development
14 Years Ago
by Myko17
… know the formula for working out the hypotoneuse, it's
Pythagoras
' Theorem: [INDENT]a^2 + b^2 = c^2 (The ^ symbolises…
a few questions
Programming
Software Development
13 Years Ago
by Dom Chester
… book for me to get? 2) I have made a
pythagoras
theorem calculator and a celsuis to fahrenheit converter and am…
simple screen shots (help a girl out)
Programming
Software Development
13 Years Ago
by kimiko
… triangle include a method to test for a right angle (
Pythagoras
theorem) put the main method in a separate test driver…
python fractal project
Programming
Software Development
13 Years Ago
by kk12345
Hey, So I need help with fractal project,
Pythagoras
Tree, and below is the code i need to complete. …
Re: python fractal project
Programming
Software Development
13 Years Ago
by kk12345
The file supposes to show a
Pythagoras
Tree by importing movieSolution. The tree shuold look like this below [URL="http://en.wikipedia.org/wiki/Pythagoras_tree"]http://http://en.wikipedia.org/wiki/Pythagoras_tree[/URL]
warning and errors after compiling
Programming
Software Development
12 Years Ago
by Wolter888
… * RealPart; // csqr = asqr + bsqr; // Vector = sqrt (csqr); // Amplitude calclution with //
pythagoras
Theorema // } // 10& Threshold value if(Vector > Threshold) { SignalDetected…
Shortest distance between surface points (Python)
Programming
Software Development
10 Years Ago
by vegaseat
One way to find the shortest distance between a series of surface (x, y) points is to let Python module itertools find the non-repeating combinations of point pairs. Now you can apply the
Pythagoras
' theorem to find all the distances and the minimum distance.
1
2
3
Next
Search
Search
Forum Categories
Hardware/Software
Programming
Digital Media
Community Center
Latest Content
Newest Topics
Latest Topics
Latest Posts
Latest Comments
Top Tags
Topics Feed
Social
Forums
Top Members
Meet People
Community Functions
DaniWeb Premium
Newsletter Archive
Markdown Syntax
Community Rules
Developer APIs
Connect API
Forum API Docs
Tools
SEO Backlink Checker
Legal
Terms of Service
Privacy Policy
FAQ
About Us
Advertise
Contact Us
© 2024 DaniWeb® LLC