Visual C++ :: Crescent Moon - Calculate Points On This Shape

Mar 28, 2013

My question is, I have been tasked to draw this shape,

![Crescent Moon][URL] ....

This is to be done using C++ to write code that will calculate the points on this shape.

Important details.

User Input - Centre Point (X, Y), number of points to be shown, Font Size (influences radius)

Output - List of co-ordinates on the shape.

The overall aim once I have the points is to put them into a graph on Excel and it will hopefully draw it for me, at the user inputted size!

I know that the maximum Radius is 165mm and the minimum is 35mm. I have decided that my base [Font Size][1] shall be 20. I then did some thinking and came up with the equation.

Radius = (Chosen Font Size/20)*130. This is just an estimation, I realise it probably not right, but I thought it could work at least as a template.

I then decided that I should create two different circles, with two different centre points, then link them together to create the shape. I thought that the INSIDE line will have to have a larger Radius and a centre point further along the X-Axis (Y staying constant), as then it could cut into the outside line.*

*(I know this is not what it looks like on the picture, just my chain of thought as it will still give the same shape)

So I defined 2nd Centre point as (X+4, Y). (Again, just estimation, thought it doesn't really matter how far apart they are).

I then decided Radius 2 = (Chosen Font Size/20)*165 (max radius)

So, I have my 2 Radii, and two centre points.

This is my code so far (it works, and everything is declared/inputted above)

for(int i=0; i<=n; i++) //output displayed to user {
Xnew = -i*(Y+R1)/n; //calculate x coordinate
Ynew = pow((((Y+R1)*(Y+R1)) - (Xnew*Xnew)), 0.5); //calculate y coordinate

[Code] ....

I am having the problem drawing the crescent moon that I cannot get the two circles to have the same starting point?

I have managed to get the results to Excel. Everything in that regard works. But when i plot the points on a graph on Excel, they do not have the same starting points. Its essentially just two half circles, one smaller than the other (Stops at the Y axis, giving the half doughnut shape).

If this makes sense, I am trying to get two parts of circles to draw the shape as such that they have the same start and end points. Currently all I am getting more a 'half doughnut' shape, due to the circles not being connected.

View 1 Replies


ADVERTISEMENT

C++ :: Draw A Crescent Moon Shape And Extracted Values To Excel To Be Drawn

Mar 28, 2013

I have some code that will allow me to draw a crescent moon shape, and have extracted the values to excel to be drawn. However in place of some numbers, there is '-1.#IND' in place.

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++ :: 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++ :: Calculate Steepness Or Incline From 3 To 4 Points (XYZ)

Jan 26, 2015

How to calculate steepness or incline from 3 to 4 points in a 3D(xyz) point?

I'm trying to calculate steepness to determine if i can or cannot place objects on a super steep elevation in a 3D game?

My initial thinking was to add up all angles then divide by 4? I'm not a match major and I am not finding any information online.

View 1 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

Visual C++ :: How To Make A Shape Outside Of Main Function

Sep 9, 2014

I know how to define a shape (here, a rectangle) and attach it to a window in C++ as follows:

Code:
#include <Simple_window.h>
void cir() { Circle c(Point(100,100),50); }
int main() {
Simple_window win(Point(100,100),600,400, "test");

[Code] ....

But how to define a shape (say a circle by that cir() function which is) outside of the main() function that is how to create a circle inside of the cir() function and it returns that circle when I called it in my main() function so that I can attach it on the window win to be visible?

View 14 Replies View Related

Visual C++ :: Draw A Shape Or Font On Dialog And Then Fill The Outline?

Jul 8, 2013

I am trying to draw a shape or font on dialog and then fill the outline. I have 2 buttons on this 2 buttons I have the following code

Code:
case IDC_BUTTON1:
MessageBox(hDlg, L"Start Drawing!!", L"ButtonPressed", MB_OK | MB_ICONEXCLAMATION);
hDC = GetDC(hDlg);
brush = CreateSolidBrush(RGB(128, 128, 128));
SelectObject(hDC, brush);

[code].....

When I remove the BeginPath() and EndPath() functions my lines are being drawn. But when I insert this BeginPath() and EndPath() and StrokeAndFillPath(hDC); the nothing is being drawn.

Why it is not doing as per the expectations. I want to draw a shape for example A with a outline. And i want it to be closed when drawing is ended and filled the hollow portion.

What am I doing wrong in this ?I am not implementing it in WM_PAINT but drawing is done in WM_LBUTTONUP.

View 6 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

Visual C++ :: Calculate PI Value Using Series

Mar 3, 2013

in code my prompt said :

(computing Π (PI) ) You can approximate (PI) value by using the following

series:
Π = 4( 1 - 1/3 + 1/5 - 1/7 + 1/9 - 1/11 + ... - 1/(2i -1) + 1/(2i + 1)

Write a method that calculate value of π by using the above series, using

the following header:
public static double pi()
assume i = 1000000

ok so I have been testing it but I really did get any far :

for ( double i = 1; i< 1000000; i+=2) {

// with these I try to increment the value of i to get to the series. I did these after and test it and the output is all wrong and I know it

sum = (1/((2*i)+1));
sum = sum + (1/((2*i)-1));
sum ++;
double pi = 4*(sum);

// I know is wrong I but I can't figure it out what to do.

View 6 Replies View Related

Visual C++ :: Calculate Two Summations - Parameter N

Sep 11, 2014

So I'm currently using Visual Studio 2013, and I was left for homework as a beginner programmer to calculate two summations. First the summation of k to n. k=1 and the equation being k^3. The parameter would be n and I need to printf the results for n=5, 33, 100, 442, 3456.

I know that some of the numbers are big values so float or long should be used but how to define these as of yet.

Another is to find the summation
(n)
(k) <<-- one big paranthesis

for values k=8 and n=10, 21, 35, 46, 68

How to start excluding <stdio.h> and int main ... Also, do I have to repeat a new function for every number for n?!

This is what I have so far for something I did differently

// Factoriales Sumatorias

#include <stdio.h>
int suma1 {
int n = 5; // Defino e Inicializo la variable
long sumatoria = 1; // definicion e inicializacion del resultado
while (n <= 5)

[Code] .....

View 3 Replies View Related

Visual C++ :: How To Calculate PCA / Memory Access Violation

Mar 23, 2013

I am trying to use PCA, but it gives memory access violation error. Here is my sample code.

Code:
int main(...) {
.................
vector<float>input_array;
for(i=0;i<number_of_lines;i++) {
for(j=0;j<feature_vector_size;j++) {
input_array.push_back(read_feature[i][j]);

[code]....

View 1 Replies View Related

Visual C++ :: How To Calculate Average And Standard Deviation

Oct 21, 2013

I've been trying to calculate the Second standard deviation but the average in the second loop isn't calculating correctly which is causing the standard deviation (method 2) to not calculate correctly.

Code:
#include <iostream>
#include <iomanip>
#include <string>
#include <fstream>
#include <cmath>
using namespace std;
int main () {
cout << "
This program will produce statistics (Mean, Standard Deviation, "

[code]...

View 4 Replies View Related

Visual C++ :: Totals Or Formula To Calculate Is Not Working?

Sep 19, 2014

My code is below:

Total Interest ends up as my last Monthly Payment amount instead of adding up all Interest Paid - What am I doing wrong?

Total Paid isn't calculating correcly either - What am I doing wrong?

I suspect both are very similar problems. I've tried several different calculations, but cannot figure this out.

#include <iostream>
#include <cmath>
using namespace std;
double GetMonthlyIntrest (double OpenBalance,double rate);
bool ContinuePgm();
int main () {
double StartingBalance,rate,amount,OpenBalance,IntPmt,TotalInt=0.0,GrandTotal=0.0;

[code]...

View 3 Replies View Related

Visual C++ :: Calculate Fewest Number Of Each Denomination

Mar 4, 2013

Write a C++ program to calculate the fewest number of each denomination needed to pay a bill of amount TOTAL. For example, if the end user enters $97 for TOTAL, program will output that the bills would consist of one $50 bill, two $20 bills, one $5 bill, and two $1 bills. (Assume that the amount is in whole dollars, no cents, and only $100, $50, $20, $10, $5, and $1 denominations are available.) Aid: You may want to use the modulus operator %.

View 5 Replies View Related

Visual C++ :: Calculate Prime Numbers In Order

May 12, 2013

So if i write a Loop to calculate Prime Numbers in order, is there any way possible for this to happen in a shorter period of time.

The loop that i constructed took about 11hrs on a Win 7 2GB ram machine to calculate about 150,000 primes, could this be done any faster................

View 14 Replies View Related

C :: How To Print Another Shape Near Previous One

Nov 9, 2014

How do i print another shape near the one i did. I have this code but how i can put another shape near it like this

Code:
#include <stdio.h>
int main() {
int i;
for (i = 0; i < 5; i++)
switch (i) {
case 0:
printf(" *

[Code] .....

View 7 Replies View Related

C# :: Custom Button Shape (WPF)

Nov 30, 2014

I have begun switching from WinForms to WPF and I'm having a hard time understanding the new concepts. In WinForms, I had a few User Controls, custom drawn using shapes (rectangles, ellipses, etc). They had some unique properties, like "Flashing" (setting this property to True and setting the "Flash Interval" property to 500 would have resulted in the control changing its background color to white and back again, every 0.5 seconds), "Beeping", etc.

I have tried to replicate these controls in WPF/XAML and so far managed to draw the shape. However, when it came to implementing a custom property that would redraw the background color of the rectangle every interval set by user in another property, i got stuck. The property is being set, but it doesn't change the background color. Alternatively, i have tried this method, with the same results (i got it to show in the "Properties" window in Visual Studio, i can set it, it is being stored in XAML, but it doesn't affect the background.

C# code behind:
public struct LCARSColors
{
public static Brush DarkBlue = (Brush)(new BrushConverter().ConvertFrom("#FF3366CC"));
public static Brush LightBlue = (Brush)(new BrushConverter().ConvertFrom("#FF99CCFF"));
public static Brush Pink = (Brush)(new BrushConverter().ConvertFrom("#FFCC99CC"));

[Code] ....

If i use this line (commented in this code sample):

<!--<SolidColorBrush x:Name="MySolidColorBrush" Color="{DynamicResource DarkBlue}" />-->

The background is colored in DarkBlue (as defined). But if i use this line:

<SolidColorBrush x:Name="MySolidColorBrush" Color="{Binding BackgroundColor, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}" />

Nothing happens, the rectangle disappears entirely. If i add this to the above line:

FallbackValue=LightYellow

The rectangle is colored in LightYellow, meaning that the property is not accepted and the fallback value is used. Why?

View 9 Replies View Related

Visual C++ :: Program That Take Input From A User And Calculate It In A Do While Loop

May 15, 2013

I'm trying to create a program that will take input from a user and calculate it in a do-while loop. The program does the calculation but the answer is wrong. The loop also doesn't work. The purpose of the program is to see how much an item will cost after a discount is taken off and tax is added.

#include <iostream>
#include <cmath>
using namespace std;
double original_cost;
double discount;
double tax;
double total;
char answer;

[Code]...

View 2 Replies View Related

C :: Drawing A Shape (Square) Into PGM Image

Nov 22, 2013

I'm doing a project and I need to draw a square into a pgm image if certain conditions are met, but I'm not sure how to draw the square into the image.

View 2 Replies View Related

C++ :: Generic Shape Area Calculator

Dec 6, 2013

I'm building a pretty basic calculator program that calculates the area of generic shapes (triangles, rectangles, and squares); for some reason though, my program is having troubles as soon as it hits the if/else code in the int main section. When I enter triangle, rectangle, or square, it just spits back out the "That's not one of the options. Please re-enter and try again." error line I created. When I isolate and run just the stuff inside the if/else statements it works great, but why it won't just understand my if (shape == triangle).... .

Code:

#include <iostream>
using namespace std;
class figure {
protected:
double x, y;

[Code] ....

View 2 Replies View Related

C++ :: How To Make A Shape Outside Of Main Function

Sep 8, 2014

I know how to define a shape and attach it to a window as follows:

#include <Simple_window.h>
void cir() { Circle c(Point(100,100),50); }
int main() {
Simple_window win(Point(100,100),600,400, "test");

Rectangle r(Point(100,100),Point(300,200));
win.attach(r);
win.wait_for_botton();
}

But how to define a shape (say a circle by that cir() function which is) outside of the main() function? And how to attach it to be visible on window win?

View 4 Replies View Related

C++ :: Use Construct Object (Shape) Efficiently?

Jun 27, 2014

have a problem with my code (I wish for answer with code). The conditions I have to grant:

- **Only** a pointer to an object must be saved in a **standard** class vector (e.g vector<ShapePtr>)
- Base class must be a polymorphic class (I call this class ShapePtr)
- I **must** have a deep copy process
- Constructor is **not** suppose to do a deep copy
- **clone()** is suppose to do the deep copy

Here is the code **provided** to me:

main.cpp
int main() {
typedef shared_ptr<Shape> ShapePtr;
vector<ShapePtr> shapevec;

[Code].....

View 1 Replies View Related

C/C++ :: Count The Times A Shape Was Selected?

Jul 28, 2014

This is part of the program, What should i do if i want to total the number of times a shape was selected at the end?

#include<iostream>
#include<string>
#include<iomanip>

[Code]....

View 3 Replies View Related

C/C++ :: How To Make A Shape Outside Of Main Function

Sep 8, 2014

I know how to define a shape (here, a rectangle) and attach it to a window in C++ as follows:

#include <Simple_window.h>
void cir() { Circle c(Point(100,100),50); }
int main() {
Simple_window win(Point(100,100),600,400, "test");
Rectangle r(Point(100,100),Point(300,200));
win.attach(r);
win.wait_for_botton();
}

But how to define a shape (say a circle by that cir() function which is) outside of the main() function? And how to attach it on the window win to be visible?

View 4 Replies View Related

C# :: API That Convert 2D Cross Sections Into 3D Shape

Mar 1, 2014

I have cross sections in the form of rectangles in the XY plane formed from two point (top left, bottom right) as well as their Z position. I'd like finding some sort of API that can extrude a basic linear-average-approximated 3D shape (preferably eventually into STL format) from these points. I've tried googling but to no avail. The aim is to build a 3D shape from 2D wireframes.

View 2 Replies View Related







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