Yelloo ...
I must write a C++ program for my computational geometry class,
and I need some references where can I solve the next problem:
POINT P(1, 0);
for (i=0;i<96;++i)
P.rotate(PI/2);
Now P must be at (1, 0) ...
but it isn't ...
How can I solve this the problem;
the rotate function in implemented with
standard math sin and cos functions.
Thanks
Mihai. 7 1142
"mihai" <Mi*********@gm ail.com> writes: Yelloo ... I must write a C++ program for my computational geometry class, and I need some references where can I solve the next problem: ... Now P must be at (1, 0) ... but it isn't ...
Is it very close or a long way away. Is it the same each time you
try it?
How can I solve this the problem; the rotate function in implemented with standard math sin and cos functions.
Maybe you could post your rotate code?
The code is like this:
P::rotate(doubl e rad)
{
double xx = _x;
double yy = _y;
_x = xx * cos(rad) + yy * sin(rad);
_y = xx * cos(rad) - yy * sin(rad);
}
And I must say that the result is close ... but I can not do P==Q after
that.
"mihai" <Mi*********@gm ail.com> writes: The code is like this:
P::rotate(doub le rad) { double xx = _x; double yy = _y; _x = xx * cos(rad) + yy * sin(rad); _y = xx * cos(rad) - yy * sin(rad); }
And I must say that the result is close ... but I can not do P==Q after that.
Perhaps you shouldn't be trying to do that. Look at http://www.eason.com/library/math/floatingmath.pdf
What Every Computer Scientist Should Know About Floating-Point Arithmetic
mihai wrote: Yelloo ... I must write a C++ program for my computational geometry class, and I need some references where can I solve the next problem:
POINT P(1, 0);
for (i=0;i<96;++i) P.rotate(PI/2);
Now P must be at (1, 0) ... but it isn't ...
No wonder. Your code accumulates all the errors.
Don't do that if you can avoid it.
POINT P(1,0);
for( i = 0; i < 96; ++i ) {
POINT Q(P);
Q.rotate( i * PI/2 );
}
In other words:
Instead of small incremental rotations on the point
itself, start with a fresh point and rotate that point
only once (but this time, with an angle identical to
the idealized summed up angles).
Other things to consider:
How do you determine that the point is not at (1,0)?
Could it be that you are using plain vanilla '==' ?
--
Karl Heinz Buchegger kb******@gascad .at
> I must write a C++ program for my computational geometry class, and I need some references where can I solve the next problem:
POINT P(1, 0);
for (i=0;i<96;++i) P.rotate(PI/2);
Now P must be at (1, 0) ... but it isn't ...
Maybe your PI/2 constant is wrong. Check if sin(PI/2)==1 and cos(PI/2)==0.
If they are, then you have an error in the rotate function. If not then
either PI/2 is wrong or your sin and cos functions are wrong. I have heard
that sin and cos implemented in the intel processors FPU are a little bit
wrong (thats why Java does not use the trig. functions in the FPU, but uses
its own), so that might be the cause.
However in general it is better not to rely on float/double calculations
being precise.
Niels Dybdahl
Niels Dybdahl wrote: I must write a C++ program for my computational geometry class, and I need some references where can I solve the next problem:
POINT P(1, 0);
for (i=0;i<96;++i) P.rotate(PI/2);
Now P must be at (1, 0) ... but it isn't ... Maybe your PI/2 constant is wrong. Check if sin(PI/2)==1 and cos(PI/2)==0. If they are, then you have an error in the rotate function. If not then either PI/2 is wrong or your sin and cos functions are wrong.
Define 'wrong'.
In particular I would be interested how you would define PI/2 in
a computer language with only a limited number of bits, such that the
value is not 'wrong'. However in general it is better not to rely on float/double calculations being precise.
That however is the cause of the OP's problem. Limited precision
due to limited bits in calculation.
--
Karl Heinz Buchegger kb******@gascad .at
Karl Heinz Buchegger wrote: mihai wrote:
POINT P(1, 0);
for (i=0;i<96;++i) P.rotate(PI/2);
No wonder. Your code accumulates all the errors. Don't do that if you can avoid it.
POINT P(1,0);
for( i = 0; i < 96; ++i ) { POINT Q(P); Q.rotate( i * PI/2 ); }
That's still not as good as it (c|sh)ould be. You should avoid
angles much bigger than 2PI. In this case:
POINT P(1,0);
for( i = 0; i < 96; ++i ) {
POINT Q(P);
Q.rotate( (i%4) * PI/2 );
}
since sin(4 * (PI/2)) == sin(0) == 0.
HTH,
Michiel Salters This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: clementine |
last post by:
Hi,
I have an array of arrays in the form of
list = ,,]
The in-built sort(),list.sort() sorts on the first element, if the first
elts are equal then it sorts on the second elt and so on...But i really
dont want to search on the second elt if the first elts are equal...the
1-D lists shud be left in the same position i.e. i want the sorted list to
be ,,] and not
|
by: Eddie |
last post by:
I wondering which one of the following I should use to get the best
performance.
1. "SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED"
OR
2. "WITH (NOLOCK)"
I notice that when I use the #1 "SET TRANSACTION..." it sets a lock Mode
type of "Sch-S" (Schema stability Lock) which described by SQL Books
Online as "Schema stability (Sch-S) locks do not block any transactional
locks, including exclusive (X) locks"
|
by: spiffo |
last post by:
The Main Issue in a nutshell
I am a corporate developer, working for a single company. Got a new project
coming up and wondering if I should stay with Python for this new, fairly
large project, are jump back on the 'safe' M$ bandwagon using a dot net
language? Cross platform is NOT an issue, but COMPLETE control/compatability
with MsSql Server (current and future versions) certainly is.
Quick History
|
by: Jeffrey |
last post by:
Good day all,
I have seen so many postings dealing with MS Access as a security risk
and other items, yet I see now clear reason why. I would really like
someone to point me in the right direction for clear reasons why MS
Access should not be used for the enterprise. For a handful of users
I don't see an issue, but when an access application (I use that
loosly) drags down the network and the SQL Server at the same time, it
makes me...
|
by: Bob |
last post by:
I'd be pinging for 24 hours at 3 second intervals. Are there any IP
addresses out there that exist just for pinging, if not, would it be
considered rude to pick a major site such a google?
Or - let me back up here - is there some other, better way to monitor
internet connection stability using .Net?
Bob
| |
by: klubbhead |
last post by:
This part of my program needs to read from 4 parameter files and then displays them on the screen by clicking a different radio button. The program itself works, but my professor says that I have to improve the code in the DescriptionPanel 's listener because there are several lines of code that are identical and I should only have them once. Here is the code:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import...
|
by: CuTe_Engineer |
last post by:
hii,
i have cs assignment i tried to solve it but i still have many
errors , plzz help mee :"< it`s not cheating becuz i`ve tried & wrote
the prog. i just wanna you to show me my mistakes
#these are the operations
+ = ,
- = ,
* = ,
1/ = only if 0 not in .
|
by: Eddie |
last post by:
Hi
I am using lcc-win on Windows 98. I'm writing a simple c console app, and
I need to set the background color to blue. Here's the code I've got at
the moment:
_asm ( "movb $2, %ah\n"
"movb $7, %dl\n"
"int $0x21\n"
);
|
by: JDeats |
last post by:
So I have bugs in my application that stem from the VS.NET 2008 WPF
desinger. The XML/XAML has gotten corrupted a few times (aparently due
to drag and drop operations executed by the designer from toolbox to
window in drop) and it consistently requires reloading, etc...
What's more: when the XAML does get corrupted, often times my
applications appear to compile bug free and the problems only reveal
themselves as nasty fatal run-time...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
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...
|
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...
|
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...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
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...
| |