In this article I am going explain how to create Shapes using Trigonometry with jQuery. JavaScript supports 3 trigonometric functions. This idea might help you if you want place elements on particular shape.
Math.sin(angle)
Math.cos(angle)
Math.tan(angle)

We need CSS and jQuery function to create pixels.

CSS :

#circle b {
  position:absolute;
  color:rgb(91,111,135);
}

#circle {
  position:relative;
  margin:auto;
  width:400px;
  height:400px;
  vertical-align:center;
}

putpixel function :

function putpixel(mx,my) {
$("#circle").append("<b style='left:"+mx+"px;top:"+my+"px'>.</b>");
}

Circle :

X = X -coordinate
Y = Y -coordinate
R = Radius of the Circle
X = R cosθ
Y = R sinθ

jQuery :

xc, yc : Center of the Cicle
i : Angle
r : Radius
var xc=200,yc=200;
var i=360,r=200;
while(i>0)
{
    putpixel(xc + r*Math.cos(i),yc+ r*Math.sin(i));
    i = i - 0.1;
}

Ellipse :

X = X -coordinate
Y = Y -coordinate
Ra, Rb = One-half of the Ellipse's major and minor axes 
X = Ra cosθ
Y = Rb sinθ

jQuery :

xc, yc : Center of the Cicle
i : Angle
ra, rb : One-half of the Ellipse's major and minor axes 
var xc=200,yc=200;
var i=360,ra=200, rb=100;
while(i>0)
{
      putpixel(xc + ra*Math.cos(i),yc+ rb*Math.sin(i));
      i = i - 0.1;
}

Random shape :

X = X -coordinate
Y = Y -coordinate
a, b  = Random variables
X = a ( 1 / cosθ )
Y = b ( 1 / sinθ )

jQuery :

xc, yc : Center
i : Angle
a = Random variables
var xc=200,yc=200;
var i=360,a=200, b=100;
while(i>0)
{
      putpixel(xc + a*(1/Math.cos(i)),yc+ b*(1/Math.sin(i)));
      i = i - 0.1;
}

23 comments:

  1. I love this. It is soo informative. Are you also searching for Swedish assignment writing help we are the best solution for you. We are best known for delivering the best services to students without having to break the bank

    ReplyDelete
  2. Your blogs are great.Are you also searching for nursing pico writing help? we are the best solution for you. We are best known for delivering nursing writing services to students without having to break the bank.

    ReplyDelete
  3. The step-by-step guide at Cricut.com/setup and start your Cricut Maker set up as a beginner. But first, let’s take a tour and learn what precisely the Cricut machine is and how it works.

    ReplyDelete
  4. All the subscribers of Amazon prime videos can watch and enjoy videos, music, web series, latest movies even Amazon original content on prime video application on android or iphone. But do you know what is Amazon.com/mytventercode If you don’t know, you are at the right place.

    ReplyDelete
  5. This comment has been removed by the author.

    ReplyDelete
  6. Convert [url=https://sites.google.com/consofts.com/jpgtopdf/]JPG TO PDF[/url] when you want to save photo in phone or computer. It is usually saved as a JPG file which is considered best for short term storage. They usually lose quality every time when sharing or saving. JPGs are not considered good for holding files for a long time.

    ReplyDelete
  7. Convert JPG TO PDF when you want to save photo in phone or computer. It is usually saved as a JPG file which is considered best for short term storage. They usually lose quality every time when sharing or saving. JPGs are not considered good for holding files for a long time.

    ReplyDelete
  8. Go to hp printer drivers, enter your printer model, and then follow the onscreen instructions to download your driver. Depending on your printer model, the guided driver installation app HP Easy Start might download.

    ReplyDelete
  9. Centimeters and Inches Cm to Inches are one amongst the broadly accepted land measurement units and both the units have their own essence. This conversion is quite simple and easy to understand. We will show you the basic formulas for a better understanding of the relationship between measurement units.

    ReplyDelete
  10. If your primary browser is Google Chrome, the fact is you don't need an extension, online tool, or even software to convert Html to Pdf. Chrome extends its usefulness to help you easily convert any HTML document to PDF. The process is easy and can be completed in a few simple steps.

    ReplyDelete
  11. Visit the wallmart shopping online website or download the Walmart App. Sign in or create a Walmart account.

    ReplyDelete
  12. Portable Document Format Convert to PDF is a universal file format that includes features of both text documents and graphic images making it one of the most commonly used file types today.

    ReplyDelete
  13. If you've been looking for a free, simple and fast way to convert your image files to PDF, your search may be over now. Get started now with our free convert jpg to pdf. Our JPG conversion online service is the best free tool to convert jpg to pdf .

    ReplyDelete
  14. PDF is a Universal Document Format that looks the same on different devices and platforms. So, to keep the same formatting and layout, it is much better to convert word to pdf documents. word to pdf It can be done easily by using our simple online/offline tool as we discussed above.

    ReplyDelete
  15. This is one of the widely accepted land measurement units. Centimeter to Inch chart is very useful to convert cm to inches .

    ReplyDelete
  16. The American Express Bluebird card is designed for consumers who want the convenience of paying with plastic but don’t want (or don’t qualify) for a regular credit card. Bluebird card only allow you to spend money already in your account at Bluebird.com/activate. So you can avoid interest payments, bounced checks, or overdraft fees.

    ReplyDelete
  17. Go through with the hp printer website: 123.hp.com/setup and follow the download and installation steps to get started with 123 hp printer setup. Connect the hp printer with your device using a wireless method.

    ReplyDelete
  18. To login to your Microsoft MFA and setup MFA on your device, here you will get complete guidelines for setup and additional security verification. Visit aka.ms/mfasetup and start using it from now.

    ReplyDelete
  19. Setup mfa and get complete security. If you still face troubles while enabling MFA on Office 365, then visit aka.ms/mfasetup and follow the steps for setting up Multi-Factor Authentication in Office 365.

    ReplyDelete
  20. You will still log on with your usual MIT staff username and password, but in addition to that, you will be asked to confirm login via the Microsoft MFA App visit by aka.ms/mfasetup .

    ReplyDelete
  21. To login to your Microsoft MFA and setup MFA on your device, here you will get complete guidelines for setup and additinal security verification. Visit aka.ms/mfasetup and start using it from now.

    ReplyDelete
  22. aka.ms/mfasetup website enables people to play Minecraft at home with other people with devices except for their one.

    ReplyDelete
  23. aka.ms/mfasetup to protect your identity is very important. If someone gets access to your mailbox this person can also misuse your identity.

    ReplyDelete

Blogroll

Popular Posts